C++实现:简单的学生信息管理系统(控制台程序)_第1页
C++实现:简单的学生信息管理系统(控制台程序)_第2页
C++实现:简单的学生信息管理系统(控制台程序)_第3页
C++实现:简单的学生信息管理系统(控制台程序)_第4页
C++实现:简单的学生信息管理系统(控制台程序)_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、/ StudentInformationSystem.cpp : Defines the entry point for the console application./#include "stdafx.h"#include <cstring>#include <iostream>#include <conio.h>#include<vector>#include<algorithm>class Studentprivate: char idNumber13; /学号char name30; /姓名char ad

2、dress50; /地址char telephone14; /电话号码int gradeMath; /数学成绩int gradePhysics; /物理成绩int gradeEnglish; /英语成绩double gradeMaPhEgAverage; /物数外平均int rankGrade; /成绩排名int gradeClassmate; /同学评分int gradeTeacher; /老师评分int gradeEthic; /道德评分double gradeAll; /综合成绩int rankAll; /综合排名public:Student(); /默认构造函数void Student

3、_WritePersonalInformation(char *iD, char *nam, char *add, char *tel); /更改学生信息void Student_WriteMaPhEgGrade(int graMa, int graPh, int graEg); /更改学生考试成绩void Student_WriteOtherGrade(int graCl, int graTe, int graEth); /更改学生其他成绩void Student_DisplayInformation(); /显示学生信息char *Student_ReadID();double Stude

4、nt_ReadGrade();double Student_ReadTotalGrade();int Student_ReadGradeRank();int Student_ReadTotalGradeRank();void Student_WriteGradeRank(int ranGr); /更改学生成绩排名void Student_WriteTotalGradeRank(int ranAl); /更改学生综合排名char *Student_ReadName();Student:Student() /默认构造函数strncpy_s(idNumber, "000000000000&

5、quot;,12);strncpy_s(name,"空",30);strncpy_s(address, "空", 50);strncpy_s(telephone, "空", 14); /电话号码gradeMath=0; /数学成绩gradePhysics=0; /物理成绩gradeEnglish=0; /英语成绩gradeMaPhEgAverage=0; /物数外平均rankGrade=0; /成绩排名gradeClassmate=0; /同学评分gradeTeacher=0; /老师评分gradeEthic=0; /道德评分 gra

6、deAll=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);void Student:Student_WriteMaPhEgGrade(int graMa, int graPh, int graEg)gra

7、deMath = 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 = graEth;gradeAll = gradeMaPhEgAverage*0.6 + gradeC

8、lassmate*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 << &qu

9、ot; 学生信息 " << endl;cout << "姓名:" << name << endl<< "学号:" << idNumber << endl<< "地址:" << address << endl<< "电话:" << telephone << endl << "数学成绩:" << gradeMat

10、h << endl<< "物理成绩:" << gradePhysics << endl<< "英语成绩:" << gradeEnglish << endl<< "三科平均成绩:" << gradeMaPhEgAverage << endl<< "学习成绩排名:" << rankGrade << endl<< "同学评价得分:" &

11、lt;< gradeClassmate << endl<< "教师评价得分:" << gradeTeacher << endl<< "道德修养评分:" << gradeEthic << endl<< "综合成绩:" << gradeAll << endl<< "综合成绩排名:" << rankAll << endl;cout << "

12、-" << 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

13、studentInformationstd:vector<Student> studentVector;int flagStudentChoose=0;int flagStudentFound=1;char *Student:Student_ReadName()return name;/-以上是基本数据结构的定义,同时定义了对数据的基本操作。定义完毕了,接下来是功能函数-void MainMenu();void EditMenu();void AddStudentPersonalInformation(int mode);void ModifyStudentInformation(

14、);void SearchStudent();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 student

15、1, Student student2);void DisplayAllStudentInformation();/-以下是主菜单界面函数-void MainMenu()int flagOperateInformation = 1;while (flagOperateInformation)using namespace std;cout << "-" << endl;cout << "欢迎进入学生信息管理系统V1.0." << endl << endl;cout << "

16、按下1:进入学生信息管理系统." << endl;cout << "按下0:退出." << endl;cout << "-" << endl<<endl<<endl;cin >> flagOperateInformation;cin.clear();cout << endl;if (flagOperateInformation)EditMenu();/-主菜单界面函数定义完毕-/-以下是编辑界面函数-void EditMenu()int

17、flagContinueOperation = 1;while (flagContinueOperation)flagContinueOperation = 0;using namespace std;cout << "-" << endl;cout << " 主菜单 " << endl;cout << "按下1:添加学生信息." << endl;cout << "按下2:修改学生信息." << endl;cout &l

18、t;< "按下3:删除学生信息." << endl;cout << "按下4:显示学生信息." << endl;cout << "按下5:按学号升序排序" << endl;cout << "按下6:读入已有信息(暂时没实现)" << endl;cout << "按下7:将信息输出(暂时没实现)" << endl;cout << "按下8:显示系统内所有学生的信息

