C++实现:学生管理系统(详细解析)

news2025/1/16 1:01:17

目录

1.题目要求

2.需求分析

3.整体设计

4.详细设计

主函数设计

 学科科目类

主菜单

读取文件与写入文件

 效果如下

 添加学生信息

删除学生信息

​编辑

修改学生信息

显示信息列表

显示学生列表

将学生列表按学号升序排列

将学生列表按平均分降序排列,平均分相同的再按学号升序排列

统计学生数据

清空系统数据

5.总结


1.题目要求

学生成绩管理系统

(1)增加记录:要求可以连续增加多条记录。
(2)查找:可以根据姓名(或学号)查找某个学生的课程成绩,查找某门课程成绩处于指定分数段内的学生名单等等。可以实现模糊查询,即输入名字的一部
分,可以列出满足条件的所有记录。再从这个记录中进行二次选择。
(3)删除一个学生的记录:要求可以先查找,再删除。删除前,要求用户确认。
(4)成绩修改:若输入错误可进行修改;要求可以先查找,再修改。
(5)统计分析:对某个班级学生的单科成绩进行统计,求出平均成绩;求平均成绩要求实现函数的重载,既能求单科的平均成绩,又能求三科总分的平均成绩。
求出一门课程标准差和合格率;
(6)排序功能:要求按总分进行排序(从高到低),若总分相同,则按数学排序;
若总分和数学相同,则按物理排序;若总分和各科成绩都相同,则按学号排
序;
(7)文件操作:可以打开文件,显示班级的所有学生信息;可以将增加或修改后的成绩重新写入文件;可以将排序好的信息写入新的文件;

2.需求分析

基本思路

设计一个学生的类。类的设计测试数据的记录和将要实现的功能。学生成绩

管理系统有若干学生成绩记录组成,学生一条记录包括:学号、姓名、数学

成绩、物理成绩和英语成绩。主函数显示功能菜单,供用户选择操作。每步操

作之前,都要显示菜单。在主函数中调用类的方法

编译环境
在DEV-C++上运行通过

3.整体设计

【1】录入学生信息
【2】显示学生信息
【3】修改学生信息
【4】查找学生信息
【5】删除学生信息
【6】学生信息文件
【7】成绩排序功能
【8】存入新文件
【9】统计分析成绩

4.详细设计

主函数设计

int main()
{
	StudentList stuList;
	stuList.init(); //读入文件数据初始化
	stuList.menu(); //打开主菜单
	return 0;
}

效果如下

 学科科目类

class Subject
{
	public:
		string proName;  //学科名
		double proScore; //分数
		void showCpInfo()
		{
			cout << left << setw(45) << proName;
			cout << left << setw(6) <<  proScore << endl;
		}
		//输出属性名,只显示总积分
		static void showHeader()
		{
			cout << left << setw(45) << "科目";
			cout << left << setw(6) <<  "分数" <<endl;
		}
};

 效果如下

主菜单

void menu()
		{
			string sel = "0";
			system("cls");
			cout << "\t\t\t**********欢迎来到学生成绩管理系统**********" << endl;
			cout << "\t\t\t你可以进行以下操作:" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             1   添加学生信息             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             2   删除学生信息             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             3   修改学生信息             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             4   查询学生信息             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             5   显示信息列表             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             6   统计学生数据             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             7   清空系统数据             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             0   退出                     |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t请选择【0-7】:";
			cin >> sel;
			while(sel != "0" && sel != "1" && sel != "2" && sel != "3" && sel != "4" && sel != "5" && sel != "6" && sel != "7")
			{
				cout << "\t\t\t输入不合法,请重新选择【0-7】:";
				cin >> sel;
			}
			if(sel == "1")
			{
				this->insertList();
				this->menu();
			}
			else if(sel == "2")
			{
				this->deleteList();
				this->menu();
			}
			else if(sel == "3")
			{
				this->updateList();
				this->menu();
			}
			else if(sel == "4")
			{
				this->selectList();
				this->menu();
			}
			else if(sel == "5")
			{
				this->displayList();
				this->menu();
			}
			else if(sel == "6")
			{
				this->statisticList();
				this->menu();
			}
			else if(sel == "7")
			{
				this->clearList();
				this->menu();
			}
			else if(sel == "0")
			{
				exit(0);
			}
		}

 效果如下

读取文件与写入文件

void readFile()
		{
			ifstream ifs;
			ifs.open("stuList.txt", ios::in);
			int n = 0; //用来接收学生数量的值
			ifs >> n;
			for(int i = 0; i < n; i++)
			{
				Student s;
				ifs >> s.stuNum >> s.stuName >> s.gender >> s.gradeNum >> s.department >> s.classNum >> s.cpNum >> s.score;
				for(int j = 0; j < s.cpNum; j++)
				{
					Subject cp;
					ifs >> cp.proName >> cp.proScore;
					s.cps.push_back(cp);
				}
				stuList.push_back(s);
			}
			ifs.close();
		}
		//写入文件
		void writeFile()
		{
			ofstream ofs;
			ofs.open("stuList.txt", ios::out);
			ofs << stuList.size() << endl; //先写入学生数量
			for (int i = 0; i < stuList.size(); i++)
			{
				ofs << stuList[i].stuNum << " " <<  stuList[i].stuName << " " << stuList[i].gender
				    << " " << stuList[i].gradeNum << " " << stuList[i].department << " " << stuList[i].classNum
				    << " " << stuList[i].cpNum << " " << stuList[i].score << endl;
				for(int j = 0; j < stuList[i].cps.size(); j++)
				{
					ofs << stuList[i].cps[j].proName << " " << stuList[i].cps[j].proScore << endl;
				}
			}
			ofs.close();
		}

 效果如下

   

 添加学生信息

void insertList()
		{
			while(true)
			{
				system("cls");
				cout << "\t\t**********************欢迎来到添加学生信息功能*************************" << endl;
				cout<< "\t\t学生基本信息一览表:"<<endl;
				displayStu();
				cout<<endl;
				cout << "\t\t------------------" << endl;
				cout << "\t\t1 添加学生信息" << endl;
				cout << "\t\t2 返回主菜单" << endl;
				cout << "\t\t------------------" << endl;
				cout << "\t\t请选择【1-2】:";
				string sel;
				cin >> sel;
				while(sel != "1" && sel != "2")
				{
					cout << "\t\t输入不合法,请重新输入【1-2】:";
					cin >> sel;
				}
				if(sel == "1")
				{
					string flag = "1";
					while (flag == "1")
					{
						cout << "\t\t输入学生信息:"<<endl;
						cout << "\t\t学号:";
						Student s;
						bool check = false;
						do
						{
							check = false;
							cin >> s.stuNum;
							for(int i = 0; i < stuList.size(); ++i)
							{
								if(s.stuNum == stuList[i].stuNum)
								{
									cout<<"\t\t该学号已存在,请重新输入:";
									check = true;
									break;
								}
							}
						}
						while(check);
						cout << "\t\t姓名:";
						cin >> s.stuName;
						cout << "\t\t性别:";
						cin >> s.gender;
						cout << "\t\t年级:";
						cin >> s.gradeNum;
						cout<<"\t\t专业:";
						cin >> s.department;
						cout<<"\t\t班级:";
						cin >> s.classNum;
						s.score = 0;
						string option = "1";
						cout<<"\t\t是否添加成绩信息?(1 是 0 否)"<<endl;
						cout << "\t\t请进行选择【0-1】:";
						cin >> option;
						while(option != "0" && option != "1")
						{
							cout << "\t\t输入不合法,请重新选择【0-1】:";
							cin >> option;
						}
						if(option == "1")
						{
							int cnt = 0;
							while(option == "1")
							{
								cnt++;
								Subject cp;
								cout<<"\t\t第"<<cnt<<"科科目名称:";
								cin>>cp.proName;
								cout<<"\t\t第"<<cnt<<"科科目成绩:";
								cin>>cp.proScore;
								s.cps.push_back(cp);
								cout << "\t\t该科成绩信息添加成功!是否继续添加?(1 是 0 否)" << endl;
								cout << "\t\t请进行选择【0-1】:";
								cin >> option;
								while(option != "0" && option != "1")
								{
									cout << "\t\t输入不合法,请重新选择【0-1】:";
									cin >> option;
								}
							}
						}
						for(int i = 0; i < s.cps.size(); i++)
						{
							s.score += s.cps[i].proScore;
						}
						if(s.cps.size() > 0) s.score /= s.cps.size(); //计算平均分
						s.cpNum = s.cps.size();
						stuList.push_back(s);
						writeFile();
						cout << "\n\t\t该名学生信息添加成功!是否继续添加?(1 是 0 否)" << endl;
						cout << "\t\t请进行选择【0-1】:";
						cin >> flag;
						while(flag != "0" && flag != "1")
						{
							cout << "\t\t输入不合法,请重新选择【0-1】:";
							cin >> flag;
						}
					}
					cout << "\t\t";
					system("pause");
				}
				else
				{
					break;
				}
			}
		}

