1、/ StudentInformationSystem.cpp : Defines the entry point for the console application./#include stdafx.h#include #include #include #include#includeclass Studentprivate: char idNumber13; /学号char name30; /姓名char address50; /地址char telephone14; /电话号码int gradeMath; /数学成绩int gradePhysics; /物理成绩int gradeEn
2、glish; /英语成绩double gradeMaPhEgAverage; /物数外平均int rankGrade; /成绩排名int gradeClassmate; /同学评分int gradeTeacher; /老师评分int gradeEthic; /道德评分double gradeAll; /综合成绩int rankAll; /综合排名public:Student(); /默认结构函数void Student_WritePersonalInformation(char *iD, char *nam, char *add, char *tel); /更改学生信息void Student
3、_WriteMaPhEgGrade(int graMa, int graPh, int graEg); /更改学生考试成绩void Student_WriteOtherGrade(int graCl, int graTe, int graEth); /更改学生其它成绩void Student_DisplayInformation(); /显示学生信息char *Student_ReadID();double Student_ReadGrade();double Student_ReadTotalGrade();int Student_ReadGradeRank();int Student_Re
4、adTotalGradeRank();void Student_WriteGradeRank(int ranGr); /更改学生成绩排名void Student_WriteTotalGradeRank(int ranAl); /更改学生综合排名char *Student_ReadName();Student:Student() /默认结构函数strncpy_s(idNumber, ,12);strncpy_s(name,空,30);strncpy_s(address, 空, 50);strncpy_s(telephone, 空, 14); /电话号码gradeMath=0; /数学成绩grad
5、ePhysics=0; /物理成绩gradeEnglish=0; /英语成绩gradeMaPhEgAverage=0; /物数外平均rankGrade=0; /成绩排名gradeClassmate=0; /同学评分gradeTeacher=0; /老师评分gradeEthic=0; /道德评分 gradeAll=0; /综合成绩rankAll=0; /综合排名 void Student:Student_WritePersonalInformation(char *iD, char *nam, char *add, char *tel)strncpy_s(idNumber,iD,12);strn
6、cpy_s(name, nam, 30);strncpy_s(address, add,50);strncpy_s(telephone, tel, 14);void Student:Student_WriteMaPhEgGrade(int graMa, int graPh, int graEg)gradeMath = graMa;gradePhysics = graPh;gradeEnglish = graEg;gradeMaPhEgAverage = (gradeMath + gradePhysics + gradeEnglish) / 3;void Student:Student_Writ
7、eOtherGrade(int graCl, int graTe, int graEth)gradeClassmate = graCl;gradeTeacher = graTe;gradeEthic = graEth;gradeAll = gradeMaPhEgAverage*0.6 + gradeClassmate*0.1 + gradeEthic*0.1 + gradeTeacher*0.2;void Student:Student_WriteGradeRank(int ranGr)rankGrade = ranGr;void Student:Student_WriteTotalGrade
8、Rank(int ranAl)rankAll = ranAl;void Student:Student_DisplayInformation()using namespace std;cout - endl;cout 学生信息 endl;cout 姓名: name endl 学号: idNumber endl 地址: address endl 电话: telephone endl 数学成绩: gradeMath endl 物理成绩: gradePhysics endl 英语成绩: gradeEnglish endl 三科平均成绩: gradeMaPhEgAverage endl 学习成绩排名:
9、 rankGrade endl 同学评价得分: gradeClassmate endl 老师评价得分: gradeTeacher endl 道德修养评分: gradeEthic endl 综合成绩: gradeAll endl 综合成绩排名: rankAll endl;cout - endl;char *Student:Student_ReadID()return idNumber;double Student:Student_ReadGrade()return gradeMaPhEgAverage;double Student:Student_ReadTotalGrade()return g
10、radeAll;int Student:Student_ReadGradeRank()return rankGrade;int Student:Student_ReadTotalGradeRank()return rankAll;namespace studentInformationstd:vector studentVector;int flagStudentChoose=0;int flagStudentFound=1;char *Student:Student_ReadName()return name;/-以上是基础数据结构定义,同时定义了对数据基础操作。定义完成了,接下来是功效函数
11、-void MainMenu();void EditMenu();void AddStudentPersonalInformation(int mode);void ModifyStudentInformation();void SearchStudent();void DeleteStudentInformation();void DisplayStudentInformation();void RankByGrade();void RankByTotalGrade();void RankByID();bool CmpGrade(Student student1,Student studen
12、t2); /这个函数参数是两个Student类对象bool CmpTotalGrade(Student student1, Student student2);bool CmpID(Student student1, Student student2);void DisplayAllStudentInformation();/-以下是主菜单界面函数-void MainMenu()int flagOperateInformation = 1;while (flagOperateInformation)using namespace std;cout - endl;cout 欢迎进入学生信息管理系
13、统V1.0. endl endl;cout 按下1:进入学生信息管理系统. endl;cout 按下0:退出. endl;cout - endlendl flagOperateInformation;cin.clear();cout endl;if (flagOperateInformation)EditMenu();/-主菜单界面函数定义完成-/-以下是编辑界面函数-void EditMenu()int flagContinueOperation = 1;while (flagContinueOperation)flagContinueOperation = 0;using namespac
14、e std;cout - endl;cout 主菜单 endl;cout 按下1:添加学生信息. endl;cout 按下2:修改学生信息. endl;cout 按下3:删除学生信息. endl;cout 按下4:显示学生信息. endl;cout 按下5:按学号升序排序 endl;cout 按下6:读入已经有信息(临时没实现) endl;cout 按下7:将信息输出(临时没实现) endl;cout 按下8:显示系统内全部学生信息 endl;cout 按下0:返回上一级. endl;cout - endl flagContinueOperation;cin.clear();cout endl
15、;switch (flagContinueOperation) case 1:AddStudentPersonalInformation(1); break;case 2:ModifyStudentInformation(); break;case 3:DeleteStudentInformation(); break;case 4:DisplayStudentInformation(); break;case 5:RankByID(); break;case 6:cout 功效暂未实现 endl; break;case 7:cout 功效暂未实现 endl; break;case 8:Dis
16、playAllStudentInformation(); break; case 0:break;/-/-以下是添加信息界面-void AddStudentPersonalInformation(int mode)using namespace std;int flagAddPersonalInformation;int flagAddGrade;int falgAddOtherGrade;Student student1;studentInformation:studentVector.push_back(student1);int currentObjectPosition;if (mod
17、e = 1)currentObjectPosition = studentInformation:studentVector.size() - 1;elsecurrentObjectPosition = studentInformation:flagStudentChoose;/-cout 请依次添加基础信息、学习成绩和其它成绩,且不要使用空格 endl;cout - endl;cout 基础信息 endl;cout 按下1:录入学生基础信息; endl 按下0:跳过基础信息。endl- flagAddPersonalInformation;cin.clear();if (flagAddPer
18、sonalInformation)char name30;char iD13;char address50;char phone14;cout name;cin.clear();cout iD;cin.clear();cout address;cin.clear();cout phone;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WritePersonalInformation(iD,name,address,phone);cout 基础信息输入成功! endl - endl;/-cout
19、 - endl;cout 学习成绩 endl;cout 按下1:录入学生学习成绩; endl 按下0:跳过学习成绩信息。 endl - flagAddGrade;cin.clear();if (flagAddGrade)int mathGrade;int physicsGrade;int englishGrade;cout mathGrade;cin.clear();cout physicsGrade;cin.clear();cout englishGrade;cin.clear();studentInformation:studentVectorcurrentObjectPosition.S
20、tudent_WriteMaPhEgGrade(mathGrade, physicsGrade, englishGrade);cout 学习成绩输入成功! endl - endl;/-cout - endl;cout 其它成绩 endl;cout 按下1:录入学生其它成绩; endl 按下0:跳过其它成绩信息。 endl - flagAddGrade;cin.clear();if (flagAddGrade)int peerGrade;int teacherGrade;int ethicGrade;cout peerGrade;cin.clear();cout teacherGrade;cin
21、.clear();cout ethicGrade;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WriteOtherGrade(peerGrade, teacherGrade, ethicGrade);cout 其它成绩输入成功! endl - endl;RankByGrade();RankByTotalGrade();cout 学生成绩录入成功! endl;cout - endlendl;void SearchStudent()using namespace std;using namesp
22、ace studentInformation;char ID13;cout 请输入学生学号: ID;cin.clear();cout -endl;int vectorSize = studentVector.size();int i = 0;while (ivectorSize) & (flagStudentFound!=0)flagStudentFound = strcmp(ID, studentVectori.Student_ReadID();i = i + 1;if (flagStudentFound = 0)flagStudentChoose = i - 1;flagStudentFo
23、und = 1;cout 您所查找学生信息以下:endl;studentVectorflagStudentChoose.Student_DisplayInformation();elsecout 未找到该学生 endl;void ModifyStudentInformation()using namespace std;using namespace studentInformation;int searchVectorSize = studentVector.size();if (searchVectorSize = 0)cout - endl;cout 目前系统中没有学生信息,请先添加学生
24、信息! endl;cout - endl;elseSearchStudent(); cout 您想对该学生信息进行修改吗? endl;cout 按下1:是。 endl;cout 按下0:放弃修改。 endl;cout - flagModify;cin.clear();if (flagModify = 1)&(flagStudentFound = 0)AddStudentPersonalInformation(2);void DeleteStudentInformation()using namespace std;using namespace studentInformation;int d
25、eleteVectorSize = studentVector.size();if (deleteVectorSize = 0)cout - endl;cout 目前系统中没有学生信息,请先添加学生信息! endl;cout - endl;elseSearchStudent();cout 您想删除该学生信息吗? endl;cout 按下1:删除。 endl;cout 按下0:取消。 endl;cout - flagModify;cin.clear();if (flagModify = 1)&(flagStudentFound = 0)std:vector:iterator iter = stu
26、dentVector.begin() + flagStudentChoose; /这么就选中了一个查到元素studentVector.erase(iter);cout 学生信息删除成功! endl - endl;void DisplayStudentInformation()using namespace std;using namespace studentInformation;int displayVectorSize = studentVector.size();if (displayVectorSize = 0)cout - endl;cout 目前系统中没有学生信息,请先添加学生信
27、息! endl;cout - student2.Student_ReadGrade(); /假如student1成绩大于student2,则返回1.这么能实现成绩降序排列void RankByGrade()using namespace studentInformation;using namespace std;int rankVectorSize = studentVector.size();if (rankVectorSize = 1)studentVector0.Student_WriteGradeRank(1);elsesort(studentVector.begin(), stud
28、entVector.end(), CmpGrade); /使用sort必需加上#include algorithm和std。sort前两个参数是指针int i = 0;for (i = 0; i =1)&(studentVectori.Student_ReadGrade() = studentVectori - 1.Student_ReadGrade()studentVectori.Student_WriteGradeRank(studentVectori - 1.Student_ReadGradeRank();elsestudentVectori.Student_WriteGradeRank
29、(i + 1);bool CmpTotalGrade(Student student1, Student student2)return student1.Student_ReadTotalGrade() student2.Student_ReadTotalGrade(); /假如student1成绩大于student2,则返回1.这么能实现成绩降序排列void RankByTotalGrade()using namespace studentInformation;using namespace std;int rankVectorSize = studentVector.size();if
30、 (rankVectorSize = 1)studentVector0.Student_WriteTotalGradeRank(1);elsesort(studentVector.begin(), studentVector.end(), CmpGrade); /使用sort必需加上#include algorithm和std。sort前两个参数是指针int i = 0;for (i = 0; i = 1) & (studentVectori.Student_ReadTotalGrade() = studentVectori - 1.Student_ReadTotalGrade()studen
31、tVectori.Student_WriteTotalGradeRank(studentVectori - 1.Student_ReadTotalGradeRank();elsestudentVectori.Student_WriteTotalGradeRank(i + 1);bool CmpID(Student student1, Student student2)int result;result = strcmp(student1.Student_ReadID(), student2.Student_ReadID();if (result0)return true;elsereturn
32、false;void RankByID()using namespace studentInformation;using namespace std;int rankVectorSize = studentVector.size();sort(studentVector.begin(), studentVector.end(), CmpID);cout - endl;cout 排序成功! endl;cout - endl;void DisplayAllStudentInformation()using namespace std;using namespace studentInformation;int displayVectorSize = studentVector.size();int i;if (displayVectorSize = 0)cout - endl;cout 目前系统中没有学生信息! endl;cout - endl;el