19、" << endl;cout << "按下0:返回上一级." << endl;cout << "-" << endl << endl;cin >> flagContinueOperation;cin.clear();cout << endl;switch (flagContinueOperation) case 1:AddStudentPersonalInformation(1); break;case 2:ModifyStudentInformat

20、ion(); 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:DisplayAllStudentInformation(); break; case 0:brea

21、k;/-/-以下是添加信息的界面-void AddStudentPersonalInformation(int mode)using namespace std;int flagAddPersonalInformation;int flagAddGrade;int falgAddOtherGrade;Student student1;studentInformation:studentVector.push_back(student1);int currentObjectPosition;if (mode = 1)currentObjectPosition = studentInformati

22、on:studentVector.size() - 1;elsecurrentObjectPosition = studentInformation:flagStudentChoose;/-cout << "请依次添加基本信息、学习成绩和其他成绩,且不要使用空格" << endl;cout << "-" << endl;cout << " 基本信息 " << endl;cout << "按下1:录入学生基本信息;" <<

23、 endl<< "按下0:跳过基本信息。"<<endl<<"-"<<endl;cin >> flagAddPersonalInformation;cin.clear();if (flagAddPersonalInformation)char name30;char iD13;char address50;char phone14;cout << "请输入学生姓名:"cin >> name;cin.clear();cout << "

24、请输入学生学号:"cin >> iD;cin.clear();cout << "请输入学生地址:"cin >> address;cin.clear();cout << "请输入学生电话:"cin >> phone;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WritePersonalInformation(iD,name,address,phone);cout << &q

25、uot;基本信息输入成功!" << endl<< "-" << endl;/-cout << "-" << endl;cout << " 学习成绩 " << endl;cout << "按下1:录入学生学习成绩;" << endl<< "按下0:跳过学习成绩信息。" << endl<< "-" << endl;c

26、in >> flagAddGrade;cin.clear();if (flagAddGrade)int mathGrade;int physicsGrade;int englishGrade;cout << "请输入数学成绩:"cin >> mathGrade;cin.clear();cout << "请输入物理成绩:"cin >> physicsGrade;cin.clear();cout << "请输入英语成绩:"cin >> englishGra

27、de;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WriteMaPhEgGrade(mathGrade, physicsGrade, englishGrade);cout << "学习成绩输入成功!" << endl<< "-" << endl;/-cout << "-" << endl;cout << " 其他成绩 " <

28、< endl;cout << "按下1:录入学生其他成绩;" << endl<< "按下0:跳过其他成绩信息。" << endl<< "-" << endl;cin >> flagAddGrade;cin.clear();if (flagAddGrade)int peerGrade;int teacherGrade;int ethicGrade;cout << "请输入同学评议成绩:"cin >> pe

29、erGrade;cin.clear();cout << "请输入教师评议成绩:"cin >> teacherGrade;cin.clear();cout << "请输入道德测评成绩成绩:"cin >> ethicGrade;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WriteOtherGrade(peerGrade, teacherGrade, ethicGrade);cout << &qu

30、ot;其他成绩输入成功!" << endl<< "-" << endl;RankByGrade();RankByTotalGrade();cout << "学生成绩录入成功!" << endl;cout << "-" << endl<<endl;void SearchStudent()using namespace std;using namespace studentInformation;char ID13;cout <