效果如下

删除学生信息

void deleteList()
		{
			while (true)
			{
				system("cls");
				cout << "\t\t***********************欢迎来到删除学生信息功能***********************" << endl;
				string sel = "0";
				cout << "\t\t-----------------" << endl;
				cout << "\t\t1 按学号删除" << endl;
				cout << "\t\t2 按姓名删除" << endl;
				cout << "\t\t3 返回主菜单" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t请进行选择【1-3】:";
				cin >> sel;
				while(sel != "1" && sel != "2" && sel != "3")
				{
					cout << "\t\t输入不合法,请重新选择【1-3】:";
					cin >> sel;
				}
				if (sel == "1")
				{
					string keyNum;
					bool flag = false;
					cout << "\t\t请输入待删除学生的学号:";
					cin >> keyNum;
					for (vector<Student>::iterator it = stuList.begin(); it != stuList.end(); ++it)
					{
						if (it->stuNum == keyNum)
						{
							flag = true;
							cout << "\t\t待删除学生的信息如下:" << endl;
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							Student::showHeader();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							it->showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout << "\t\t确认删除?(1 是 0 否)" << endl;
							cout << "\t\t请进行选择【0-1】:";
							string ch = "0";
							cin >> ch;
							while(ch != "0" && ch != "1")
							{
								cout << "\t\t输入不合法,请重新选择【0-1】:";
								cin >> ch;
							}
							if (ch == "0") break;
							else
							{
								stuList.erase(it);
								writeFile();
								cout << "\t\t删除成功!" << endl;
								break;
							}
						}
					}
					if (!flag) cout << "\t\t查无此人,无法删除!\n" << endl;
					cout << "\t\t";
					system("pause");
				}
				else if (sel == "2")
				{
					string keyName;
					bool flag = false;
					cout << "\t\t请输入待删除学生的姓名:";
					cin >> keyName;
					for (vector<Student>::iterator it = stuList.begin(); it != stuList.end(); ++it)
					{
						if (it->stuName == keyName)
						{
							flag = true;
							cout << "\t\t待删除学生的信息如下:" << endl;
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t\t";
							Student::showHeader();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							it->showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout << "\t\t确认删除?(1 是 0 否)" << endl;
							cout << "\t\t请进行选择【0-1】:";
							string ch = "0";
							cin >> ch;
							while(ch != "0" && ch != "1")
							{
								cout << "\t\t输入不合法,请重新选择【0-1】:";
								cin >> ch;
							}
							if (ch == "0") break;
							else
							{
								stuList.erase(it);
								writeFile();
								cout << "\t\t删除成功!" << endl;
								break;
							}
						}
					}
					if (!flag) cout << "\t\t查无此人,无法删除!\n" << endl;
					cout << "\t\t";
					system("pause");
				}
				else
				{
					break;
				}
			}
		}

效果如下

修改学生信息

void updateList()
		{
			while(true)
			{
				system("cls");
				cout << "\t\t***********************欢迎来到修改学生信息功能***********************" << endl;
				string sel = "0";
				cout << "\t\t-----------------" << endl;
				cout << "\t\t1 修改学生基本信息" << endl;
				cout << "\t\t2 修改学生成绩信息" << endl;
				cout << "\t\t3 返回主菜单" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t请进行选择【1-3】:";
				cin >> sel;
				while(sel != "1" && sel != "2" && sel != "3")
				{
					cout << "\t\t输入不合法,请重新选择【1-3】:";
					cin >> sel;
				}

				if(sel == "1")
				{
					bool flag = false;
					string keyNum;
					cout << "\t\t请输入待修改学生的学号:";
					cin >> keyNum;
					for (int i = 0; i < stuList.size(); i++)
					{
						if (stuList[i].stuNum == keyNum)
						{
							flag = true;
							cout << "\t\t待修改学生基本信息如下:" << endl;
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							Student::showHeader();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							stuList[i].showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							
							Student s = stuList[i];
							cout << "\t\t请输入修改后的学号:";
							bool check = false;
							do
							{
								check = false;
								cin >> s.stuNum;
								for(int j = 0; j < stuList.size(); ++j)
								{
									if(s.stuNum == stuList[j].stuNum && i != j)
									{
										cout<<"\t\t该学号已被录入,请重新输入学号:";
										check = true;
										break;
									}
								}
							}
							while(check);
							cout << "\t\t请输入修改后的姓名:";
							cin >> s.stuName;
							cout << "\t\t请输入修改后的性别:";
							cin >> s.gender;
							cout << "\t\t请输入修改后的年级:";
							cin >> s.gradeNum;
							cout<<"\t\t请输入修改后的专业:";
							cin >> s.department;
							cout<<"\t\t请输入修改后的班级:";
							cin >> s.classNum;
							cout << "\t\t是否确认修改?(1 是 0 否)" << endl;
							cout << "\t\t请进行选择【0-1】:";
							string ch = "0";
							cin >> ch;
							while(ch != "0" && ch != "1")
							{
								cout << "\t\t输入不合法,请重新选择【0-1】:";
								cin >> ch;
							}

							if (ch == "0") break;
							else
							{
								stuList[i] = s;
								cout << "\t\t修改成功!" << endl;
								writeFile();
								break;
							}
						}
					}
					if (!flag) cout << "\t\t查无此人,无法修改!\n" << endl;
				}
				else if(sel == "2")
				{
					bool flag = false;
					string keyNum;
					cout << "\t\t请输入待修改学生的学号:";
					cin >> keyNum;
					for (int i = 0; i < stuList.size(); i++)
					{
						if (stuList[i].stuNum == keyNum)
						{
							flag = true;
							cout << "\t\t待修改学生成绩信息如下:" << endl;
							cout << "\t\t----------------------------------------------------------" << endl;
							cout<<"\t\t";
							cout << left << setw(8) <<  "编号";
							Subject::showHeader();
							cout << "\t\t----------------------------------------------------------" << endl;
							for(int j = 0; j < stuList[i].cps.size(); j++)
							{
								cout<<"\t\t";
								cout << left << setw(8) << j + 1;
								stuList[i].cps[j].showCpInfo();
							}
							cout << "\t\t----------------------------------------------------------" << endl;
							Student s = stuList[i];
							cout << "\t\t请选择修改方式:"<<endl;
							string option = "1";
							cout << "\t\t-------------------------------" << endl;
							cout << "\t\t1 基于该学生原有成绩信息进行修改" << endl;
							cout << "\t\t2 清空该学生所有科目及成绩信息" << endl;
							cout << "\t\t-------------------------------" << endl;
							cout << "\t\t请进行选择【1-2】:";
							cin >> option;
							while(option != "1" && option != "2")
							{
								cout << "\t\t输入不合法,请重新选择【1-2】:";
								cin >> option;
							}
							Subject cp;
							if(option == "1")
							{
								s.cps.clear();
								s.score = 0;
								s.cpNum = 0;
								cout<<"\t\t输入修改后的学科成绩信息:"<<endl;
								int cnt = 0;
								while(option == "1")
								{
									cnt++;
									cout<<"\t\t第"<<cnt<<"科科目名称:";
									cin>>cp.proName;
									cout<<"\t\t第"<<cnt<<"科科目成绩:";
									cin>>cp.proScore;
									s.cps.push_back(cp);
									cout << "\n\t\t添加成功!是否继续添加?(1 是 0 否)" << endl;
									cout << "\t\t请进行选择【0-1】:";
									cin >> option;
									while(option != "0" && option != "1")
									{
										cout << "\t\t输入不合法,请重新选择【0-1】:";
										cin >> option;
									}
								}
							}
							else if(option == "2")
							{
								s.cps.clear();
								s.score = 0;
								s.cpNum = 0;
							}
							//计算平均分
							for(int i = 0; i < s.cps.size(); i++)
							{
								s.score += s.cps[i].proScore;
							}
							if(s.cps.size() > 0) s.cpNum = s.cps.size();
							cout << "\t\t是否确认修改?(1 是 0 否)" << endl;
							cout << "\t\t请进行选择【0-1】:";
							string ch = "0";
							cin >> ch;
							while(ch != "0" && ch != "1")
							{
								cout << "\t\t输入不合法,请重新选择【0-1】:";
								cin >> ch;
							}
							if (ch == "0") break;
							else
							{
								stuList[i] = s;
								cout << "\t\t修改成功!" << endl;
								writeFile();
								break;
							}
						}
					}
					if (!flag) cout << "\t\t查无此人,无法修改!\n" << endl;
				}
				else
				{
					break;
				}
				cout << "\t\t";
				system("pause");
			}
		}

