《C实现简单的学生信息管理系统控制台程序.pdf》由会员分享,可在线阅读,更多相关《C实现简单的学生信息管理系统控制台程序.pdf(42页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、C 实现简单的学生信息管理系统控制台程序 The document was prepared on January 2,2021/#include stdafx.h#include#include#include#include#includeclass Studentprivate:char idNumber13;/学号char name30;/姓名char address50;/地址char telephone14;/电话号码int gradeMath;/数学成绩int gradePhysics;/物理成绩int gradeEnglish;/英语成绩double gradeMaPhEgAv
2、erage;/物数外平均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_WriteMaPhEgGrade(int graMa,int graPh,int graEg)
3、;/更改学生考试成绩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_ReadTotalGradeRank();void Student_WriteGradeRank(int ranGr
4、);/更改学生成绩排名void Student_WriteTotalGradeRank(int ranAl);/更改学生综合排名char*Student_ReadName();Student:Student()/默认构造函数strncpy_s(idNumber,000000000000,12);strncpy_s(name,空,30);strncpy_s(address,空,50);strncpy_s(telephone,空,14);/电话号码gradeMath=0;/数学成绩gradePhysics=0;/物理成绩gradeEnglish=0;/英语成绩gradeMaPhEgAverage=
5、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);strncpy_s(name,nam,30);strncpy_s(address,add,50);strncpy_s(telephone,tel,14)
6、;void Student:Student_WriteMaPhEgGrade(int graMa,int graPh,int graEg)gradeMath=graMa;gradePhysics=graPh;gradeEnglish=graEg;gradeMaPhEgAverage=(gradeMath+gradePhysics+gradeEnglish)/3;void Student:Student_WriteOtherGrade(int graCl,int graTe,int graEth)gradeClassmate=graCl;gradeTeacher=graTe;gradeEthic
7、=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_WriteTotalGradeRank(int ranAl)rankAll=ranAl;void Student:Student_DisplayInformation()using namespace std;cout -endl;cout 学生信息
8、endl;cout 姓名:name endl 学号:idNumber endl 地址:address endl 电话:telephone endl 数学成绩:gradeMath endl 物理成绩:gradePhysics endl 英语成绩:gradeEnglish endl 三科平均成绩:gradeMaPhEgAverage endl 学习成绩排名:rankGrade endl 同学评价得分:gradeClassmate endl 教师评价得分:gradeTeacher endl 道德修养评分:gradeEthic endl 综合成绩:gradeAll endl 综合成绩排名:rankAl
9、l endl;cout -endl;char*Student:Student_ReadID()return idNumber;double Student:Student_ReadGrade()return gradeMaPhEgAverage;double Student:Student_ReadTotalGrade()return gradeAll;int Student:Student_ReadGradeRank()return rankGrade;int Student:Student_ReadTotalGradeRank()return rankAll;namespace stude
10、ntInformationstd:vector studentVector;int flagStudentChoose=0;int flagStudentFound=1;char*Student:Student_ReadName()return name;/-以上是基本数据结构的定义,同时定义了对数据的基本操作。定义完毕了,接下来是功能函数-void MainMenu();void EditMenu();void AddStudentPersonalInformation(int mode);void ModifyStudentInformation();void SearchStudent(
11、);void DeleteStudentInformation();void DisplayStudentInformation();void RankByGrade();void RankByTotalGrade();void RankByID();bool CmpGrade(Student student1,Student student2);/这个函数的参数是两个Student 类的对象bool CmpTotalGrade(Student student1,Student student2);bool CmpID(Student student1,Student student2);vo
12、id DisplayAllStudentInformation();/-以下是主菜单界面函数-void MainMenu()int flagOperateInformation=1;while(flagOperateInformation)using namespace std;endl;cout -cout 欢迎进入学生信息管理系统 V1.0.endl endl;cout 按下 1:进入学生信息管理系统.endl;cout 按下 0:退出.endl;cout -endlendl flagOperateInformation;cin.clear();cout endl;if(flagOpera
13、teInformation)EditMenu();/-主菜单界面函数定义完毕-/-以下是编辑界面函数-void EditMenu()int flagContinueOperation=1;while(flagContinueOperation)flagContinueOperation=0;using namespace std;cout -endl;cout 主菜单 endl;cout 按下 1:添加学生信息.endl;cout 按下 2:修改学生信息.endl;cout 按下 3:删除学生信息.endl;cout 按下 4:显示学生信息.endl;cout 按下 5:按学号升序排序 end
14、l;cout 按下 6:读入已有信息(暂时没实现)endl;cout 按下 7:将信息输出(暂时没实现)endl;cout 按下 8:显示系统内所有学生的信息 endl;cout 按下 0:返回上一级.endl;endl;cout -endl flagContinueOperation;cin.clear();cout endl;switch(flagContinueOperation)case 1:AddStudentPersonalInformation(1);break;case 2:ModifyStudentInformation();break;case 3:DeleteStuden
15、tInformation();break;case 4:DisplayStudentInformation();break;case 5:RankByID();break;case 6:cout 功能暂未实现 endl;break;case 7:cout 功能暂未实现 endl;break;case 8:DisplayAllStudentInformation();break;case 0:break;/-/-以下是添加信息的界面-void AddStudentPersonalInformation(int mode)using namespace std;int flagAddPersona
16、lInformation;int flagAddGrade;int falgAddOtherGrade;Student student1;studentInformation:studentVector.push_back(student1);int currentObjectPosition;if(mode=1)1;currentObjectPosition=studentInformation:studentVector.size()-elsecurrentObjectPosition=studentInformation:flagStudentChoose;-/-cout 请依次添加基本
17、信息、学习成绩和其他成绩,且不要使用空格 endl;cout -endl;cout 基本信息 endl;cout 按下 1:录入学生基本信息;endl 按下 0:跳过基本信息。endl-flagAddPersonalInformation;cin.clear();if(flagAddPersonalInformation)char name30;char iD13;char address50;char phone14;cout name;cin.clear();cout iD;cin.clear();cout address;cin.clear();cout phone;cin.clear(
18、);studentInformation:studentVectorcurrentObjectPosition.Student_WritePersonalInformation(iD,name,address,phone);cout 基本信息输入成功!endl-endl;/-cout -endl;cout 学习成绩 endl;cout 按下 1:录入学生学习成绩;endl 按下 0:跳过学习成绩信息。endl-flagAddGrade;cin.clear();if(flagAddGrade)int mathGrade;int physicsGrade;int englishGrade;cout
19、 mathGrade;cin.clear();cout physicsGrade;cin.clear();cout englishGrade;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WriteMaPhEgGrade(mathGrade,physicsGrade,englishGrade);cout 学习成绩输入成功!endl-endl;/-cout -endl;cout 其他成绩 endl;cout 按下 1:录入学生其他成绩;endl 按下 0:跳过其他成绩信息。endl-flagAd
20、dGrade;cin.clear();if(flagAddGrade)int peerGrade;int teacherGrade;int ethicGrade;cout peerGrade;cin.clear();cout teacherGrade;cin.clear();cout ethicGrade;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WriteOtherGrade(peerGrade,teacherGrade,ethicGrade);cout 其他成绩输入成功!endl-en
21、dl;RankByGrade();RankByTotalGrade();cout 学生成绩录入成功!endl;cout -endlendl;void SearchStudent()using namespace std;using namespace studentInformation;char ID13;cout 请输入学生的学号:ID;cin.clear();cout -endl;int vectorSize=studentVector.size();int i=0;while(ivectorSize)&(flagStudentFound!=0)flagStudentFound=strc
22、mp(ID,studentVectori.Student_ReadID();i=i+1;if(flagStudentFound=0)flagStudentChoose=i-1;flagStudentFound=1;cout 您所查找的学生信息如下:endl;studentVectorflagStudentChoose.Student_DisplayInformation();elsecout 未找到该学生 endl;void ModifyStudentInformation()using namespace std;using namespace studentInformation;int
23、searchVectorSize=studentVector.size();if(searchVectorSize=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)AddStudentPersonalInformation(2);void
24、DeleteStudentInformation()using namespace std;using namespace studentInformation;int deleteVectorSize=studentVector.size();if(deleteVectorSize=0)cout -endl;cout 当前系统中没有学生信息,请先添加学生信息!endl;cout -endl;elseSearchStudent();cout 您想删除该学生的信息吗 endl;cout 按下 1:删除。endl;cout 按下 0:取消。endl;cout -flagModify;cin.cle
25、ar();if(flagModify=1)&(flagStudentFound=0)std:vector:iterator iter=studentVector.begin()+flagStudentChoose;/这样就选中了一个查到的元素studentVector.erase(iter);cout 学生信息删除成功!endl-endl;void DisplayStudentInformation()using namespace std;using namespace studentInformation;int displayVectorSize=studentVector.size()
26、;if(displayVectorSize=0)cout -endl;cout 当前系统中没有学生信息,请先添加学生信息!endl;cout -student2.Student_ReadGrade();/如果 student1 成绩大于 student2,则返回 1.这样能实现成绩的降序排列void RankByGrade()using namespace studentInformation;using namespace std;int rankVectorSize=studentVector.size();if(rankVectorSize=1)studentVector0.Studen
27、t_WriteGradeRank(1);elsesort(studentVector.begin(),studentVector.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_ReadGradeRa
28、nk();elsestudentVectori.Student_WriteGradeRank(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 st
29、d;int rankVectorSize=studentVector.size();if(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.
30、Student_ReadTotalGrade()studentVectori.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)re
31、turn true;elsereturn 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 s
32、tudentInformation;int displayVectorSize=studentVector.size();int i;if(displayVectorSize=0)cout -endl;cout 当前系统中没有学生信息!endl;cout -endl;else endl;endl;endl;endl;cout -cout 姓名学号综合成绩综合排名 for(i=0;i displayVectorSize;i+)cout studentVectori.Student_ReadName()studentVectori.Student_ReadID()studentVectori.St
33、udent_ReadTotalGrade()studentVectori.Student_ReadTotalGradeRank()cout -/-以下是主函数-void main()MainMenu();/*-下面的这是一个排序函数,用到了冒泡排序法,但是程序没用到。上面的排序用了 sort()函数来实现,功能是一样的。*/*void RankByGrade()using namespace studentInformation;using namespace std;int flagCompareOut=0;int flagCompareIn=0;int rankVectorSize;ran
34、kVectorSize=studentVector.size();if(rankVectorSize=0)cout -endl 系统当前没有学生信息!endl-endl;else if(rankVectorSize=1)studentVectorflagCompareOut.Student_WriteGradeRank(flagCompareOut+1);elseint flagCompareOut=0;int flagCompareIn=0;for(flagCompareOut=0;flagCompareOut rankVectorSize-1;flagCompareOut+)for(fla
35、gCompareIn=0;flagCompareIn rankVectorSize-flagCompareOut-1;flagCompareIn+)if(studentVectorflagCompareIn.Student_ReadGrade()studentVectorflagCompareIn+1.Student_ReadGrade()Student studentTemp;studentTemp=studentVectorflagCompareIn;studentVectorflagCompareIn=studentVectorflagCompareIn+1;studentVectorf
36、lagCompareIn+1=studentTemp;int i=0;for(i=0;i 0)&(studentVectori.Student_ReadGrade()=studentVectori-1.Student_ReadGrade()studentVectori.Student_WriteGradeRank(studentVectori-1.Student_ReadGradeRank();elsestudentVectori.Student_WriteGradeRank(i+1);void RankByTotalGrade()using namespace studentInformat
37、ion;using namespace std;int flagCompareOut=0;int flagCompareIn=0;int rankVectorSize;rankVectorSize=studentVector.size();if(rankVectorSize=0)cout -endl 系统当前没有学生信息!endl-endl;else if(rankVectorSize=1)studentVectorflagCompareOut.Student_WriteTotalGradeRank(flagCompareOut+1);elseint flagCompareOut=0;int
38、flagCompareIn=0;for(flagCompareOut=0;flagCompareOut rankVectorSize-1;flagCompareOut+)for(flagCompareIn=0;flagCompareIn rankVectorSize-flagCompareOut-1;flagCompareIn+)Student studentTemp;if(studentVectorflagCompareIn.Student_ReadTotalGrade()studentVectorflagCompareIn+1.Student_ReadTotalGrade()student
39、Temp=studentVectorflagCompareIn;studentVectorflagCompareIn=studentVectorflagCompareIn+1;studentVectorflagCompareIn+1=studentTemp;int i=0;for(i=0;i 0)&(studentVectori.Student_ReadTotalGrade()=studentVectori-1.Student_ReadTotalGrade()studentVectori.Student_WriteTotalGradeRank(studentVectori-1.Student_ReadTotalGradeRank();elsestudentVectori.Student_WriteTotalGradeRank(i+1);void RankByID()*/