C++基于vector容器的学生成绩管理系统

**C++基于vector容器的学生成绩管理系统**

  • 1.引言
  • 2.设计依据及框图
    • 2.1设计平台
    • 2.2设计思想及功能
    • 2.3系统执行流程图
  • 3.各模块功能设计
    • 3.1头文件声明
    • 3.2系统中类的定义
    • 3.3系统中定义的函数列表
    • 3.4主菜单界面模块
    • 3.5添加学生信息模块
    • 3.6学生信息查询模块
    • 3.7学生信息修改模块
    • 3.8学生信息删除模块
    • 3.9学生GPA排名模块
    • 3.10打印学生信息模块
  • 源码

1.引言

C++是C语言的继承,它既可以进行C语言的过程化程序设计,又可以进行以抽象数据类型为特点的基于对象的程序设计,还可以进行以继承和多态为特点的面向对象的程序设计。C++擅长面向对象程序设计的同时,还可以进行基于过程的程序设计,因而C++就适应的问题规模而论,大小由之。
C++不仅拥有计算机高效运行的实用性特征,同时还致力于提高大规模程序的编程质量与程序设计语言的问题描述能力。

2.设计依据及框图

2.1设计平台

Visual C++是Microsoft公司推出的功能最强大、也是最复杂的程序设计工具之一。它最常用的版本为Visual C++ 6.0。
Visual C++ 6.0集程序的代码编辑、编译、连接、调试等功能于一体,为编程人员提供了一个既完整又方便的开发环境。此外,Visual C++ 6.0不仅支持传统的软件开发方法,还支持面向对象的开发风格,其可以看作是一个集成开发工具,提供了软件代码自动生成和可视化的资源编辑功能。Visual C++ 6.0具有一些其他可视化集成开发软件所不具备的特性。

2.2设计思想及功能

系统采用结构化,面向对象的程序设计方法进行,采用文件存储数据,采用C++语言进行开发,程序的书写是锯齿状,各个函数分开存放。
在添加模块中能新添加相应学生的信息;在修改函数中添加了修改单项学生信息;在搜索模块中可以根据所选类型的分类显示该分类的相应的学生的信息;在删除模块中能根据相应的名字选择学生信息进行删除;在统计模块中,可以显示学生所有信息。

2.3系统执行流程图

C++基于vector容器的学生成绩管理系统_第1张图片

3.各模块功能设计

3.1头文件声明

为了实现各个模块的功能,系统中声明了所需的头文件:

#include
#include
#include
#include
#include
#include

3.2系统中类的定义

系统中通过定义学生类,课程类和成绩类三类,并通过C++的继承派生特性,实现三个类之间的联系,
联系如下图:C++基于vector容器的学生成绩管理系统_第2张图片

此外本课设还采用vector容器进行编写:

class Student		//学生类
{
     
public:
	Student( string name, int id, string sex)
	{
     
        this->name = name;
		this->id = id;
		this->sex = sex;
	}
	string name;
	int id;
	string sex;
};

class Grade			//课程类
{
     
public:
	string English;
	string Math;
	string C_plus;
	string Analog_circuit;
	string Sports;
	string Matlab;
	string Data_structure;
	string Physical;
};					