效果如下

 

显示信息列表

void selectList()
		{
			while (true)
			{
				system("cls");
				cout << "\t\t***********************欢迎来到查询学生信息功能************************" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t1 按学号查询" << endl;
				cout << "\t\t2 按姓名查询" << endl;
				cout << "\t\t3 返回主菜单" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t请进行选择【1-3】:";
				string sel = "0";
				cin >> sel;
				while(sel != "1" && sel != "2" && sel != "3")
				{
					cout << "\t\t输入不合法,请重新选择【1-3】:";
					cin >> sel;
				}
				if (sel == "1")
				{
					string keyNum;
					bool flag = false;
					cout << "\t\t请输入待查询学生的学号:";
					cin >> keyNum;
					cout << "\t\t查询结果如下:" << endl;
					cout<<"\t\t基本信息:"<<endl;
					cout << "\t\t-----------------------------------------------------------------------" << endl;
					cout<<"\t\t";
					Student::showHeader();
					cout << "\t\t-----------------------------------------------------------------------" << endl;
					for (int i = 0; i < stuList.size(); i++)
					{
						if (stuList[i].stuNum == keyNum)
						{
							flag = true;
							cout<<"\t\t";
							stuList[i].showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<endl;
							cout<<"\t\t"<<stuList[i].stuName<<"成绩信息:"<<endl;
							cout << "\t\t----------------------------------------------------------" << endl;
							cout<<"\t\t";
							cout << left << setw(8) <<  "编号";
							Subject::showHeader();
							cout << "\t\t----------------------------------------------------------" << endl;
							for(int j = 0; j < stuList[i].cps.size(); j++)
							{
								cout<<"\t\t";
								cout << left << setw(8) << j + 1;
								stuList[i].cps[j].showCpInfo();
							}
							cout << "\t\t----------------------------------------------------------" << endl;
							break;
						}
					}
					if (!flag) cout << "\t\t查无此人!\n" << endl;
					cout << "\t\t";
					system("pause");
				}
				else if (sel == "2")
				{
					string keyName;
					bool flag = false;
					cout << "\t\t请输入待查询联系人的姓名:";
					cin >> keyName;
					cout << "\t\t查询结果如下:" << endl;
					cout << "\t\t-----------------------------------------------------------------------" << endl;
					cout<<"\t\t";
					Student::showHeader();
					cout << "\t\t-----------------------------------------------------------------------" << endl;
					for (int i = 0; i < stuList.size(); i++)
					{
						if (stuList[i].stuName == keyName)
						{
							flag = true;
							cout<<"\t\t";
							stuList[i].showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<endl;
							cout<<"\t\t"<<stuList[i].stuName<<"成绩信息:"<<endl;
							cout << "\t\t----------------------------------------------------------" << endl;
							cout<<"\t\t";
							cout << left << setw(8) <<  "编号";
							Subject::showHeader();
							cout << "\t\t----------------------------------------------------------" << endl;
							for(int j = 0; j < stuList[i].cps.size(); j++)
							{
								cout<<"\t\t";
								cout << left << setw(8) << j + 1;
								stuList[i].cps[j].showCpInfo();
							}
							cout << "\t\t----------------------------------------------------------" << endl;
							break;
						}
					}
					if (!flag) cout << "\t\t查无此人!\n" << endl;
					cout << "\t\t";
					system("pause");
				}
				else 
				{
					break; 
				}
			}
		}
		//遍历学生列表
		void displayStu()
		{
			cout << "\t\t-----------------------------------------------------------------------" << endl;
			cout<<"\t\t";
			Student::showHeader();
			cout << "\t\t-----------------------------------------------------------------------" << endl;
			for (int i = 0; i < stuList.size(); i++)
			{
				cout << "\t\t";
				stuList[i].showStuInfo();
			}
			cout << "\t\t-----------------------------------------------------------------------" << endl;
		}
		//查询获奖信息
		void displayCp()
		{
			cout << "\t\t-----------------------------------------------------------------------" << endl;
			cout<<"\t\t";
			cout << left << setw(12) << "学号";
			cout << left << setw(10) <<  "姓名";
			Subject::showHeader();
			cout << "\t\t-----------------------------------------------------------------------" << endl;
			for (int i = 0; i < stuList.size(); i++)
			{
				for(int j = 0; j < stuList[i].cps.size(); j++)
				{
					cout << "\t\t";
					cout << left << setw(12) << stuList[i].stuNum;
					cout << left << setw(10) <<  stuList[i].stuName;
					stuList[i].cps[j].showCpInfo();
				}
			}
			cout << "\t\t-----------------------------------------------------------------------" << endl;
		}

显示学生列表

void displayList()
		{
			system("cls");
			cout << "\t\t***********************欢迎来到显示信息列表功能************************" << endl;
			cout << "\t\t表1:学生基本信息一览表"<<endl;
			this->displayStu();
			cout << "\n\t\t表2:学生成绩信息一览表"<<endl;
			this->displayCp();
			cout << "\t\t";
			system("pause");
		}

 效果如下

将学生列表按学号升序排列

static bool cmpNum(const Student& s1,const Student& s2)
		{
			return s1.stuNum < s2.stuNum;
		}

将学生列表按平均分降序排列,平均分相同的再按学号升序排列

static bool cmpscore(const Student& s1,const Student& s2)
		{
			if(s1.stuNum != s2.stuNum) return s1.score > s2.score;
			else return s1.stuNum < s2.stuNum;
		}

统计学生数据

