#include<iostream>
#include<fstream>
#include<cstring>
#include <iomanip>
using namespace std;
typedef struct
{
char id[20];//学号
char name[20];//姓名
char sex[5];//性别
int age;//年龄
char major[20];//专业
char class_num[20];//班级
int score[4];//C++ 英语 高数 总分
}STU;
STU stu[100];//创建结构体数组
int NUM=0;//记录录入学生数量
void Sort_Sum()
{
STU temp;
int i,j;
for(i=0;i<NUM;i++)
{
for(j=i+1;j<NUM;j++)
{
if(stu[i].score[3]<stu[j].score[3])
{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
}
}
}
int Menu()
{
int chioce;
system("cls");
cout<<endl;
cout<<"********************************** 学 生 信 息 管 理 系 统 **********************************"<<endl;
cout<<endl;
cout<<"---***--***--***--***--***--***--***-------------------------------------------***--***--***--***--***--***--***--***---"<<endl;
cout<<" 1: 学 生 基 本 信 息 管 理"<<endl;
cout<<endl;
cout<<"---***--***--***--***--***--***--***-------------------------------------------***--***--***--***--***--***--***--***---"<<endl;
cout<<" 2: 学 生 成 绩 信 息 管 理"<<endl;
cout<<endl;
cout<<"---***--***--***--***--***--***--***-------------------------------------------***--***--***--***--***--***--***--***---"<<endl;
cout<<" 3: 班 级 学 生 信 息 管 理"<<endl;
cout<<endl;
cout<<"---***--***--***--***--***--***--***-------------------------------------------***--***--***--***--***--***--***--***---"<<endl;
cout<<" 4: 学 生 专 业 信 息 管 理"<<endl;
cout<<endl;
cout<<"---***--***--***--***--***--***--***-------------------------------------------***--***--***--***--***--***--***--***---"<<endl;
cout<<" 5: 其 他 功 能 "<<endl;
cout<<endl;
cout<<"---***--***--***--***--***--***--***-------------------------------------------***--***--***--***--***--***--***--***---"<<endl;
cout<<endl;
cout<<"******************************************** 0: 退 出 系 统 ***************************************************"<<endl;
cout<<"请 选 择:";
cin>>chioce;
while(chioce<0||chioce>5)
{
cout<<"输 入 错 误 ,请 重 新 输 入!"<<endl;
cin>>chioce;
}
return chioce;
}
void Input_Stu_Info()
{
int i;
char temp[20];
system("cls");
cout<<endl;
cout<<"******************************************* 1: 添 加 学 生 信 息 ***************************************"<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 新 增 学 生 学 号:";
cin>>temp;
for(i=0;i<NUM;i++)//查找是存在该学号
{
if(!strcmp(temp,stu[i].id))
{
cout<<"该 学 号 已 存 在 ! 添 加 失 败 !"<<endl;
system("pause");
return ;
}
}
strcpy(stu[NUM].id,temp);
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 新 增 学 生 姓 名:";
cin>>stu[NUM].name;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 新 增 学 生 性 别:";
cin>>stu[NUM].sex;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 新 增 学 生 年 龄:";
cin>>stu[NUM].age;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 新 增 学 生 专 业:";
cin>>stu[NUM].major;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 新 增 学 生 班 级:";
cin>>stu[NUM].class_num;
stu[NUM].score[3]=-1;//-1代表总分 所有科目成绩还没录入
NUM++;//人数+1
cout<<endl;
cout<<"录 入 成 功 !"<<endl;
cout<<endl;
system("pause");
}
/*显示n个学生信息*/
void Print_Stu_Info(STU* stu,int n)
{
int i;
cout<<"************************************************************************************************************************";
cout<<setw(-10)<<"学 号";
cout<<setw(10)<<"姓 名";
cout<<setw(10)<<"性 别";
cout<<setw(10)<<"年 龄";
cout<<setw(10)<<"专 业";
cout<<setw(10)<<"班 级"<<endl;
cout<<"************************************************************************************************************************";
for(i=0;i<n;i++)
{
cout<<setw(-10)<<stu[i].id;
cout<<setw(10)<<stu[i].name;
cout<<setw(10)<<stu[i].sex;
cout<<setw(10)<<stu[i].age;
cout<<setw(10)<<stu[i].major;
cout<<setw(10)<<stu[i].class_num<<endl;
}
cout<<"************************************************************************************************************************";
}
void Modify_Stu_Info()
{
int i;
char temp[20];
system("cls");
cout<<endl;
cout<<"******************************************* 2: 修 改 学 生 信 息 ***************************************"<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 修 改 学 生 学 号:";
cin>>temp;
cout<<endl;
for(i=0;i<NUM;i++)//查找是存在该学号
{
if(!strcmp(temp,stu[i].id))
{
break;
}
}
if(i==NUM)//没找到
{
cout<<"无 该 学 号 信 息 !"<<endl;
system("pause");
return ;
}
else
{
Print_Stu_Info(stu+i,1);//显示学生当前信息
}
cout<<endl;
cout<<"请 输 入 修 改 学 生 姓 名:";
cin>>stu[i].name;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 修 改 学 生 性 别:";
cin>>stu[i].sex;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 修 改 学 生 年 龄:";
cin>>stu[i].age;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 修 改 学 生 专 业:";
cin>>stu[i].major;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 修 改 学 生 班 级:";
cin>>stu[i].class_num;
cout<<endl;
cout<<"修 改 成 功 !"<<endl;
cout<<endl;
system("pause");
}
void Serach_Stu_Info()
{
int i;
char temp[20];
system("cls");
cout<<endl;
cout<<"******************************************* 4: 查 询 学 生 信 息 ***************************************"<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 查 找 学 生 学 号:";
cin>>temp;
cout<<endl;
for(i=0;i<NUM;i++)//查找是存在该学号
{
if(!strcmp(temp,stu[i].id))
{
break;
}
}
if(i==NUM)//没找到
{
cout<<endl;
cout<<"无 该 学 号 信 息 !"<<endl;
}
else
{
Print_Stu_Info(stu+i,1);//显示学生当前信息
}
cout<<endl;
system("pause");
}
void Del_Stu_Info()
{
int i,j;
char temp[20];
system("cls");
cout<<endl;
cout<<"******************************************* 3: 删 除 学 生 信 息 ***************************************"<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 删 除 学 生 学 号:";
cin>>temp;
cout<<endl;
for(i=0;i<NUM;i++)//查找是存在该学号
{
if(!strcmp(temp,stu[i].id))
{
break;
}
}
if(i==NUM)//没找到
{
cout<<"无 该 学 号 信 息!"<<endl;
system("pause");
return ;
}
else
{
Print_Stu_Info(stu+i,1);//显示学生当前信息
}
cout<<endl;
cout<<"确 认 删 除 ? Y / N"<<endl;
cin>>temp;
cout<<endl;
if(!strcmp("Y",temp)||!strcmp("y",temp))
{
for(j=i;j<NUM;j++)
{
stu[j]=stu[j+1];
}
NUM--;
cout<<"删 除 成 功 !"<<endl;
cout<<endl;
}
else
{
cout<<"取 消 删 除 成 功 !"<<endl;
cout<<endl;
}
system("pause");
}
void Stu_Info_Menu()
{
int chioce;
do
{
system("cls");
cout<<endl;
cout<<"************************************** 学 生 基 本 信 息 管 理 ********************************"<<endl;
cout<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 1: 添 加 学 生 信 息"<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 2: 修 改 学 生 信 息"<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 3: 删 除 学 生 信 息"<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 4: 查 询 学 生 信 息"<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 5: 浏 览 学 生 信 息"<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<endl;
cout<<"************************************************ 0: 返 回 上 一 级 ***********************************************"<<endl;
cout<<"请 选 择:";
cin>>chioce;
while(chioce<0||chioce>5)
{
cout<<"输 入 错 误,请重新输入!"<<endl;
cin>>chioce;
}
switch(chioce)
{
case 1:
Input_Stu_Info();
break;
case 2:
Modify_Stu_Info();
break;
case 3:
Del_Stu_Info();
break;
case 4:
Serach_Stu_Info();
break;
case 5:
system("cls");
cout<<endl;
cout<<"******************************************* 5: 浏 览 学 生 信 息 ***************************************"<<endl;
cout<<endl;
Print_Stu_Info(stu,NUM);
cout<<endl;
system("pause");
break;
}
}while(chioce!=0);
}
void Input_Score_Info()
{
int i;
char temp[20];
system("cls");
cout<<endl;
cout<<"******************************************* 1: 添 加 学 生 成 绩 ***************************************"<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 学 生 学 号:";
cin>>temp;
cout<<endl;
for(i=0;i<NUM;i++)//查找是存在该学号
{
if(!strcmp(temp,stu[i].id))
{
break;
}
}
if(i==NUM)//没找到
{
cout<<endl;
cout<<"无 该 学 号 信 息!"<<endl;
cout<<endl;
system("pause");
return ;
}
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 C++ 成 绩:";
cin>>stu[i].score[0];
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 高 数 成 绩:";
cin>>stu[i].score[1];
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 英 语 成 绩:";
cin>>stu[i].score[2];
stu[i].score[3]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
cout<<endl;
cout<<"录 入 成 功 !"<<endl;
cout<<endl;
system("pause");
}
void Print_Score_Info(STU* stu,int n)
{
int i;
cout<<"************************************************************************************************************************";
cout<<setw(-10)<<"学 号";
cout<<setw(10)<<"姓 名";
cout<<setw(10)<<" C++";
cout<<setw(10)<<"高 数";
cout<<setw(10)<<"英 语";
cout<<setw(10)<<"平 均 分";
cout<<setw(10)<<"总 分"<<endl;
cout<<"************************************************************************************************************************";
for(i=0;i<n;i++)
{
cout<<setw(-10)<<stu[i].id;
cout<<setw(10)<<stu[i].name;
if(stu[i].score[3]!=-1)
{
cout<<setw(11)<<stu[i].score[0];
cout<<setw(10)<<stu[i].score[1];
cout<<setw(10)<<stu[i].score[2];
cout<<setw(10)<<stu[i].score[3]*1.0/3;
cout<<setw(10)<<stu[i].score[3]<<endl;
}
else
{
cout<<setw(11)<<"无";
cout<<setw(10)<<"无";
cout<<setw(10)<<"无";
cout<<setw(10)<<"无";
cout<<setw(10)<<"无"<<endl;
}
}
cout<<"************************************************************************************************************************";
}
void Serach_Score_Info()
{
int i;
char temp[20];
system("cls");
cout<<endl;
cout<<"******************************************* 3: 查 询 学 生 成 绩 ***************************************"<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 查 找 学 生 学 号:";
cin>>temp;
cout<<endl;
for(i=0;i<NUM;i++)//查找是存在该学号
{
if(!strcmp(temp,stu[i].id))
{
break;
}
}
if(i==NUM)//没找到
{
cout<<"无 该 学 号 信 息!"<<endl;
}
else
{
Print_Score_Info(stu+i,1);//显示学生当前信息
}
cout<<endl;
system("pause");
}
void Modify_Score_Info()
{
int i;
char temp[20];
system("cls");
cout<<endl;
cout<<"******************************************* 2: 修 改 学 生 成 绩 ***************************************"<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 修 改 学 生 学 号:";
cin>>temp;
cout<<endl;
for(i=0;i<NUM;i++)//查找是存在该学号
{
if(!strcmp(temp,stu[i].id))
{
break;
}
}
if(i==NUM)//没找到
{
cout<<"无 该 学 号 信 息!"<<endl;
system("pause");
return ;
}
else
{
Print_Score_Info(stu+i,1);//显示学生当前信息
}
cout<<endl;
cout<<"请 输 入 C++ 成 绩:";
cin>>stu[i].score[0];
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 高 数 成 绩:";
cin>>stu[i].score[1];
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 英 语 成 绩:";
cin>>stu[i].score[2];
stu[i].score[3]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
cout<<endl;
cout<<"修 改 成 功 !"<<endl;
cout<<endl;
system("pause");
}
void Score_Info_Menu()
{
int chioce;
do
{
system("cls");
cout<<endl;
cout<<"************************************** 学 生 成 绩 信 息 管 理 ********************************"<<endl;
cout<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 1: 录 入 学 生 成 绩"<<endl;
cout<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 2: 修 改 学 生 成 绩"<<endl;
cout<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 3: 查 询 学 生 成 绩"<<endl;
cout<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 4: 浏 览 学 生 成 绩"<<endl;
cout<<endl;
cout<<"************************************************ 0: 返 回 上 一 级 ***********************************************"<<endl;
cout<<"请 选 择:";
cin>>chioce;
while(chioce<0||chioce>4)
{
cout<<"输入错误,请重新输入!"<<endl;
cin>>chioce;
}
switch(chioce)
{
case 1:
Input_Score_Info();
break;
case 2:
Modify_Score_Info();
break;
case 3:
Serach_Score_Info();
break;
case 4:
system("cls");
cout<<endl;
cout<<"******************************************* 4: 浏 览 学 生 信 息 ***************************************"<<endl;
cout<<endl;
Sort_Sum();
Print_Score_Info(stu,NUM);
cout<<endl;
system("pause");
break;
}
}while(chioce!=0);
}
void Save_Stu_Info()
{
ofstream fileout("stu_info.dat",ios::binary);
if(!fileout)
{
cout<<"文件不能被打开!"<<endl;
return ;
}
for(int i=0;i<NUM;i++)
{
fileout.write((char*)&stu[i],sizeof(STU));
}
fileout.close();
}
void Load_Stu_Info()
{
ifstream filein("stu_info.dat",ios::binary);
while(filein)
{
filein.read((char*)&stu[NUM],sizeof(STU));
NUM++;
}
if(NUM>=1)
{
NUM-=1;
}
filein.close();
}
void Print_Class_Info()
{
int i;
char temp1[20],temp2[20];
system("cls");
cout<<endl;
cout<<"******************************************* 1: 浏 览 班 级 信 息 ***************************************"<<endl;
cout<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 要 查 看 的 专 业 及 班 级:";
cin>>temp1>>temp2;
cout<<endl;
cout<<"************************************************************************************************************************";
cout<<setw(-10)<<"学 号";
cout<<setw(10)<<"姓 名";
cout<<setw(10)<<"性 别";
cout<<setw(10)<<"年 龄";
cout<<setw(10)<<"专 业";
cout<<setw(10)<<"班 级";
cout<<setw(10)<<" C++";
cout<<setw(10)<<"高 数";
cout<<setw(10)<<"英 语";
cout<<setw(10)<<"平 均 分";
cout<<setw(10)<<"总 分"<<endl;
cout<<"************************************************************************************************************************";
for(i=0;i<NUM;i++)
{
if(!strcmp(temp1,stu[i].major)&&!strcmp(temp2,stu[i].class_num))
{
cout<<setw(-10)<<stu[i].id;
cout<<setw(10)<<stu[i].name;
cout<<setw(10)<<stu[i].sex;
cout<<setw(10)<<stu[i].age;
cout<<setw(10)<<stu[i].major;
cout<<setw(10)<<stu[i].class_num;
if(stu[i].score[3]!=-1)
{
cout<<setw(11)<<stu[i].score[0];
cout<<setw(10)<<stu[i].score[1];
cout<<setw(10)<<stu[i].score[2];
cout<<setw(10)<<stu[i].score[3]*1.0/3;
cout<<setw(10)<<stu[i].score[3]<<endl;
}
else
{
cout<<setw(11)<<"无";
cout<<setw(10)<<"无";
cout<<setw(10)<<"无";
cout<<setw(10)<<"无";
cout<<setw(10)<<"无"<<endl;
}
}
}
cout<<"************************************************************************************************************************";
cout<<endl;
system("pause");
}
void Del_Class_Info()
{
int i,flag=1,j;
char temp[20],temp1[20],temp2[20];
system("cls");
cout<<endl;
cout<<"******************************************* 2: 删 除 班 级 信 息 ***************************************"<<endl;
cout<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------";
cout<<"请 输 入 要 删 除 的 专 业 及 班 级:";
cin>>temp1>>temp2;
cout<<"************************************************************************************************************************";
cout<<setw(-10)<<"学 号";
cout<<setw(10)<<"姓 名";
cout<<setw(10)<<"性 别";
cout<<setw(10)<<"年 龄";
cout<<setw(10)<<"专 业";
cout<<setw(10)<<"班 级";
cout<<setw(10)<<" C++";
cout<<setw(10)<<"高 数";
cout<<setw(10)<<"英 语";
cout<<setw(10)<<"平 均 分";
cout<<setw(10)<<"总 分"<<endl;
cout<<"************************************************************************************************************************";
for(i=0;i<NUM;i++)
{
if(!strcmp(temp1,stu[i].major)&&!strcmp(temp2,stu[i].class_num))
{
cout<<setw(-10)<<stu[i].id;
cout<<setw(10)<<stu[i].name;
cout<<setw(10)<<stu[i].sex;
cout<<setw(10)<<stu[i].age;
cout<<setw(10)<<stu[i].major;
cout<<setw(10)<<stu[i].class_num;
if(stu[i].score[3]!=-1)
{
cout<<setw(11)<<stu[i].score[0];
cout<<setw(10)<<stu[i].score[1];
cout<<setw(10)<<stu[i].score[2];
cout<<setw(10)<<stu[i].score[3]*1.0/3;
cout<<setw(10)<<stu[i].score[3]<<endl;
}
else
{
cout<<setw(11)<<"无";
cout<<setw(10)<<"无";
cout<<setw(10)<<"无";
cout<<setw(10)<<"无";
cout<<setw(10)<<"无"<<endl;
}
flag=0;
}
}
cout<<"************************************************************************************************************************";
if(flag)
{
cout<<"无该专业班级信息"<<endl;
system("pause");
return ;
}
cout<<endl;
cout<<"确认删除?Y/N"<<endl;
cin>>temp;
if(!strcmp(temp,"Y")||!strcmp(temp,"y"))
{
for(i=0;i<NUM;)
{
if(!strcmp(temp1,stu[i].major)&&!strcmp(temp2,stu[i].class_num))
{
for(j=i;j<NUM;j++)
{
stu[j]=stu[j+1];
}
NUM--;
}
else
{
i++;
}
}
cout<<endl;
cout<<"删除成功"<<endl;
}
else
{
cout<<endl;
cout<<"取消删除成功"<<endl;
}
cout<<endl;
system("pause");
}
void Class_Info_Menu()
{
int chioce;
do
{
system("cls");
cout<<endl;
cout<<"************************************** 班 级 学 生 信 息 管 理 ********************************"<<endl;
cout<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 1: 浏 览 班 级 信 息"<<endl;
cout<<endl;
cout<<"****----****----****----****----****------------------------------------------------****----****----****----****----****";
cout<<" 2: 删 除 学 生 成 绩"<<endl;
cout<<endl;
cout<<"************************************************ 0: 返 回 上 一 级 ***********************************************"<<endl;
cout<<"请 选 择:";
cin>>chioce;
while(chioce<0||chioce>2)
{
cout<<"输入错误,请重新输入!"<<endl;
cin>>chioce;
}
switch(chioce)
{
case 1:
Sort_Sum();
Print_Class_Info();
break;
case 2:
Del_Class_Info();
break;
}
}while(chioce!=0);
}
int main()
{
int chioce;
system("mode con: cols=120 lines=40");
Load_Stu_Info();
do
{
chioce=Menu();
switch(chioce)
{
case 1:
Stu_Info_Menu();
break;
case 2:
Score_Info_Menu();
break;
case 3:
Class_Info_Menu();
break;
}
}while(chioce!=0);
Save_Stu_Info();
return 0;
}