class Score : public Grade,virtual public Student	//成绩类
{
     
public:
	Score(string name, int id, string sex, float English_score, float Math_score, float C_plus_score, float Analog_circuit_score, float Sports_score, float Matlab_score, float Data_structure_score, float Physical_score) :Student(name, id, sex)
	{
     
		this->English_score = English_score;
		this->Math_score = Math_score;
		this->C_plus_score = C_plus_score;
		this->Analog_circuit_score = Analog_circuit_score;
		this->Sports_score = Sports_score;
		this->Matlab_score = Matlab_score;
		this->Data_structure_score = Data_structure_score;
		this->Physical_score = Physical_score;
		GPA = (English_score + Math_score + C_plus_score + Analog_circuit_score + Sports_score + Matlab_score + Data_structure_score + Physical_score) / 8.0;
	}
	float English_score;
	float Math_score; 
	float C_plus_score;
	float Analog_circuit_score;
	float Sports_score;
	float Matlab_score;
	float Data_structure_score;
	float Physical_score;
	float GPA;
};
class stusystem
{
     
public:
	stusystem()    //打开文件
	{
     
		ifstream ifs("学生成绩.txt", ios::in);
		if (ifs.is_open() != NULL)
		{
     
			string name, sex;
			int id;
			float English_score;
			float Math_score;
			float C_plus_score;
			float Analog_circuit_score;
			float Sports_score;
			float Matlab_score;
			float Data_structure_score;
			float Physical_score;
			float GPA;    
			while (ifs >> name >> id >> sex >> English_score >> Math_score >> C_plus_score >> Analog_circuit_score >> Sports_score >> Matlab_score >> Data_structure_score >> Physical_score)
			{
     
				Score s(name , id , sex , English_score , Math_score , C_plus_score , Analog_circuit_score , Sports_score , Matlab_score , Data_structure_score , Physical_score);
				a.push_back(s);
			}
		}
	}
	vector<Score>a;
	void Save();       //保存
	void Add();        //添加
	void AddAgain();   //再度添加
	void Del();        //删除
	void Find();       //查找菜单
	void Findname();   //查找名字
	void Findid();     //查找学号
	void Sort();       //排序
	void Remake();     //重新编辑
	void Print();      //打印
	void mainmenu()    //主菜单
};

操作类stysystem执行流程图如下:C++基于vector容器的学生成绩管理系统_第3张图片

3.3系统中定义的函数列表

为了实现相应的功能,在程序的设计中定义了相关的函数,各个函数原型如下:

void Save();       //保存
	void Add();        //添加
	void AddAgain();   //再度添加
	void Del();        //删除
	void Find();       //查找菜单
	void Findname();   //查找名字
	void Findid();     //查找学号
	void Sort();       //排序
	void Remake();     //重新编辑
	void Print();      //打印
void mainmenu()    //主菜单

3.4主菜单界面模块

主菜单界面如下图:C++基于vector容器的学生成绩管理系统_第4张图片

代码如下:

void mainmenu()    //主菜单
	{
     
		system("cls");
		cout << "____________________________________________" << endl;
		cout << "|                                          |" << endl;
		cout << "|    添加学生信息                     1    |" << endl;
		cout << "|    查找学生信息                     2    |" << endl;
		cout << "|    GPA排名                          3    |" << endl;
		cout << "|    修改学生信息                     4    |" << endl;
		cout << "|    删除学生信息                     5    |" << endl;
		cout << "|    打印学生信息                     6    |" << endl;
		cout << "|    退出系统                         0    |" << endl;
		cout << "|                                          |" << endl;
		cout << "--------------------------------------------" << endl;
		cout << "请输入你的选择:";
		int x;
		cin >> x;
		switch (x)
		{
     
		case 1:Add(); break;
		case 2:Find(); break;
		case 3:Sort(); break;
		case 4:Remake(); break;
		case 5:Del(); break;
		case 6:Print(); break;
		case 0:Save(); break;
		default:cout << "输入错误,请重新输入\n"; Sleep(1000); mainmenu(); break;
		}
	}
};

3.5添加学生信息模块

添加学生信息函数执行流程图如下:C++基于vector容器的学生成绩管理系统_第5张图片

3.6学生信息查询模块

学生信息查询函数执行流程图如下:C++基于vector容器的学生成绩管理系统_第6张图片

核心代码如下:

{
     	string s; 
	bool flag = false;         //异常解决方案
	cout << "请输入需查找的学生姓名:";
	cin >> s;
	for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
	{
     
		if ((*i).name == s)
		{
     
			flag = true;
			cout << "学号" << "\t" << "姓名" << "\t" << "性别" << "  " << "各科学分" << "  " << "英语" << "  " << "高等数学"
				<< "  " << "C++" << "  " << "模拟电路" << "  " << "体育" << "  " << "Matlab"
				<< "  " << "数据结构" << "  " << "大学物理" << "   " << "GPA" << endl;
			cout << (*i).name << "\t" << (*i).id << "\t" << (*i).sex << "\t    \t" << (*i).English_score << "\t" <<
				(*i).Math_score << "\t" << (*i).C_plus_score << "\t" << (*i).Analog_circuit_score << "\t" << (*i).Sports_score
				<< "\t" << (*i).Matlab_score << "\t" << (*i).Data_structure_score << "\t" << (*i).Physical_score << "\t  " << (*i).GPA << endl;
			cout << "\n按任意键返回主菜单"; char ch;
			cin >> ch; mainmenu();
		}
		if (flag == false)
		{
     
			cout << "查无此人!" << endl;
			Findname();
		}
}

3.7学生信息修改模块

学生信息修改函数执行流程图如下:C++基于vector容器的学生成绩管理系统_第7张图片

代码如下:

void stusystem::Remake()
{
     
	system("cls");
	cout << "修改学生成绩:" << endl;
	cout << "请输入要修改的学生学号:";
	int id;
	cin >> id;
	for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
	{
     
		if ((*i).id == id)
		{
     
			cout << "已找到该学生,请重新输入该学生的信息" << endl;
			int ID;
			string name, sex;
			float eng, math, cplus, mndl, ty, matlab, sjjg, dw;
			cout << "姓名:"; cin >> name;
			cout << "学号:"; cin >> id;
			cout << "性别:"; cin >> sex;
			cout << "英语:"; cin >>eng;
			cout << "高数:"; cin >> math;
			cout << "C++:"; cin >>cplus;
			cout << "模拟电路:"; cin >> mndl;
			cout << "体育:"; cin >> ty;
			cout << "Matlab:"; cin >> matlab;
			cout << "数据结构:"; cin >> sjjg;
			cout << "大学物理:"; cin >> dw;
			char c;
			cout << "是否保存修改?(y/n)";
			cin >> c;
			switch (c) {
     
			case'y':
			case'Y':
				(*i).name = name; (*i).id = id; (*i).sex = sex; (*i).English_score = eng; (*i).Math_score = math;
				(*i).C_plus_score = cplus; (*i).Analog_circuit_score = mndl; (*i).Sports_score = ty; (*i).Physical_score = dw; break;
			case'n':
			case'N':
				 break;
			default:cout << "输入错误,将返回主菜单\n"; Sleep(1000); mainmenu(); break;
			}
		}
	}
	Save();
	cout << "\n按任意键返回主菜单"; char ch;
	cin >> ch; return;
}

3.8学生信息删除模块

学生信息删除函数执行流程图如下:C++基于vector容器的学生成绩管理系统_第8张图片

代码如下:

void stusystem::Del()   //删除
{
     
	cout << "请输入学生的学号" << endl;
	int id;
	cin >> id;
	for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
	{
     
		if ((*i).id == id)
		{
     
			int select;
			cout << "是否删除?" << endl;
			cout << "1.是" << "   " << "2.否" << endl;
			cin >> select;
			switch (select)
			{
     
			case 1:
				a.erase(i);  //以string.h为头文件的删除函数
				cout << "删除成功" << endl;
				break;
			case 2:
				cout << "您未删除" << endl;
				break;
			default:cout << "输入错误,将返回主菜单\n"; Sleep(1000); mainmenu(); break;
			}
			if ((*i).id != id)
			{
     
				cout << "查无此人" << endl;
			}

		}
	}
	Save();
	cout << "\n按任意键返回主菜单"; char ch;
	cin >> ch; return;
}

3.9学生GPA排名模块

排序模块函数执行流程图如下:C++基于vector容器的学生成绩管理系统_第9张图片

代码如下:

bool mysort(Score a,Score b)//自定义排序规则
{
     
	if (a.GPA == b.GPA) {
     
		return a.id > b.id;         //若gpa相同则按学号从小到大排列
	}
	else {
     
		return a.GPA > b.GPA;       //gpa从大到小排
	}
}
void stusystem::Sort()
{
     
	system("cls");
	if (a.size() == 0)
		cout << "文件不存在" << endl;
	else {
     
		sort(a.begin(), a.end(), mysort);
		cout << "学号" << "\t" << "姓名" << "\t" << "性别" << "  " << "各科学分" << "  " << "英语" << "  " << "高等数学"
			<< "  " << "C++" << "  " << "模拟电路" << "  " << "体育" << "  " << "Matlab"
			<< "  " << "数据结构" << "  " << "大学物理" << "   " << "GPA" << endl;
		for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
		{
     
			cout << (*i).name << "\t" << (*i).id << "\t" << (*i).sex << "\t    \t" << (*i).English_score << "\t" <<
				(*i).Math_score << "\t" << (*i).C_plus_score << "\t" << (*i).Analog_circuit_score << "\t" << (*i).Sports_score
				<< "\t" << (*i).Matlab_score << "\t" << (*i).Data_structure_score << "\t" << (*i).Physical_score << "\t  " << (*i).GPA << endl;
		}
		cout << "\n按任意键返回主菜单"; char ch;
		cin >> ch; return;
	}
}

3.10打印学生信息模块

打印模块执行流程图如下:C++基于vector容器的学生成绩管理系统_第10张图片

代码如下:

void stusystem::Print()
{
     
	system("cls");
	if (a.size() == 0)
		cout << "文件不存在" << endl;
	else {
     
		cout << "学号" << "\t" << "姓名" << "\t" << "性别" << "  " << "各科学分" << "  " << "英语" << "  " << "高等数学"
			<< "  " << "C++" << "  " << "模拟电路" << "  " << "体育" << "  " << "Matlab"
			<< "  " << "数据结构" << "  " << "大学物理" << "   " << "GPA" << endl;
		for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
		{
     
			cout << (*i).name << "\t" << (*i).id << "\t" << (*i).sex << "\t    \t" << (*i).English_score << "\t" <<
				(*i).Math_score << "\t" << (*i).C_plus_score << "\t" << (*i).Analog_circuit_score << "\t" << (*i).Sports_score
				<< "\t" << (*i).Matlab_score << "\t" << (*i).Data_structure_score << "\t" << (*i).Physical_score << "\t  " << (*i).GPA << endl;
		}
	}
	cout << "\n按任意键返回主菜单"; char ch;
	cin >> ch; return;
}

源码

完整代码如下:

#include
#include
#include
#include
#include
#include
using namespace std;
class Student		//学生类
{
     
public:
	Student( string name, int id, string sex)
	{
     
        this->name = name;
		this->id = id;
		this->sex = sex;
	}
	string name;
	int id;
	string sex;
};

class Grade			//课程类
{
     
public:
	string English;
	string Math;
	string C_plus;
	string Analog_circuit;
	string Sports;
	string Matlab;
	string Data_structure;
	string Physical;
};

class Score : public Grade,virtual public Student	//成绩类
{
     
public:
	Score(string name, int id, string sex, float English_score, float Math_score, float C_plus_score, float Analog_circuit_score, float Sports_score, float Matlab_score, float Data_structure_score, float Physical_score) :Student(name, id, sex)
	{
     
		this->English_score = English_score;
		this->Math_score = Math_score;
		this->C_plus_score = C_plus_score;
		this->Analog_circuit_score = Analog_circuit_score;
		this->Sports_score = Sports_score;
		this->Matlab_score = Matlab_score;
		this->Data_structure_score = Data_structure_score;
		this->Physical_score = Physical_score;
		GPA = (English_score + Math_score + C_plus_score + Analog_circuit_score + Sports_score + Matlab_score + Data_structure_score + Physical_score) / 8.0;
	}
	float English_score;
	float Math_score;
	float C_plus_score;
	float Analog_circuit_score;
	float Sports_score;
	float Matlab_score;
	float Data_structure_score;
	float Physical_score;
	float GPA;


};
class stusystem
{
     
public:
	stusystem()    //打开文件
	{
     
		ifstream ifs("学生成绩.txt", ios::in);
		if (ifs.is_open() != NULL)
		{
     
			string name, sex;
			int id;
			float English_score;
			float Math_score;
			float C_plus_score;
			float Analog_circuit_score;
			float Sports_score;
			float Matlab_score;
			float Data_structure_score;
			float Physical_score;
			float GPA;    //说实话你设的这变量名真的长
			while (ifs >> name >> id >> sex >> English_score >> Math_score >> C_plus_score >> Analog_circuit_score >> Sports_score >> Matlab_score >> Data_structure_score >> Physical_score)
			{
     
				Score s(name , id , sex , English_score , Math_score , C_plus_score , Analog_circuit_score , Sports_score , Matlab_score , Data_structure_score , Physical_score);
				a.push_back(s);
			}
		}
		else
		{
     
			cout << "不存在该文件" << endl;

		}
	}
	vector<Score>a;
	void Save();       //保存
	void Add();        //添加
	void AddAgain();   //再度添加
	void Del();        //删除
	void Find();       //查找菜单
	void Findname();   //查找名字
	void Findid();     //查找学号
	void Sort();       //排序
	void Remake();     //重新编辑
	void Print();      //打印
	void mainmenu()    //主菜单
	{
     
		system("cls");
		cout << "____________________________________________" << endl;
		cout << "|                                          |" << endl;
		cout << "|    添加学生信息                     1    |" << endl;
		cout << "|    查找学生信息                     2    |" << endl;
		cout << "|    GPA排名                          3    |" << endl;
		cout << "|    修改学生信息                     4    |" << endl;
		cout << "|    删除学生信息                     5    |" << endl;
		cout << "|    打印学生信息                     6    |" << endl;
		cout << "|    退出系统                         0    |" << endl;
		cout << "|                                          |" << endl;
		cout << "--------------------------------------------" << endl;
		cout << "请输入你的选择:";
		int x;
		cin >> x;
		switch (x)
		{
     
		case 1:Add(); break;
		case 2:Find(); break;
		case 3:Sort(); break;
		case 4:Remake(); break;
		case 5:Del(); break;
		case 6:Print(); break;
		case 0:Save(); break;
		default:cout << "输入错误,请重新输入\n"; Sleep(1000); mainmenu(); break;
		}
	}
};

void stusystem::Save()  //保存文件
{
     
	ofstream ofs("学生成绩.txt", ios::out);
	for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
	{
     
		ofs << (*i).name << "\t" << (*i).id << "\t" << (*i).sex << "\t" << (*i).English_score << "\t" <<
			(*i).Math_score << "\t" << (*i).C_plus_score << "\t" << (*i).Analog_circuit_score << "\t" << (*i).Sports_score
			<< "\t" << (*i).Matlab_score << "\t" << (*i).Data_structure_score << "\t" << (*i).Physical_score << "\t" << (*i).GPA;
	}
	ofs.close();
}

void stusystem::Add()  //添加
{
     
	system("cls");
	int flag;
	
	cout << "请输入学生信息:" << endl;
	string name, sex;
	int id;
	float eng, math, cplus, mndl, ty, matlab, sjjg, dw;
	while (1)
	{
     
		cout << "姓名:";
		cin >> name;
		
		cout << "学号:";
		cin >> id;
		for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
		{
     
			if ((*i).id == id)
			{
     
				cout << "此同学信息已经存在,请重新输入";
				Sleep(700);
				Add();
			}
		}
		cout << "性别:";
		cin >> sex;
		do {
     
			flag = 0;
			cout << "英语学分:";
			cin >> eng;
			if (eng > 5.0 || eng < 0) {
     
				cout << " 对不起,请输入0-5.0之间的数字!!\n";
			}
			else {
     
				flag = 1;
			}
		} while (flag == 0);
		do {
     
			flag = 0;
			cout << "高数学分:";
			cin >> math;
			if (math > 5.00 || math < 0) {
     
				cout << " 对不起,请输入0-5.00之间的数字!!\n";
			}
			else {
     
				flag = 1;
			}
		} while (flag == 0);
		do {
     
			flag = 0;
			cout << "C++学分:";
			cin >> cplus;
			if (cplus > 5.00 || cplus < 0) {
     
				cout << " 对不起,请输入0-5.00之间的数字!!\n";
			}
			else {
     
				flag = 1;
			}
		} while (flag == 0);
		do {
     
			flag = 0;
			cout << "模拟电路学分:";
			cin >> mndl;
			if (mndl > 5.00 || mndl < 0) {
     
				cout << " 对不起,请输入0-5.00之间的数字!!\n";
			}
			else {
     
				flag = 1;
			}
		} while (flag == 0);
		do {
     
			flag = 0;
			cout << "体育学分:";
			cin >> ty;
			if (ty > 5.00 || ty < 0) {
     
				cout << " 对不起,请输入0-5.00之间的数字!!\n";
			}
			else {
     
				flag = 1;
			}
		} while (flag == 0);
		do {
     
			flag = 0;
			cout << "Matlab学分:";
			cin >> matlab;
			if (matlab > 5.00 || matlab < 0) {
     
				cout << " 对不起,请输入0-5.00之间的数字!!\n";
			}
			else {
     
				flag = 1;
			}
		} while (flag == 0);
		do {
     
			flag = 0;
			cout << "数据结构学分:";
			cin >> sjjg;
			if (sjjg > 5.00 || sjjg < 0) {
     
				cout << " 对不起,请输入0-5.00之间的数字!!\n";
			}
			else {
     
				flag = 1;
			}
		} while (flag == 0);
		do {
     
			flag = 0;
			cout << "大学物理学分:";
			cin >> dw;
			if (dw > 5.00 || dw < 0) {
     
				cout << " 对不起,请输入0-5.00之间的数字!!\n";
			}
			else {
     
				flag = 1;
			}
		} while (flag == 0);
		Score s(name, id, sex, eng, math, cplus, mndl, ty, matlab, sjjg, dw);
		a.push_back(s);  //vector头文件中的push_back操作符,意思是插入到表尾
		Save();
		cout << "添加成功" << endl;
		AddAgain();	
	}
}
void stusystem::AddAgain()
{
     
        cout << "是否继续添加学生成绩信息?(y/n)" << endl;
        char sign = '0';
		cin >> sign;
		switch (sign) {
     
		case'y':
		case'Y':
			Add(); break;
		case'n':
		case'N':
			mainmenu(); break;
		default:cout << "输入错误,请重新输入\n"; Sleep(1000); AddAgain(); break;
		}
}
void stusystem::Find()
{
     
	system("cls");
	cout << "查找学生成绩:" << endl;
	cout << "请选择查询方式:" << endl;
	cout << "1-姓名查询" << endl << "2-学号查询" << endl;
	int x = 0;	
	cin >> x;
	switch (x)
	{
     
	case 1:
		Findname(); break;
	case 2:
		Findid(); break;
	}
}
void stusystem::Findname()
{
     
	
	string s; 
	bool flag = false;         //异常解决方案
	cout << "请输入需查找的学生姓名:";
	cin >> s;
	for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
	{
     
		if ((*i).name == s)
		{
     
			flag = true;
			cout << "学号" << "\t" << "姓名" << "\t" << "性别" << "  " << "各科学分" << "  " << "英语" << "  " << "高等数学"
				<< "  " << "C++" << "  " << "模拟电路" << "  " << "体育" << "  " << "Matlab"
				<< "  " << "数据结构" << "  " << "大学物理" << "   " << "GPA" << endl;
			cout << (*i).name << "\t" << (*i).id << "\t" << (*i).sex << "\t    \t" << (*i).English_score << "\t" <<
				(*i).Math_score << "\t" << (*i).C_plus_score << "\t" << (*i).Analog_circuit_score << "\t" << (*i).Sports_score
				<< "\t" << (*i).Matlab_score << "\t" << (*i).Data_structure_score << "\t" << (*i).Physical_score << "\t  " << (*i).GPA << endl;
			cout << "\n按任意键返回主菜单"; char ch;
			cin >> ch; mainmenu();
		}
		if (flag == false)
		{
     
			cout << "查无此人!" << endl;
			Findname();
		}
	}
}
void stusystem::Findid()
{
     
	int y=0;
	bool flag = false;         //异常解决方案
	cout << "请输入需查找的学生学号:";
	cin >> y;
	for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
	{
     
		if ((*i).id == y)
		{
     
			flag = true;
			cout << "学号" << "\t" << "姓名" << "\t" << "性别" << "  " << "各科学分" << "  " << "英语" << "  " << "高等数学"
				<< "  " << "C++" << "  " << "模拟电路" << "  " << "体育" << "  " << "Matlab"
				<< "  " << "数据结构" << "  " << "大学物理" << "   " << "GPA" << endl;
			cout << (*i).name << "\t" << (*i).id << "\t" << (*i).sex << "\t    \t" << (*i).English_score << "\t" <<
				(*i).Math_score << "\t" << (*i).C_plus_score << "\t" << (*i).Analog_circuit_score << "\t" << (*i).Sports_score
				<< "\t" << (*i).Matlab_score << "\t" << (*i).Data_structure_score << "\t" << (*i).Physical_score << "\t  " << (*i).GPA << endl;
			cout << "\n按任意键返回主菜单"; char ch;
			cin >> ch; mainmenu();
		}
		if (flag == false)
		{
     
			cout << "查无此人!" << endl;
			Findid();
		}
	}
}

void stusystem::Del()   //删除
{
     
	cout << "请输入学生的学号" << endl;
	int id;
	cin >> id;
	for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
	{
     
		if ((*i).id == id)
		{
     
			int select;
			cout << "学号" << "\t" << "姓名" << "\t" << "性别" << "  " << "各科学分" << "  " << "英语" << "  " << "高等数学"
				<< "  " << "C++" << "  " << "模拟电路" << "  " << "体育" << "  " << "Matlab"
				<< "  " << "数据结构" << "  " << "大学物理" << "   " << "GPA" << endl;
			cout << (*i).name << "\t" << (*i).id << "\t" << (*i).sex << "\t    \t" << (*i).English_score << "\t" <<
				(*i).Math_score << "\t" << (*i).C_plus_score << "\t" << (*i).Analog_circuit_score << "\t" << (*i).Sports_score
				<< "\t" << (*i).Matlab_score << "\t" << (*i).Data_structure_score << "\t" << (*i).Physical_score << "\t  " << (*i).GPA << endl;
			cout << "是否删除?" << endl;
			cout << "1.是" << "   " << "2.否" << endl;
			cin >> select;
			switch (select)
			{
     
			case 1:
				a.erase(i);  //以string.h为头文件的删除函数
				cout << "删除成功" << endl; Sleep(100); mainmenu(); break;
			case 2:
				cout << "您未删除" << endl; Sleep(100); mainmenu(); break;
			default:cout << "输入错误,将返回主菜单\n"; Sleep(1000); mainmenu(); break;
			}
			if ((*i).id != id)
			{
     
				cout << "查无此人" << endl;
			}

		}
	}
	Save();
	cout << "\n按任意键返回主菜单"; char ch;
	cin >> ch; Sleep(500); return;
}
void stusystem::Remake()
{
     
	system("cls");
	cout << "修改学生成绩:" << endl;
	cout << "请输入要修改的学生学号:";
	int id;
	cin >> id;
	for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
	{
     
		if ((*i).id == id)
		{
     
			cout << "已找到该学生,请重新输入该学生的信息" << endl;
			int ID;
			string name, sex;
			float eng, math, cplus, mndl, ty, matlab, sjjg, dw;
			cout << "姓名:"; cin >> name;
			cout << "学号:"; cin >> id;
			cout << "性别:"; cin >> sex;
			cout << "英语:"; cin >>eng;
			cout << "高数:"; cin >> math;
			cout << "C++:"; cin >>cplus;
			cout << "模拟电路:"; cin >> mndl;
			cout << "体育:"; cin >> ty;
			cout << "Matlab:"; cin >> matlab;
			cout << "数据结构:"; cin >> sjjg;
			cout << "大学物理:"; cin >> dw;
			char c;
			cout << "是否保存修改?(y/n)";
			cin >> c;
			switch (c) {
     
			case'y':
			case'Y':
				(*i).name = name; (*i).id = id; (*i).sex = sex; (*i).English_score = eng; (*i).Math_score = math;
				(*i).C_plus_score = cplus; (*i).Analog_circuit_score = mndl; (*i).Sports_score = ty; (*i).Physical_score = dw; break;
			case'n':
			case'N':
				 break;
			default:cout << "输入错误,将返回主菜单\n"; Sleep(1000); mainmenu(); break;

			}
		}
	}
	Save();
	cout << "\n按任意键返回主菜单"; char ch;
	cin >> ch; Sleep(500); return;
}
bool mysort(Score a,Score b)//自定义排序规则
{
     
	if (a.GPA == b.GPA) {
     
		return a.id > b.id;         //若gpa相同则按学号从小到大排列
	}
	else {
     
		return a.GPA > b.GPA;       //gpa从大到小排
	}
}
void stusystem::Sort()
{
     
	system("cls");
	if (a.size() == 0)
		cout << "文件不存在" << endl;
	else {
     
		sort(a.begin(), a.end(), mysort);   //排序函数从向量表头至表尾使用自定义mysort规则
		cout << "学号" << "\t" << "姓名" << "\t" << "性别" << "  " << "各科学分" << "  " << "英语" << "  " << "高等数学"
			<< "  " << "C++" << "  " << "模拟电路" << "  " << "体育" << "  " << "Matlab"
			<< "  " << "数据结构" << "  " << "大学物理" << "   " << "GPA" << endl;
		for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
		{
     
			cout << (*i).name << "\t" << (*i).id << "\t" << (*i).sex << "\t    \t" << (*i).English_score << "\t" <<
				(*i).Math_score << "\t" << (*i).C_plus_score << "\t" << (*i).Analog_circuit_score << "\t" << (*i).Sports_score
				<< "\t" << (*i).Matlab_score << "\t" << (*i).Data_structure_score << "\t" << (*i).Physical_score << "\t  " << (*i).GPA << endl;
		}
		cout << "\n按任意键返回主菜单"; char ch;
		cin >> ch; Sleep(500); return;
	}
}
void stusystem::Print()
{
     
	system("cls");
	if (a.size() == 0)
		cout << "文件不存在" << endl;
	else {
     
		cout << "学号" << "\t" << "姓名" << "\t" << "性别" << "  " << "各科学分" << "  " << "英语" << "  " << "高等数学"
			<< "  " << "C++" << "  " << "模拟电路" << "  " << "体育" << "  " << "Matlab"
			<< "  " << "数据结构" << "  " << "大学物理" << "   " << "GPA" << endl;
		for (vector<Score>::iterator i = a.begin(); i != a.end(); i++)
		{
     
			cout << (*i).name << "\t" << (*i).id << "\t" << (*i).sex << "\t    \t" << (*i).English_score << "\t" <<
				(*i).Math_score << "\t" << (*i).C_plus_score << "\t" << (*i).Analog_circuit_score << "\t" << (*i).Sports_score
				<< "\t" << (*i).Matlab_score << "\t" << (*i).Data_structure_score << "\t" << (*i).Physical_score << "\t  " << (*i).GPA << endl;
		}
	}
	cout << "\n按任意键返回主菜单"; char ch;
	cin >> ch; Sleep(500); return;
}
int main()
{
     
	stusystem stu;
	while (1)
	{
     
		stu.mainmenu();
	}
	return 0;
}

你可能感兴趣的:(课题设计,c++,编程语言)