void statisticList()
		{
			while(true)
			{
				system("cls");
				cout << "\t\t***********************欢迎来到统计学生数据功能************************" << endl;
				string sel = "0";
				cout << "\t\t-----------------" << endl;
				cout << "\t\t1 按学号排序" << endl;
				cout << "\t\t2 按平均分排序" << endl;
				cout << "\t\t3 返回主菜单" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t请进行选择【1-3】:";
				cin >> sel;
				while(sel != "1" && sel != "2" && sel != "3")
				{
					cout << "\t\t输入不合法,请重新选择【1-3】:";
					cin >> sel;
				}
				if(sel == "1")
				{
					sort(stuList.begin(), stuList.end(), cmpNum);
					cout<<"\t\t按学号升序排列如下:"<<endl;
					this->displayStu();
					int numMale = 0, numFemale = 0;
					for(int i = 0; i < stuList.size(); ++i)
					{
						if(stuList[i].gender == "男") numMale++;
						else if(stuList[i].gender == "女") numFemale++;
					}
					cout<<"\t\t一共 " << stuList.size() << " 人,其中男生 " << numMale << " 人,女生 " << numFemale << " 人。"<<endl;
					cout << "\t\t";
					system("pause");
				}
				else if(sel == "2")
				{
					sort(stuList.begin(), stuList.end(), cmpscore);
					cout<<"\t\t按平均分降序排列如下:"<<endl;
					this->displayStu();
					vector<int> z(10);
					double totalscore = 0;
					for(int i = 0; i < stuList.size(); ++i)
					{
						totalscore += stuList[i].score;
						if(0 <= stuList[i].score && stuList[i].score < 60) z[0]++;
						else if(60 <= stuList[i].score && stuList[i].score < 70) z[1]++;
						else if(70 <= stuList[i].score && stuList[i].score < 80) z[2]++;
						else if(80 <= stuList[i].score && stuList[i].score < 90) z[3]++;
						else z[4]++;
					}
					cout<<"\t\tscore < 60 -------------- " << z[0] << " 人" << endl;
					cout<<"\t\t60 <= score < 70 --------- " << z[1] << " 人" << endl;
					cout<<"\t\t70 <= score < 80 --------- " << z[2] << " 人" << endl;
					cout<<"\t\t80 <= score < 90 --------- " << z[3] << " 人" << endl;
					cout<<"\t\tscore >= 90 ------------- " << z[4] << " 人" << endl;
					cout<<"\t\t所有学生平均分为:"<<totalscore / stuList.size()<<endl;
					cout<<"\t\t"<<stuList.back().gradeNum<<"级"<<stuList.back().department<<stuList.back().classNum<<"班---";
					cout<<stuList.back().stuName<<"平均分最低,为:"<<stuList.back().score<<"分"<<endl;
					cout<<"\t\t"<<stuList.front().gradeNum<<"级"<<stuList.front().department<<stuList.front().classNum<<"班---";
					cout<<stuList.front().stuName<<"平均分最高,为:"<<stuList.front().score<<"分"<<endl;
					cout << "\t\t";
					system("pause");
				}
				else
				{
					break;
				}
			}
		}

效果如下

清空系统数据

void clearList()
		{
			while (true)
			{
				string sel = "0";
				system("cls");
				cout << "\t\t**************欢迎来到清空系统数据功能***************" << endl;
				cout << "\t\t------------------" << endl;
				cout << "\t\t1 确认清空系统数据" << endl;
				cout << "\t\t2 返回主菜单" << endl;
				cout << "\t\t------------------" << endl;
				cout << "\t\t请慎重选择【1-2】:";
				cin >> sel;
				while(sel != "1" && sel != "2")
				{
					cout << "\t\t输入不合法,请重新输入【1-2】:";
					cin >> sel;
				}
				if (sel == "1")
				{
					stuList.clear();
					cout << "\t\t清空成功!" << endl;
					cout << "\t\t";
					system("pause");
					writeFile();
				}
				else 
				{
					break;
				}
			}
		}
};

效果如下

5.总结

实现亮点:

界面简洁、每次操作完一个功能可进行一次清屏操作,仅保留功能提示文字;

排序功能实现了多种排序方式:单科排序以及总成绩排序

统计功能实现了平均分、及格人数、标准差等数据的统计

输出新文件时可以新建文件名,保存路径,输出文件同时统计数据:包括总分平均分、及格人数、标准差等;

读入文件允许输入文件路径进行读取;
不足之处:

代码实现中有些变量显得多余,部分变量命名与其功能不太匹配;

如需完整代码请给我一个一键三连,并评论:学生管理系统!我会根据大家情况发送完整代码