31、< "请输入学生的学号:"<<endl;cin >> ID;cin.clear();cout << "-"<<endl;int vectorSize = studentVector.size();int i = 0;while (i<vectorSize) & (flagStudentFound!=0)flagStudentFound = strcmp(ID, studentVectori.Student_ReadID();i = i + 1;if (flagStudentFound =

32、 0)flagStudentChoose = i - 1;flagStudentFound = 1;cout << "您所查找的学生信息如下:"<<endl;studentVectorflagStudentChoose.Student_DisplayInformation();elsecout << "未找到该学生" << endl;void ModifyStudentInformation()using namespace std;using namespace studentInformation;in

33、t searchVectorSize = studentVector.size();if (searchVectorSize = 0)cout << "-" << endl;cout << "当前系统中没有学生信息,请先添加学生信息!" << endl;cout << "-" << endl;elseSearchStudent(); cout << "您想对该学生的信息进行修改吗?" << endl;cout <&

34、lt; "按下1:是的。" << endl;cout << "按下0:放弃修改。" << endl;cout << "-" << endl;int flagModify;cin >> flagModify;cin.clear();if (flagModify = 1)&(flagStudentFound = 0)AddStudentPersonalInformation(2);void DeleteStudentInformation()using nam

35、espace std;using namespace studentInformation;int deleteVectorSize = studentVector.size();if (deleteVectorSize = 0)cout << "-" << endl;cout << "当前系统中没有学生信息,请先添加学生信息!" << endl;cout << "-" << endl;elseSearchStudent();cout << "

36、;您想删除该学生的信息吗?" << endl;cout << "按下1:删除。" << endl;cout << "按下0:取消。" << endl;cout << "-" << endl;int flagModify;cin >> flagModify;cin.clear();if (flagModify = 1)&(flagStudentFound = 0)std:vector<Student>:itera

37、tor iter = studentVector.begin() + flagStudentChoose; /这样就选中了一个查到的元素studentVector.erase(iter);cout << "学生信息删除成功!" << endl<< "-" << endl;void DisplayStudentInformation()using namespace std;using namespace studentInformation;int displayVectorSize = studentVe

38、ctor.size();if (displayVectorSize = 0)cout << "-" << endl;cout << "当前系统中没有学生信息,请先添加学生信息!" << endl;cout << "-" << endl;elseSearchStudent();if (flagStudentFound = 0)studentVectorflagStudentChoose.Student_DisplayInformation();bool CmpGra

39、de(Student student1, Student student2)return student1.Student_ReadGrade() > student2.Student_ReadGrade(); /如果student1成绩大于student2,则返回1.这样能实现成绩的降序排列void RankByGrade()using namespace studentInformation;using namespace std;int rankVectorSize = studentVector.size();if (rankVectorSize = 1)studentVecto

40、r0.Student_WriteGradeRank(1);elsesort(studentVector.begin(), studentVector.end(), CmpGrade); /使用sort必须加上#include algorithm和std。sort的前两个参数是指针int i = 0;for (i = 0; i <= rankVectorSize-1; i+)if (i>=1)&&(studentVectori.Student_ReadGrade() = studentVectori - 1.Student_ReadGrade()studentVect

41、ori.Student_WriteGradeRank(studentVectori - 1.Student_ReadGradeRank();elsestudentVectori.Student_WriteGradeRank(i + 1);bool CmpTotalGrade(Student student1, Student student2)return student1.Student_ReadTotalGrade() > student2.Student_ReadTotalGrade(); /如果student1成绩大于student2,则返回1.这样能实现成绩的降序排列void

42、RankByTotalGrade()using namespace studentInformation;using namespace std;int rankVectorSize = studentVector.size();if (rankVectorSize = 1)studentVector0.Student_WriteTotalGradeRank(1);elsesort(studentVector.begin(), studentVector.end(), CmpGrade); /使用sort必须加上#include algorithm和std。sort的前两个参数是指针int i

43、 = 0;for (i = 0; i <= rankVectorSize - 1; i+)if (i >= 1) && (studentVectori.Student_ReadTotalGrade() = studentVectori - 1.Student_ReadTotalGrade()studentVectori.Student_WriteTotalGradeRank(studentVectori - 1.Student_ReadTotalGradeRank();elsestudentVectori.Student_WriteTotalGradeRank(i

44、+ 1);bool CmpID(Student student1, Student student2)int result;result = strcmp(student1.Student_ReadID(), student2.Student_ReadID();if (result<0)return true;elsereturn false;void RankByID()using namespace studentInformation;using namespace std;int rankVectorSize = studentVector.size();sort(student

45、Vector.begin(), studentVector.end(), CmpID);cout << "-" << endl;cout << "排序成功!" << endl;cout << "-" << endl;void DisplayAllStudentInformation()using namespace std;using namespace studentInformation;int displayVectorSize = studentVecto

46、r.size();int i;if (displayVectorSize = 0)cout << "-" << endl;cout << "当前系统中没有学生信息!" << endl;cout << "-" << endl;elsecout << "-" << endl;cout << "姓名 学号 综合成绩 综合排名" << endl;for (i = 0; i < d

47、isplayVectorSize; i+)cout << studentVectori.Student_ReadName() << " "<< studentVectori.Student_ReadID() << " "<< studentVectori.Student_ReadTotalGrade() << " "<< studentVectori.Student_ReadTotalGradeRank() << endl;cout <

48、;< "-" << endl;/-以下是主函数-void main()MainMenu();/*-下面的这是一个排序函数,用到了冒泡排序法,但是程序没用到。上面的排序用了sort()函数来实现,功能是一样的。*/*void RankByGrade()using namespace studentInformation;using namespace std;int flagCompareOut=0;int flagCompareIn=0;int rankVectorSize;rankVectorSize = studentVector.size();if

49、(rankVectorSize = 0)cout << "-" << endl<< "系统当前没有学生信息!" << endl<< "-" << endl;else if (rankVectorSize = 1)studentVectorflagCompareOut.Student_WriteGradeRank(flagCompareOut + 1);elseint flagCompareOut = 0;int flagCompareIn = 0;for (fla

50、gCompareOut = 0; flagCompareOut < rankVectorSize - 1; flagCompareOut+)for (flagCompareIn = 0; flagCompareIn < rankVectorSize - flagCompareOut - 1; flagCompareIn+)if (studentVectorflagCompareIn.Student_ReadGrade() < studentVectorflagCompareIn + 1.Student_ReadGrade()Student studentTemp;studentTe

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论