C++学生智能管理系统

翻出来的一个古早神秘东西,可以加学生、删学生、打印学生列表,功能不多但就那样吧。

#include<bits/stdc++.h>
#include<time.h>
#include<ctime>
#include<windows.h>
#include<math.h>
#include<conio.h>
using namespace std;

const int N = 1e6 + 10;
enum ConsoleColor {BLACK = 0,BLUE = 1,GREEN = 2,CYAN = 3,RED = 4,
				MAGENTA = 5,BROWN = 6,LIGHT_GRAY = 7,DARK_GRAY = 8,
				LIGHT_BLUE = 9,LIGHT_GREEN = 10,LIGHT_CYAN = 11,
				LIGHT_RED = 12,LIGHT_MAGENTA = 13,YELLOW = 14,WHITE = 15};
void Color(ConsoleColor color) {HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
			SetConsoleTextAttribute(hConsole, color);}
void Color2(int color) {HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
			SetConsoleTextAttribute(hConsole, color);}
int randint(int a,int b){srand(static_cast<unsigned int>(time(0)));return rand() % (b-a+1)+a;}
void Slow(string a) {int l=a.size();for(int i=0;i<l;i++){cout<<a[i];Sleep(20);}cout << endl; Sleep(100);}
void Slow2(string a) {int l=a.size();for(int i=0;i<l;i++){cout<<a[i];Sleep(20);}Sleep(100);}
void Slow3(string a) {int l=a.size();for(int i=0;i<l;i++){Color2(i*2%15==0?i*2%15+1:i*2%15);cout<<a[i];Sleep(20);}cout << endl; Sleep(100);}

struct Student{
	int id;
	string name;
};
bool cmp(Student a,Student b){return (a.id!=b.id)?(a.id<b.id):(a.name<b.name);}
struct Students{
	Student s[1000];
	int len;
	
	Student QueryStudent(int _id){
		//查询 
		if(len==0){Color(LIGHT_RED);Slow("对不起,学生列表是空的。");Color(WHITE);Student s = {-1,""};return s;}
		for(int i = 1; i <= len; i++){
			if(s[i].id == _id){
				return s[i];
			}
		}
		Color(LIGHT_RED);Slow("对不起,没有这个学生。");Color(WHITE);
		Student s = {-1,""};return s;
	}
	void AddStudent(int _id, string _name){
		//增加 
		s[len+1].id = _id;
		s[len+1].name = _name;len++;
		Slow("已添加。");
		sort(s+1,s+len+1,cmp);
	}
	void AddStudent2(int _id, string _name){
		//增加 
		s[len+1].id = _id;
		s[len+1].name = _name;len++;
		sort(s+1,s+len+1,cmp);
	}
	void DeleteStudent(int _id){
		//删除 
		if(len==0){Color(LIGHT_RED);Slow("对不起,学生列表是空的。");Color(WHITE);return;}
		for(int i = 1; i <= len; i++){
			if(s[i].id == _id){
				for(int j = i+1; j <= len; j++){
					s[j-1] = s[j];
				}
				len--;Slow("已删除。");return;
			}
		}
		Color(LIGHT_RED);Slow("对不起,没有这个学生。");Color(WHITE);
		return;
	}
	void PrintStudent(){
		Slow("正在打印········"); 
		for(int i = 1; i <= len; i++){
			cout << s[i].id << "\n\t" << s[i].name << endl;
		}
		return;
	}
};
Students s;
int main(){
	Slow3("欢迎进入学生管理系统"); 
	Color(WHITE);
	s.len=0;
	while(1){
		Slow("增加学生按1,删除学生按2,查询学生按3,打印学生列表按4,保存退出按5");
		char a = getch(); 
		if(a=='1'){
			Slow("请输入学号和名字");
			int i;string j;
			cin >> i >> j; 
			s.AddStudent(i,j);
		}
		else if(a=='2'){
			Slow("请输入学号");
			int i;
			cin >> i; 
			s.DeleteStudent(i);
		}
		else if(a=='3'){
			Slow("请输入学号");
			int i;
			cin >> i; 
			Student s3 = s.QueryStudent(i);
			if(s3.id!=-1){
				Slow2("已查询到");cout << i;Slow("号同学");
				Slow("学生信息为:"); 
				Students s2;
				s2.AddStudent2(s3.id,s3.name);
				s2.PrintStudent();
			}
		}
		else if(a=='4'){
			s.PrintStudent();
		} 
		else{
			
			exit(114514);
		} 
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值