算了,还是发给大家吧,记得给个三连哈

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;
//学科科目类
class Subject
{
	public:
		string proName;  //学科名
		double proScore; //分数
		void showCpInfo()
		{
			cout << left << setw(45) << proName;
			cout << left << setw(6) <<  proScore << endl;
		}
		//输出属性名,只显示总积分
		static void showHeader()
		{
			cout << left << setw(45) << "科目";
			cout << left << setw(6) <<  "分数" <<endl;
		}
};
//学生类
class Student
{
	public:
		string stuNum;         //学号
		string stuName;        //姓名
		string gender;         //性别
		int gradeNum;          //年级
		string department;     //专业
		int classNum;          //班级
		vector<Subject> cps;  //学生的各个科目
		int cpNum;            //科目门数
		double score;         //平均分
		Student()
		{
		}
		Student(string stuNum, string stuName, string gender, int gradeNum, string department, int classNum,vector<Subject> cps, int cpNum, double score)
		{
			this->stuNum = stuNum;
			this->stuName = stuName;
			this->gender = gender;
			this->gradeNum = gradeNum;
			this->department = department;
			this->classNum = classNum;
			this->cps = cps;
			this->cpNum = cpNum;
			this->score = score;
		}
		~Student()
		{
		}
		//输出属性值  score是平均分
		void showStuInfo()
		{
			cout << left << setw(12) << stuNum;
			cout << left << setw(10) <<  stuName;
			cout << left << setw(6) << gender;
			cout << left << setw(8) << gradeNum;
			cout << left << setw(23) << department;
			cout << left << setw(6) << classNum;
			cout << left << setw(6) << score << endl;
		}
		//输出属性名
		static void showHeader()
		{
			cout << left << setw(12) << "学号";
			cout << left << setw(10) <<  "姓名";
			cout << left << setw(6) << "性别";
			cout << left << setw(8) << "年级";
			cout << left << setw(23) << "专业";
			cout << left << setw(6) << "班级";
			cout << left << setw(6) << "平均分" << endl;
		}
};
//学生列表类
class StudentList
{
	private:
		vector<Student> stuList;
	public:
		StudentList()
		{
		}
		StudentList(vector<Student> stuList)
		{
			this->stuList = stuList;
		}
		~StudentList()
		{
		}
		//初始化
		void init()
		{
			readFile(); //读取文件
		}
		//主菜单
		void menu()
		{
			string sel = "0";
			system("cls");
			cout << "\t\t\t**********欢迎来到学生成绩管理系统**********" << endl;
			cout << "\t\t\t你可以进行以下操作:" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             1   添加学生信息             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             2   删除学生信息             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             3   修改学生信息             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             4   查询学生信息             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             5   显示信息列表             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             6   统计学生数据             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             7   清空系统数据             |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t|             0   退出                     |" << endl;
			cout << "\t\t\t|------------------------------------------|" << endl;
			cout << "\t\t\t请选择【0-7】:";
			cin >> sel;
			while(sel != "0" && sel != "1" && sel != "2" && sel != "3" && sel != "4" && sel != "5" && sel != "6" && sel != "7")
			{
				cout << "\t\t\t输入不合法,请重新选择【0-7】:";
				cin >> sel;
			}
			if(sel == "1")
			{
				this->insertList();
				this->menu();
			}
			else if(sel == "2")
			{
				this->deleteList();
				this->menu();
			}
			else if(sel == "3")
			{
				this->updateList();
				this->menu();
			}
			else if(sel == "4")
			{
				this->selectList();
				this->menu();
			}
			else if(sel == "5")
			{
				this->displayList();
				this->menu();
			}
			else if(sel == "6")
			{
				this->statisticList();
				this->menu();
			}
			else if(sel == "7")
			{
				this->clearList();
				this->menu();
			}
			else if(sel == "0")
			{
				exit(0);
			}
		}
		//读取文件
		void readFile()
		{
			ifstream ifs;
			ifs.open("stuList.txt", ios::in);
			int n = 0; //用来接收学生数量的值
			ifs >> n;
			for(int i = 0; i < n; i++)
			{
				Student s;
				ifs >> s.stuNum >> s.stuName >> s.gender >> s.gradeNum >> s.department >> s.classNum >> s.cpNum >> s.score;
				for(int j = 0; j < s.cpNum; j++)
				{
					Subject cp;
					ifs >> cp.proName >> cp.proScore;
					s.cps.push_back(cp);
				}
				stuList.push_back(s);
			}
			ifs.close();
		}
		//写入文件
		void writeFile()
		{
			ofstream ofs;
			ofs.open("stuList.txt", ios::out);
			ofs << stuList.size() << endl; //先写入学生数量
			for (int i = 0; i < stuList.size(); i++)
			{
				ofs << stuList[i].stuNum << " " <<  stuList[i].stuName << " " << stuList[i].gender
				    << " " << stuList[i].gradeNum << " " << stuList[i].department << " " << stuList[i].classNum
				    << " " << stuList[i].cpNum << " " << stuList[i].score << endl;
				for(int j = 0; j < stuList[i].cps.size(); j++)
				{
					ofs << stuList[i].cps[j].proName << " " << stuList[i].cps[j].proScore << endl;
				}
			}
			ofs.close();
		}
		//添加学生信息
		void insertList()
		{
			while(true)
			{
				system("cls");
				cout << "\t\t**********************欢迎来到添加学生信息功能*************************" << endl;
				cout<< "\t\t学生基本信息一览表:"<<endl;
				displayStu();
				cout<<endl;
				cout << "\t\t------------------" << endl;
				cout << "\t\t1 添加学生信息" << endl;
				cout << "\t\t2 返回主菜单" << endl;
				cout << "\t\t------------------" << endl;
				cout << "\t\t请选择【1-2】:";
				string sel;
				cin >> sel;
				while(sel != "1" && sel != "2")
				{
					cout << "\t\t输入不合法,请重新输入【1-2】:";
					cin >> sel;
				}
				if(sel == "1")
				{
					string flag = "1";
					while (flag == "1")
					{
						cout << "\t\t输入学生信息:"<<endl;
						cout << "\t\t学号:";
						Student s;
						bool check = false;
						do
						{
							check = false;
							cin >> s.stuNum;
							for(int i = 0; i < stuList.size(); ++i)
							{
								if(s.stuNum == stuList[i].stuNum)
								{
									cout<<"\t\t该学号已存在,请重新输入:";
									check = true;
									break;
								}
							}
						}
						while(check);
						cout << "\t\t姓名:";
						cin >> s.stuName;
						cout << "\t\t性别:";
						cin >> s.gender;
						cout << "\t\t年级:";
						cin >> s.gradeNum;
						cout<<"\t\t专业:";
						cin >> s.department;
						cout<<"\t\t班级:";
						cin >> s.classNum;
						s.score = 0;
						string option = "1";
						cout<<"\t\t是否添加成绩信息?(1 是 0 否)"<<endl;
						cout << "\t\t请进行选择【0-1】:";
						cin >> option;
						while(option != "0" && option != "1")
						{
							cout << "\t\t输入不合法,请重新选择【0-1】:";
							cin >> option;
						}
						if(option == "1")
						{
							int cnt = 0;
							while(option == "1")
							{
								cnt++;
								Subject cp;
								cout<<"\t\t第"<<cnt<<"科科目名称:";
								cin>>cp.proName;
								cout<<"\t\t第"<<cnt<<"科科目成绩:";
								cin>>cp.proScore;
								s.cps.push_back(cp);
								cout << "\t\t该科成绩信息添加成功!是否继续添加?(1 是 0 否)" << endl;
								cout << "\t\t请进行选择【0-1】:";
								cin >> option;
								while(option != "0" && option != "1")
								{
									cout << "\t\t输入不合法,请重新选择【0-1】:";
									cin >> option;
								}
							}
						}
						for(int i = 0; i < s.cps.size(); i++)
						{
							s.score += s.cps[i].proScore;
						}
						if(s.cps.size() > 0) s.score /= s.cps.size(); //计算平均分
						s.cpNum = s.cps.size();
						stuList.push_back(s);
						writeFile();
						cout << "\n\t\t该名学生信息添加成功!是否继续添加?(1 是 0 否)" << endl;
						cout << "\t\t请进行选择【0-1】:";
						cin >> flag;
						while(flag != "0" && flag != "1")
						{
							cout << "\t\t输入不合法,请重新选择【0-1】:";
							cin >> flag;
						}
					}
					cout << "\t\t";
					system("pause");
				}
				else
				{
					break;
				}
			}
		}
		//删除学生信息
		void deleteList()
		{
			while (true)
			{
				system("cls");
				cout << "\t\t***********************欢迎来到删除学生信息功能***********************" << endl;
				string sel = "0";
				cout << "\t\t-----------------" << endl;
				cout << "\t\t1 按学号删除" << endl;
				cout << "\t\t2 按姓名删除" << endl;
				cout << "\t\t3 返回主菜单" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t请进行选择【1-3】:";
				cin >> sel;
				while(sel != "1" && sel != "2" && sel != "3")
				{
					cout << "\t\t输入不合法,请重新选择【1-3】:";
					cin >> sel;
				}
				if (sel == "1")
				{
					string keyNum;
					bool flag = false;
					cout << "\t\t请输入待删除学生的学号:";
					cin >> keyNum;
					for (vector<Student>::iterator it = stuList.begin(); it != stuList.end(); ++it)
					{
						if (it->stuNum == keyNum)
						{
							flag = true;
							cout << "\t\t待删除学生的信息如下:" << endl;
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							Student::showHeader();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							it->showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout << "\t\t确认删除?(1 是 0 否)" << endl;
							cout << "\t\t请进行选择【0-1】:";
							string ch = "0";
							cin >> ch;
							while(ch != "0" && ch != "1")
							{
								cout << "\t\t输入不合法,请重新选择【0-1】:";
								cin >> ch;
							}
							if (ch == "0") break;
							else
							{
								stuList.erase(it);
								writeFile();
								cout << "\t\t删除成功!" << endl;
								break;
							}
						}
					}
					if (!flag) cout << "\t\t查无此人,无法删除!\n" << endl;
					cout << "\t\t";
					system("pause");
				}
				else if (sel == "2")
				{
					string keyName;
					bool flag = false;
					cout << "\t\t请输入待删除学生的姓名:";
					cin >> keyName;
					for (vector<Student>::iterator it = stuList.begin(); it != stuList.end(); ++it)
					{
						if (it->stuName == keyName)
						{
							flag = true;
							cout << "\t\t待删除学生的信息如下:" << endl;
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t\t";
							Student::showHeader();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							it->showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout << "\t\t确认删除?(1 是 0 否)" << endl;
							cout << "\t\t请进行选择【0-1】:";
							string ch = "0";
							cin >> ch;
							while(ch != "0" && ch != "1")
							{
								cout << "\t\t输入不合法,请重新选择【0-1】:";
								cin >> ch;
							}
							if (ch == "0") break;
							else
							{
								stuList.erase(it);
								writeFile();
								cout << "\t\t删除成功!" << endl;
								break;
							}
						}
					}
					if (!flag) cout << "\t\t查无此人,无法删除!\n" << endl;
					cout << "\t\t";
					system("pause");
				}
				else
				{
					break;
				}
			}
		}
		//修改学生信息
		void updateList()
		{
			while(true)
			{
				system("cls");
				cout << "\t\t***********************欢迎来到修改学生信息功能***********************" << endl;
				string sel = "0";
				cout << "\t\t-----------------" << endl;
				cout << "\t\t1 修改学生基本信息" << endl;
				cout << "\t\t2 修改学生成绩信息" << endl;
				cout << "\t\t3 返回主菜单" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t请进行选择【1-3】:";
				cin >> sel;
				while(sel != "1" && sel != "2" && sel != "3")
				{
					cout << "\t\t输入不合法,请重新选择【1-3】:";
					cin >> sel;
				}

				if(sel == "1")
				{
					bool flag = false;
					string keyNum;
					cout << "\t\t请输入待修改学生的学号:";
					cin >> keyNum;
					for (int i = 0; i < stuList.size(); i++)
					{
						if (stuList[i].stuNum == keyNum)
						{
							flag = true;
							cout << "\t\t待修改学生基本信息如下:" << endl;
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							Student::showHeader();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<"\t\t";
							stuList[i].showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							
							Student s = stuList[i];
							cout << "\t\t请输入修改后的学号:";
							bool check = false;
							do
							{
								check = false;
								cin >> s.stuNum;
								for(int j = 0; j < stuList.size(); ++j)
								{
									if(s.stuNum == stuList[j].stuNum && i != j)
									{
										cout<<"\t\t该学号已被录入,请重新输入学号:";
										check = true;
										break;
									}
								}
							}
							while(check);
							cout << "\t\t请输入修改后的姓名:";
							cin >> s.stuName;
							cout << "\t\t请输入修改后的性别:";
							cin >> s.gender;
							cout << "\t\t请输入修改后的年级:";
							cin >> s.gradeNum;
							cout<<"\t\t请输入修改后的专业:";
							cin >> s.department;
							cout<<"\t\t请输入修改后的班级:";
							cin >> s.classNum;
							cout << "\t\t是否确认修改?(1 是 0 否)" << endl;
							cout << "\t\t请进行选择【0-1】:";
							string ch = "0";
							cin >> ch;
							while(ch != "0" && ch != "1")
							{
								cout << "\t\t输入不合法,请重新选择【0-1】:";
								cin >> ch;
							}

							if (ch == "0") break;
							else
							{
								stuList[i] = s;
								cout << "\t\t修改成功!" << endl;
								writeFile();
								break;
							}
						}
					}
					if (!flag) cout << "\t\t查无此人,无法修改!\n" << endl;
				}
				else if(sel == "2")
				{
					bool flag = false;
					string keyNum;
					cout << "\t\t请输入待修改学生的学号:";
					cin >> keyNum;
					for (int i = 0; i < stuList.size(); i++)
					{
						if (stuList[i].stuNum == keyNum)
						{
							flag = true;
							cout << "\t\t待修改学生成绩信息如下:" << endl;
							cout << "\t\t----------------------------------------------------------" << endl;
							cout<<"\t\t";
							cout << left << setw(8) <<  "编号";
							Subject::showHeader();
							cout << "\t\t----------------------------------------------------------" << endl;
							for(int j = 0; j < stuList[i].cps.size(); j++)
							{
								cout<<"\t\t";
								cout << left << setw(8) << j + 1;
								stuList[i].cps[j].showCpInfo();
							}
							cout << "\t\t----------------------------------------------------------" << endl;
							Student s = stuList[i];
							cout << "\t\t请选择修改方式:"<<endl;
							string option = "1";
							cout << "\t\t-------------------------------" << endl;
							cout << "\t\t1 基于该学生原有成绩信息进行修改" << endl;
							cout << "\t\t2 清空该学生所有科目及成绩信息" << endl;
							cout << "\t\t-------------------------------" << endl;
							cout << "\t\t请进行选择【1-2】:";
							cin >> option;
							while(option != "1" && option != "2")
							{
								cout << "\t\t输入不合法,请重新选择【1-2】:";
								cin >> option;
							}
							Subject cp;
							if(option == "1")
							{
								s.cps.clear();
								s.score = 0;
								s.cpNum = 0;
								cout<<"\t\t输入修改后的学科成绩信息:"<<endl;
								int cnt = 0;
								while(option == "1")
								{
									cnt++;
									cout<<"\t\t第"<<cnt<<"科科目名称:";
									cin>>cp.proName;
									cout<<"\t\t第"<<cnt<<"科科目成绩:";
									cin>>cp.proScore;
									s.cps.push_back(cp);
									cout << "\n\t\t添加成功!是否继续添加?(1 是 0 否)" << endl;
									cout << "\t\t请进行选择【0-1】:";
									cin >> option;
									while(option != "0" && option != "1")
									{
										cout << "\t\t输入不合法,请重新选择【0-1】:";
										cin >> option;
									}
								}
							}
							else if(option == "2")
							{
								s.cps.clear();
								s.score = 0;
								s.cpNum = 0;
							}
							//计算平均分
							for(int i = 0; i < s.cps.size(); i++)
							{
								s.score += s.cps[i].proScore;
							}
							if(s.cps.size() > 0) s.cpNum = s.cps.size();
							cout << "\t\t是否确认修改?(1 是 0 否)" << endl;
							cout << "\t\t请进行选择【0-1】:";
							string ch = "0";
							cin >> ch;
							while(ch != "0" && ch != "1")
							{
								cout << "\t\t输入不合法,请重新选择【0-1】:";
								cin >> ch;
							}
							if (ch == "0") break;
							else
							{
								stuList[i] = s;
								cout << "\t\t修改成功!" << endl;
								writeFile();
								break;
							}
						}
					}
					if (!flag) cout << "\t\t查无此人,无法修改!\n" << endl;
				}
				else
				{
					break;
				}
				cout << "\t\t";
				system("pause");
			}
		}
		//查询学生信息
		void selectList()
		{
			while (true)
			{
				system("cls");
				cout << "\t\t***********************欢迎来到查询学生信息功能************************" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t1 按学号查询" << endl;
				cout << "\t\t2 按姓名查询" << endl;
				cout << "\t\t3 返回主菜单" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t请进行选择【1-3】:";
				string sel = "0";
				cin >> sel;
				while(sel != "1" && sel != "2" && sel != "3")
				{
					cout << "\t\t输入不合法,请重新选择【1-3】:";
					cin >> sel;
				}
				if (sel == "1")
				{
					string keyNum;
					bool flag = false;
					cout << "\t\t请输入待查询学生的学号:";
					cin >> keyNum;
					cout << "\t\t查询结果如下:" << endl;
					cout<<"\t\t基本信息:"<<endl;
					cout << "\t\t-----------------------------------------------------------------------" << endl;
					cout<<"\t\t";
					Student::showHeader();
					cout << "\t\t-----------------------------------------------------------------------" << endl;
					for (int i = 0; i < stuList.size(); i++)
					{
						if (stuList[i].stuNum == keyNum)
						{
							flag = true;
							cout<<"\t\t";
							stuList[i].showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<endl;
							cout<<"\t\t"<<stuList[i].stuName<<"成绩信息:"<<endl;
							cout << "\t\t----------------------------------------------------------" << endl;
							cout<<"\t\t";
							cout << left << setw(8) <<  "编号";
							Subject::showHeader();
							cout << "\t\t----------------------------------------------------------" << endl;
							for(int j = 0; j < stuList[i].cps.size(); j++)
							{
								cout<<"\t\t";
								cout << left << setw(8) << j + 1;
								stuList[i].cps[j].showCpInfo();
							}
							cout << "\t\t----------------------------------------------------------" << endl;
							break;
						}
					}
					if (!flag) cout << "\t\t查无此人!\n" << endl;
					cout << "\t\t";
					system("pause");
				}
				else if (sel == "2")
				{
					string keyName;
					bool flag = false;
					cout << "\t\t请输入待查询联系人的姓名:";
					cin >> keyName;
					cout << "\t\t查询结果如下:" << endl;
					cout << "\t\t-----------------------------------------------------------------------" << endl;
					cout<<"\t\t";
					Student::showHeader();
					cout << "\t\t-----------------------------------------------------------------------" << endl;
					for (int i = 0; i < stuList.size(); i++)
					{
						if (stuList[i].stuName == keyName)
						{
							flag = true;
							cout<<"\t\t";
							stuList[i].showStuInfo();
							cout << "\t\t-----------------------------------------------------------------------" << endl;
							cout<<endl;
							cout<<"\t\t"<<stuList[i].stuName<<"成绩信息:"<<endl;
							cout << "\t\t----------------------------------------------------------" << endl;
							cout<<"\t\t";
							cout << left << setw(8) <<  "编号";
							Subject::showHeader();
							cout << "\t\t----------------------------------------------------------" << endl;
							for(int j = 0; j < stuList[i].cps.size(); j++)
							{
								cout<<"\t\t";
								cout << left << setw(8) << j + 1;
								stuList[i].cps[j].showCpInfo();
							}
							cout << "\t\t----------------------------------------------------------" << endl;
							break;
						}
					}
					if (!flag) cout << "\t\t查无此人!\n" << endl;
					cout << "\t\t";
					system("pause");
				}
				else 
				{
					break; 
				}
			}
		}
		//遍历学生列表
		void displayStu()
		{
			cout << "\t\t-----------------------------------------------------------------------" << endl;
			cout<<"\t\t";
			Student::showHeader();
			cout << "\t\t-----------------------------------------------------------------------" << endl;
			for (int i = 0; i < stuList.size(); i++)
			{
				cout << "\t\t";
				stuList[i].showStuInfo();
			}
			cout << "\t\t-----------------------------------------------------------------------" << endl;
		}
		//查询获奖信息
		void displayCp()
		{
			cout << "\t\t-----------------------------------------------------------------------" << endl;
			cout<<"\t\t";
			cout << left << setw(12) << "学号";
			cout << left << setw(10) <<  "姓名";
			Subject::showHeader();
			cout << "\t\t-----------------------------------------------------------------------" << endl;
			for (int i = 0; i < stuList.size(); i++)
			{
				for(int j = 0; j < stuList[i].cps.size(); j++)
				{
					cout << "\t\t";
					cout << left << setw(12) << stuList[i].stuNum;
					cout << left << setw(10) <<  stuList[i].stuName;
					stuList[i].cps[j].showCpInfo();
				}
			}
			cout << "\t\t-----------------------------------------------------------------------" << endl;
		}

