C++实现:简单的学生信息管理系统(控制台程序).doc
如有侵权,请联系网站删除,仅供学习与交流C+实现:简单的学生信息管理系统(控制台程序)【精品文档】第 13 页/ 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 address50; /地址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_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 Student_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",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; /道德评分 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);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 = 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 << " 学生信息 " << 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<< "综合成绩排名:" << rankAll << 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 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();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 student1, Student student2);void DisplayAllStudentInformation();/-以下是主菜单界面函数-void MainMenu()int flagOperateInformation = 1;while (flagOperateInformation)using namespace std;cout << "-" << endl;cout << "欢迎进入学生信息管理系统V1.0." << endl << endl;cout << "按下1:进入学生信息管理系统." << endl;cout << "按下0:退出." << endl;cout << "-" << endl<<endl<<endl;cin >> flagOperateInformation;cin.clear();cout << endl;if (flagOperateInformation)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:按学号升序排序" << endl;cout << "按下6:读入已有信息(暂时没实现)" << endl;cout << "按下7:将信息输出(暂时没实现)" << endl;cout << "按下8:显示系统内所有学生的信息" << endl;cout << "按下0:返回上一级." << endl;cout << "-" << endl << endl;cin >> flagContinueOperation;cin.clear();cout << endl;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:DisplayAllStudentInformation(); 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 (mode = 1)currentObjectPosition = studentInformation:studentVector.size() - 1;elsecurrentObjectPosition = studentInformation:flagStudentChoose;cout << "请依次添加基本信息、学习成绩和其他成绩,且不要使用空格" << endl;cout << "-" << endl;cout << " 基本信息 " << endl;cout << "按下1:录入学生基本信息;" << endl<< "按下0:跳过基本信息。"<<endl<<"-"<<endl;cin >> flagAddPersonalInformation;cin.clear();if (flagAddPersonalInformation)char name30;char iD13;char address50;char phone14;cout << "请输入学生姓名:"cin >> name;cin.clear();cout << "请输入学生学号:"cin >> iD;cin.clear();cout << "请输入学生地址:"cin >> address;cin.clear();cout << "请输入学生电话:"cin >> phone;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WritePersonalInformation(iD,name,address,phone);cout << "基本信息输入成功!" << endl<< "-" << endl;cout << "-" << endl;cout << " 学习成绩 " << endl;cout << "按下1:录入学生学习成绩;" << endl<< "按下0:跳过学习成绩信息。" << endl<< "-" << endl;cin >> flagAddGrade;cin.clear();if (flagAddGrade)int mathGrade;int physicsGrade;int englishGrade;cout << "请输入数学成绩:"cin >> mathGrade;cin.clear();cout << "请输入物理成绩:"cin >> physicsGrade;cin.clear();cout << "请输入英语成绩:"cin >> englishGrade;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WriteMaPhEgGrade(mathGrade, physicsGrade, englishGrade);cout << "学习成绩输入成功!" << endl<< "-" << endl;cout << "-" << endl;cout << " 其他成绩 " << endl;cout << "按下1:录入学生其他成绩;" << endl<< "按下0:跳过其他成绩信息。" << endl<< "-" << endl;cin >> flagAddGrade;cin.clear();if (flagAddGrade)int peerGrade;int teacherGrade;int ethicGrade;cout << "请输入同学评议成绩:"cin >> peerGrade;cin.clear();cout << "请输入教师评议成绩:"cin >> teacherGrade;cin.clear();cout << "请输入道德测评成绩成绩:"cin >> ethicGrade;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WriteOtherGrade(peerGrade, teacherGrade, ethicGrade);cout << "其他成绩输入成功!" << endl<< "-" << endl;RankByGrade();RankByTotalGrade();cout << "学生成绩录入成功!" << endl;cout << "-" << endl<<endl;void SearchStudent()using namespace std;using namespace studentInformation;char ID13;cout << "请输入学生的学号:"<<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 = 0)flagStudentChoose = i - 1;flagStudentFound = 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 << "当前系统中没有学生信息,请先添加学生信息!" << endl;cout << "-" << endl;elseSearchStudent(); cout << "您想对该学生的信息进行修改吗?" << endl;cout << "按下1:是的。" << endl;cout << "按下0:放弃修改。" << endl;cout << "-" << endl;int flagModify;cin >> flagModify;cin.clear();if (flagModify = 1)&(flagStudentFound = 0)AddStudentPersonalInformation(2);void 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 << "-" << endl;int flagModify;cin >> flagModify;cin.clear();if (flagModify = 1)&(flagStudentFound = 0)std:vector<Student>:iterator iter = studentVector.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 << "当前系统中没有学生信息,请先添加学生信息!" << endl;cout << "-" << endl;elseSearchStudent();if (flagStudentFound = 0)studentVectorflagStudentChoose.Student_DisplayInformation();bool CmpGrade(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)studentVector0.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()studentVectori.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 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 = 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 + 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(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;elsecout << "-" << endl;cout << "姓名 学号 综合成绩 综合排名" << endl;for (i = 0; i < displayVectorSize; i+)cout << studentVectori.Student_ReadName() << " "<< studentVectori.Student_ReadID() << " "<< studentVectori.Student_ReadTotalGrade() << " "<< studentVectori.Student_ReadTotalGradeRank() << endl;cout << "-" << endl;/-以下是主函数-void main