C++实现简单的学生信息管理系统控制台程序.docx
《C++实现简单的学生信息管理系统控制台程序.docx》由会员分享,可在线阅读,更多相关《C++实现简单的学生信息管理系统控制台程序.docx(26页珍藏版)》请在冰豆网上搜索。
![C++实现简单的学生信息管理系统控制台程序.docx](https://file1.bdocx.com/fileroot1/2023-5/23/9082bb1e-06f8-4fc1-bc6b-cda15c456f7c/9082bb1e-06f8-4fc1-bc6b-cda15c456f7c1.gif)
C++实现简单的学生信息管理系统控制台程序
//StudentInformationSystem.cpp:
Definestheentrypointfortheconsoleapplication.
//
#include"stdafx.h"
#include
#include
#include
#include
#include
classStudent
{
private:
charidNumber[13];//学号
charname[30];//姓名
charaddress[50];//地址
chartelephone[14];//电话号码
intgradeMath;//数学成绩
intgradePhysics;//物理成绩
intgradeEnglish;//英语成绩
doublegradeMaPhEgAverage;//物数外平均
intrankGrade;//成绩排名
intgradeClassmate;//同学评分
intgradeTeacher;//老师评分
intgradeEthic;//道德评分
doublegradeAll;//综合成绩
intrankAll;//综合排名
public:
Student();//默认构造函数
voidStudent_WritePersonalInformation(char*iD,char*nam,char*add,char*tel);//更改学生信息
voidStudent_WriteMaPhEgGrade(intgraMa,intgraPh,intgraEg);//更改学生考试成绩
voidStudent_WriteOtherGrade(intgraCl,intgraTe,intgraEth);//更改学生其他成绩
voidStudent_DisplayInformation();//显示学生信息
char*Student_ReadID();
doubleStudent_ReadGrade();
doubleStudent_ReadTotalGrade();
intStudent_ReadGradeRank();
intStudent_ReadTotalGradeRank();
voidStudent_WriteGradeRank(intranGr);//更改学生成绩排名
voidStudent_WriteTotalGradeRank(intranAl);//更改学生综合排名
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;//综合排名
}
voidStudent:
:
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);
}
voidStudent:
:
Student_WriteMaPhEgGrade(intgraMa,intgraPh,intgraEg)
{
gradeMath=graMa;
gradePhysics=graPh;
gradeEnglish=graEg;
gradeMaPhEgAverage=(gradeMath+gradePhysics+gradeEnglish)/3;
}
voidStudent:
:
Student_WriteOtherGrade(intgraCl,intgraTe,intgraEth)
{
gradeClassmate=graCl;
gradeTeacher=graTe;
gradeEthic=graEth;
gradeAll=gradeMaPhEgAverage*0.6+gradeClassmate*0.1+gradeEthic*0.1+gradeTeacher*0.2;
}
voidStudent:
:
Student_WriteGradeRank(intranGr)
{
rankGrade=ranGr;
}
voidStudent:
:
Student_WriteTotalGradeRank(intranAl)
{
rankAll=ranAl;
}
voidStudent:
:
Student_DisplayInformation()
{
usingnamespacestd;
cout<<"-------------------------------------"<cout<<"学生信息"<cout<<"姓名:
"<<<"学号:
"<<<"地址:
"<
<<"电话:
"<<<"数学成绩:
"<<<"物理成绩:
"<<<"英语成绩:
"<<<"三科平均成绩:
"<<<"学习成绩排名:
"<<<"同学评价得分:
"<<<"教师评价得分:
"<<<"道德修养评分:
"<<<"综合成绩:
"<<<"综合成绩排名:
"<cout<<"--------------------------------------"<}
char*Student:
:
Student_ReadID()
{
returnidNumber;
}
doubleStudent:
:
Student_ReadGrade()
{
returngradeMaPhEgAverage;
}
doubleStudent:
:
Student_ReadTotalGrade()
{
returngradeAll;
}
intStudent:
:
Student_ReadGradeRank()
{
returnrankGrade;
}
intStudent:
:
Student_ReadTotalGradeRank()
{
returnrankAll;
}
namespacestudentInformation
{
std:
:
vectorstudentVector;
intflagStudentChoose=0;
intflagStudentFound=1;
}
char*Student:
:
Student_ReadName()
{
returnname;
}
//-----------------------以上是基本数据结构的定义,同时定义了对数据的基本操作。
定义完毕了,接下来是功能函数--------------------
voidMainMenu();
voidEditMenu();
voidAddStudentPersonalInformation(intmode);
voidModifyStudentInformation();
voidSearchStudent();
voidDeleteStudentInformation();
voidDisplayStudentInformation();
voidRankByGrade();
voidRankByTotalGrade();
voidRankByID();
boolCmpGrade(Studentstudent1,Studentstudent2);//这个函数的参数是两个Student类的对象
boolCmpTotalGrade(Studentstudent1,Studentstudent2);
boolCmpID(Studentstudent1,Studentstudent2);
voidDisplayAllStudentInformation();
//-----------------------以下是主菜单界面函数-------------------------------------------------------------------------------
voidMainMenu()
{
intflagOperateInformation=1;
while(flagOperateInformation)
{
usingnamespacestd;
cout<<"-----------------------------------------------------"<cout<<"欢迎进入学生信息管理系统V1.0."<cout<<"按下1:
进入学生信息管理系统."<cout<<"按下0:
退出."<cout<<"-----------------------------------------------------"<cin>>flagOperateInformation;
cin.clear();
cout<if(flagOperateInformation)
EditMenu();
}
}
//------------------------主菜单界面函数定义完毕--------------------------------------------------------------------------
//------------------------以下是编辑界面函数------------------------------------------------------------------------------
voidEditMenu()
{
intflagContinueOperation=1;
while(flagContinueOperation)
{
flagContinueOperation=0;
usingnamespacestd;
cout<<"--------------------------------------------"<cout<<"主菜单"<cout<<"按下1:
添加学生信息."<cout<<"按下2:
修改学生信息."<cout<<"按下3:
删除学生信息."<cout<<"按下4:
显示学生信息."<cout<<"按下5:
按学号升序排序"<cout<<"按下6:
读入已有信息(暂时没实现)"<cout<<"按下7:
将信息输出(暂时没实现)"<cout<<"按下8:
显示系统内所有学生的信息"<cout<<"按下0:
返回上一级."<cout<<"--------------------------------------------"<cin>>flagContinueOperation;
cin.clear();
cout<switch(flagContinueOperation)
{
case1:
AddStudentPersonalInformation
(1);break;
case2:
ModifyStudentInformation();break;
case3:
DeleteStudentInformation();break;
case4:
DisplayStudentInformation();break;
case5:
RankByID();break;
case6:
cout<<"功能暂未实现"<case7:
cout<<"功能暂未实现"<case8:
DisplayAllStudentInformation();break;
case0:
break;
}
}
}
//-----------------------------------------------------------------------------------------------------------------------
//-----------------------以下是添加信息的界面----------------------------------------------------------------------
voidAddStudentPersonalInformation(intmode)
{
usingnamespacestd;
intflagAddPersonalInformation;
intflagAddGrade;
intfalgAddOtherGrade;
Studentstudent1;
studentInformation:
:
studentVector.push_back(student1);
intcurrentObjectPosition;
if(mode==1)
currentObjectPosition=studentInformation:
:
studentVector.size()-1;
else
currentObjectPosition=studentInformation:
:
flagStudentChoose;
//--------------------------------------------------------------------------
cout<<"请依次添加基本信息、学习成绩和其他成绩,且不要使用空格"<cout<<"-------------------------------------"<cout<<"基本信息"<cout<<"按下1:
录入学生基本信息;"<<<"按下0:
跳过基本信息。
"<<<"--------------------------------------"<cin>>flagAddPersonalInformation;
cin.clear();
if(flagAddPersonalInformation)
{
charname[30];
chariD[13];
charaddress[50];
charphone[14];
cout<<"请输入学生姓名:
";
cin>>name;
cin.clear();
cout<<"请输入学生学号:
";
cin>>iD;
cin.clear();
cout<<"请输入学生地址:
";
cin>>address;
cin.clear();
cout<<"请输入学生电话:
";
cin>>phone;
cin.clear();
studentInformation:
:
studentVector[currentObjectPosition].Student_WritePersonalInformation(iD,name,address,phone);
cout<<"基本信息输入成功!
"<<<"------------------------------"<}
//------------------------------------------------------------------------------------
cout<<"-------------------------------------"<cout<<"学习成绩"<cout<<"按下1:
录入学生学习成绩;"<<<"按下0:
跳过学习成绩信息。
"<<<"--------------------------------------"<cin>>flagAddGrade;
cin.clear();
if(flagAddGrade)
{
intmathGrade;
intphysicsGrade;
intenglishGrade;
cout<<"请输入数学成绩:
";
cin>>mathGrade;
cin.clear();
cout<<"请输入物理成绩:
";
cin>>physicsGrade;
cin.clear();
cout<<"请输入英语成绩:
";
cin>>englishGrade;
cin.clear();
studentInformation:
:
studentVector[currentObjectPosition].Student_WriteMaPhEgGrade(mathGrade,physicsGrade,englishGrade);
cout<<"学习成绩输入成功!
"<<<"------------------------------"<}
//---------------------------------------------------------------
cout<<"-------------------------------------"<cout<<"其他成绩"<cout<<"按下1:
录入学生其他成绩;"<<<"按下0:
跳过其他成绩信息。
"<<<"--------------------------------------"<cin>>flagAddGrade;
cin.clear();
if(flagAddGrade)
{
intpeerGrade;
intteacherGrade;
intethicGrade;
cout<<"请输入同学评议成绩:
";
cin>>peerGrade;
cin.clear();
cout<<"请输入教师评议成绩:
";
cin>>teacherGrade;
cin.clear();
cout<<"请输入道德测评成绩成绩:
";
cin>>ethicGrade;
cin.clear();
studentInformation:
:
studentVector[currentObjectPosition].Student_WriteOtherGrade(peerGrade,teacherGrade,ethicGrade);
cout<<"其他成绩输入成功!
"<<<"------------------------------"<}
RankByGrade();
RankByTotalGrade();
cout<<"学生成绩录入成功!
"<cout<<"-------------------------------------"<}
voidSearchStudent()
{
usingnamespacestd;
usingnamespacestudentInformation;
charID[13];
cout<<"请输入学生的学号:
"<cin>>ID;
cin.clear();
cout<<"------------------------------"<intvectorSize=studentVector.size();
inti=0;
while((i=0))
{
flagStudentFound=strcmp(ID,studentVector[i].St