		//显示信息列表
		void displayList()
		{
			system("cls");
			cout << "\t\t***********************欢迎来到显示信息列表功能************************" << endl;
			cout << "\t\t表1:学生基本信息一览表"<<endl;
			this->displayStu();
			cout << "\n\t\t表2:学生成绩信息一览表"<<endl;
			this->displayCp();
			cout << "\t\t";
			system("pause");
		}
		//将学生列表按学号升序排列
		static bool cmpNum(const Student& s1,const Student& s2)
		{
			return s1.stuNum < s2.stuNum;
		}
		//将学生列表按平均分降序排列,平均分相同的再按学号升序排列
		static bool cmpscore(const Student& s1,const Student& s2)
		{
			if(s1.stuNum != s2.stuNum) return s1.score > s2.score;
			else return s1.stuNum < s2.stuNum;
		}
		//统计学生数据
		void statisticList()
		{
			while(true)
			{
				system("cls");
				cout << "\t\t***********************欢迎来到统计学生数据功能************************" << endl;
				string sel = "0";
				cout << "\t\t-----------------" << endl;
				cout << "\t\t1 按学号排序" << endl;
				cout << "\t\t2 按平均分排序" << endl;
				cout << "\t\t3 返回主菜单" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t请进行选择【1-3】:";
				cin >> sel;
				while(sel != "1" && sel != "2" && sel != "3")
				{
					cout << "\t\t输入不合法,请重新选择【1-3】:";
					cin >> sel;
				}
				if(sel == "1")
				{
					sort(stuList.begin(), stuList.end(), cmpNum);
					cout<<"\t\t按学号升序排列如下:"<<endl;
					this->displayStu();
					int numMale = 0, numFemale = 0;
					for(int i = 0; i < stuList.size(); ++i)
					{
						if(stuList[i].gender == "男") numMale++;
						else if(stuList[i].gender == "女") numFemale++;
					}
					cout<<"\t\t一共 " << stuList.size() << " 人,其中男生 " << numMale << " 人,女生 " << numFemale << " 人。"<<endl;
					cout << "\t\t";
					system("pause");
				}
				else if(sel == "2")
				{
					sort(stuList.begin(), stuList.end(), cmpscore);
					cout<<"\t\t按平均分降序排列如下:"<<endl;
					this->displayStu();
					vector<int> z(10);
					double totalscore = 0;
					for(int i = 0; i < stuList.size(); ++i)
					{
						totalscore += stuList[i].score;
						if(0 <= stuList[i].score && stuList[i].score < 60) z[0]++;
						else if(60 <= stuList[i].score && stuList[i].score < 70) z[1]++;
						else if(70 <= stuList[i].score && stuList[i].score < 80) z[2]++;
						else if(80 <= stuList[i].score && stuList[i].score < 90) z[3]++;
						else z[4]++;
					}
					cout<<"\t\tscore < 60 -------------- " << z[0] << " 人" << endl;
					cout<<"\t\t60 <= score < 70 --------- " << z[1] << " 人" << endl;
					cout<<"\t\t70 <= score < 80 --------- " << z[2] << " 人" << endl;
					cout<<"\t\t80 <= score < 90 --------- " << z[3] << " 人" << endl;
					cout<<"\t\tscore >= 90 ------------- " << z[4] << " 人" << endl;
					cout<<"\t\t所有学生平均分为:"<<totalscore / stuList.size()<<endl;
					cout<<"\t\t"<<stuList.back().gradeNum<<"级"<<stuList.back().department<<stuList.back().classNum<<"班---";
					cout<<stuList.back().stuName<<"平均分最低,为:"<<stuList.back().score<<"分"<<endl;
					cout<<"\t\t"<<stuList.front().gradeNum<<"级"<<stuList.front().department<<stuList.front().classNum<<"班---";
					cout<<stuList.front().stuName<<"平均分最高,为:"<<stuList.front().score<<"分"<<endl;
					cout << "\t\t";
					system("pause");
				}
				else
				{
					break;
				}
			}
		}
		//清空系统数据
		void clearList()
		{
			while (true)
			{
				string sel = "0";
				system("cls");
				cout << "\t\t**************欢迎来到清空系统数据功能***************" << endl;
				cout << "\t\t------------------" << endl;
				cout << "\t\t1 确认清空系统数据" << endl;
				cout << "\t\t2 返回主菜单" << endl;
				cout << "\t\t------------------" << endl;
				cout << "\t\t请慎重选择【1-2】:";
				cin >> sel;
				while(sel != "1" && sel != "2")
				{
					cout << "\t\t输入不合法,请重新输入【1-2】:";
					cin >> sel;
				}
				if (sel == "1")
				{
					stuList.clear();
					cout << "\t\t清空成功!" << endl;
					cout << "\t\t";
					system("pause");
					writeFile();
				}
				else 
				{
					break;
				}
			}
		}
};

int main()
{
	StudentList stuList;
	stuList.init(); //读入文件数据初始化
	stuList.menu(); //打开主菜单
	return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/415763.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

文件操作File类,OutputStream、InputStream、Reader、Writer的用法

文章目录File 类OutputStream、InputStreamInputStreamOutputStreamReader、WriterReaderWriter注意事项简单模拟实战File 类 Java标准库中提供的File类是对硬盘上的文件的抽象&#xff0c;每一个File对象代表了一个文件&#xff0c;因为文件在硬盘上存储&#xff0c;而直接操…

4月11日作业修订

A.这主要看你互斥锁锁的资源是那部分的&#xff0c;如果是进程内资源&#xff0c;则可以实现同一进程不同线程之间的互斥&#xff0c;而如果将共享内存作为互斥锁进行操作则可以实现不同进程之间的互斥。 B.这是必然的&#xff0c;加锁是为了防止数据的二义性 C.信号量同时使…

代码规范(以后会补充)

目录 为什么要规范代码 不规范的代码有什么特点 ​编辑 不规范的坏处 规范代码是什么样的 如何规范代码 1.代码中不要出现莫名其妙的数字 2.深度嵌套 3.注释 4.避免创建大函数 5.重复代码 6.变量命名 7.函数命名 8.命名时注意动词的使用 9. 常量值所有都大写 10. 避免变…

Bossies 2016:最佳开源大数据工具

导读在今年的 Bossie开源大数据工具中&#xff0c;你会发现最新最好的方法是利用大型集群进行索引、搜索、图形处理、流处理、结构化查询、分布式OLAP和机器学习&#xff0c;因为众多处理器和RAM可降低工作量级。 处理大数据可能会遇到各种各样的问题&#xff0c;目前没有任何工…

SpringMVC简介及入门

SpringMVC SpringMVC简介 一、三层架构和MVC 1、三层架构概述 &#xff08;1&#xff09;开发架构&#xff1a;一是 C/S 架构 (客户端/服务器)&#xff0c;二是B/S架构&#xff08;浏览器/服务器)。在JavaEE开发中&#xff0c;几乎全部是基于 B/S架构的开发。在B/S 架构中&…

最简单IDEA社区版构建SpringBoot项目

一、环境准备 IDEA Community Edition jdk8 maven 二、下载SpringBoot项目 https://start.spring.io/ 项目名称自己修改下。 点击ADD DEPENDENCIES&#xff0c;添加Web依赖。 下载构建好的SpringBoot项目的压缩包 三、idea中打开SpringBoot项目 使用maven加载依赖。 四、测…

【数据库原理 • 三】关系数据库标准语言SQL

前言 数据库技术是计算机科学技术中发展最快&#xff0c;应用最广的技术之一&#xff0c;它是专门研究如何科学的组织和存储数据&#xff0c;如何高效地获取和处理数据的技术。它已成为各行各业存储数据、管理信息、共享资源和决策支持的最先进&#xff0c;最常用的技术。 当前…

4.7 AOP底层源码原理

4.7.1 AOP源码 进入到这里 F8跳过assertBeanFactoryActive方法&#xff0c;因为spring它方法调用太乱了&#xff0c;如果不挑“核心”去看&#xff0c;很快你就会被绕晕&#xff0c; 那么我们怎么判断这个assertBeanFactoryActive不是核心&#xff0c;注意前面getbean方法返回…

《淘宝网店》:计算总收益

目录 一、题目 二、思路 1、当两个年份不一样的时候 &#xff08;1&#xff09;from年剩余之后的收益 &#xff08;2&#xff09;中间年份的全部收益 &#xff08;3&#xff09;to年有的收益 2、同一个年份 三、代码 详细注释版本&#xff1a; 简化注释版本&#xff…

RC滤波器

前阶段&#xff0c;因项目解干扰问题&#xff0c;和同事聊起来RC滤波。所以&#xff0c;今日借此机会&#xff0c;通过文章的方式再一次给大家简单的普及一下RC滤波的知识。 关于滤波&#xff0c;其目的还是为了尽可能多的让有用信号做到无衰减&#xff0c;无用信号衰减至近乎…

云南计算机专升本经验分享

一、概述 经验分享 越早准备越好&#xff0c;切勿过分迷信同学的学习进度。 英语(97) 在云南专升本里面&#xff0c;英语在90以上已经是不错了&#xff0c;我由于自身基础不好原因&#xff0c;导致我刚开始一度想放弃英语&#xff0c;所以对英语的学习也是极尽节俭&#xff0…

Python每日一练(20230416)

目录 1. 有效数字 &#x1f31f;&#x1f31f;&#x1f31f; 2. 二叉树的最大深度 &#x1f31f; 3. 单词搜索 &#x1f31f;&#x1f31f; &#x1f31f; 每日一练刷题专栏 &#x1f31f; Golang每日一练 专栏 Python每日一练 专栏 C/C每日一练 专栏 Java每日一练 …

【RabbitMQ】图解RabbitMQ是如何保证消息可靠性的

目录 一、概述 1、消息可靠性 2、SpringBoot整合RabbitMQ配置文件 二、生产者---RabbitMQ服务器如何保证信息不丢失 1、confirm确认模式 1.说明 2.SpringBoot代码实现 2、return退回模式 1.说明 2.SpringBoot代码实现 三、RabbitMQ服务器如何保证消息不丢失 四、Ra…

Logstash:使用自定义正则表达式模式

有时 Logstash Grok 没有我们需要的模式。 幸运的是我们有正则表达式库&#xff1a;Oniguruma。在很多时候&#xff0c;如果 Logstash 所提供的正则表达不能满足我们的需求&#xff0c;我们选用定制自己的表达式。 定义 Logstash 是一种服务器端数据处理管道&#xff0c;可同时…

zabbix客户端配置

一、zabbix客户端配置 1.实验环境&#xff1a;关闭防火墙和安全模块 systemctl disable --now firewalld setenforce 0 2.服务端和客户端都要时间同步 yum install -y ntpdate #注意安装需要用网络源安装&#xff0c;不能用本地源 ntpda…

电子器件系列34:tvs二极管(2)

一、基本原理&#xff1a; 二、重要产数&#xff1a; 不同的资料对于相同的参数可能有不同的命名&#xff0c;要根据实际情况来确定参数的意义 这里以上图表格里的参数名称进行解析&#xff0c;以其他资料作为参考。 结合图表和伏安特性曲线&#xff0c;再结合下面的图我是…

你认为的.NET数据库连接池,真的是全部吗?

一般我们的项目中会使用1到2个数据库连接配置&#xff0c;同程艺龙的数据库连接被收拢到配置中心&#xff0c;由DBA统一配置和维护&#xff0c;业务方通过某个字符串配置拿到的是开箱即用的Connection对象。 DBA能在对业务方无侵入的情况下&#xff0c;让大规模微服务实例切换…

第二周P9-P22

文章目录第三章 系统总线3.1、总线的基本概念一、为什么要用总线二、什么是总线三、总线上信息的传送四、总线结构的计算机举例1、单总线结构框图2、面向CPU的双总线结构框图3、以存储器为中心的双总线结构图3.2、总线的分类1、片内总线2、系统总线3、通信走线3.3、总线特性及性…

基于多目标粒子群优化算法的计及光伏波动性的主动配电网有功无功协调优化(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

Vivado中ILA(集成逻辑分析仪)的使用

Vivado中ILA&#xff08;集成逻辑分析仪&#xff09;的使用一、写在前面二、ILA(Integrated Logic Analyzer)的使用2.1 ILA查找2.2 ILA配置2.2.1 General Options2.2.2 Probe Ports三、ILA调用四、ILA联调4.1 信号窗口4.2 波形窗口4.3 状态窗口4.4 设置窗口4.5 触发条件设置窗口…