#include<iostream>
//输入输出
#include<string>
#include<iomanip>
//输出格式控制
using namespace std;
char press;int choose;int n;
class Student
{public:
string name;
char number;
float gs;
float cjj;
float yy;
float ls;
float zz;
int sum;
int ave;
};
Student stud[30];
//========================输入资料========
void input()
{cout<<"请根据你的需要输入学生的个数:";
cin>>n;for(int a=0;a<n;a++)
{cout<<"请输入第"<<a+1<<"个学生资料:"<<endl;
cout<<"学号:"<<' ';cin>>stud[a].number;
cout<<"姓名:"<<' ';cin>>stud[a].name;
cout<<"高数:"<<' ';cin>>stud[a].gs;
cout<<"C++:"<<' ';cin>>stud[a].cjj;
cout<<"英语:"<<' ';cin>>stud[a].yy;
cout<<"历史:"<<' ';cin>>stud[a].ls;
cout<<"政治:"<<' ';cin>>stud[a].zz;}
}
//————————————————删除资料——————————————————
void SC()
{do{string SC_name;
cout<<"请输入你要删除的学生名字:"<<endl;int i=0;cin>>SC_name;
while(stud[i].name!=SC_name&&i<n) i++;
//查找判断
if(stud[i].name==SC_name)
{for(int j=i;j<n-1;j++)
{stud[i].number=stud[i+1].number;
stud[i].name=stud[i+1].name;
stud[i].gs=stud[i+1].gs;
stud[i].cjj=stud[i+1].cjj;
stud[i].yy=stud[i+1].yy;
stud[i].ls=stud[i+1].ls;
stud[i].zz=stud[i+1].zz;}
cout<<"删除成功!"<<endl;n=n-1;}
else if(i==n) {cout<<"can't find this name"<<endl;cout<<"该信息不存在,无法删除!"<<endl;}
cout<<"(是否继续操作?(y/n))"<<endl;cin>>press;}while(press=='y'||press=='Y') ;}
//————————————————修改资料——————————————————
void XG()
{begin:string find_name;int i;
cout<<"请输入你要修改的学生名字:"<<endl;cin>>find_name;
for(i=0;i<n;i++)
if(stud[i].name==find_name)
{cout<<stud[i].name<<" "<<"has been found:"<<endl;
cout<<"学生的学号:"<<stud[i].number<<' '
<<"姓名:"<<stud[i].name<<' '
<< "英语:"<<stud[i].gs<<' '
<< "班级:"<<stud[i].cjj<<' '
<<"高数成绩:"<<stud[i].yy<<' '
<<"大学英语成绩:"<<stud[i].ls<<' '
<<"C++成绩:"<<stud[i].zz<<endl;break;}
if(stud[i].name!=find_name)
{cout<<"can't find this name"<<endl;
cout<<"请重新查找!"<<endl;goto begin;}
for(int j=0;j<n;j++)
{cout<<"请输入新的信息:"<<endl;
cout<<"学号:"<<' ';cin>>stud[j].number;
cout<<"姓名:"<<' ';cin>>stud[j].name;
cout<<"英语:"<<' ';cin>>stud[j].gs;
cout<<"班级:"<<' ';cin>>stud[j].cjj;
cout<<"高数成绩:"<<' ';cin>>stud[j].yy;
cout<<"大学英语成绩:"<<' ';cin>>stud[j].ls;
cout<<"C++成绩:"<<' ';cin>>stud[j].zz;
}
}
void km()
{char press;
int i,k,c;
cout<<"请输入要查询学生的学号"<<endl;
cin>>press;
for (i=0;i<30;i++)
{
if (stud[i].number==press)
k=i;
}
cout<<"输入要查询的科目代号"<<endl;
/*void wkcj()
{
cout<<"1.高数"<<endl;
cout<<"2.C++"<<endl;
cout<<"3.英语"<<endl;
cout<<"4.历史"<<endl;
cout<<"5.政治"<<endl;
}
void average()
{int num;
int i,k,s=0;
cout<<"请输入要查询的学号"<<endl;
cin>>num;
for (i=0;i<30;i++)
{
if (stud[i].number==num)
k=i;break;
if (stud[i].number!=num)
s=s+1;
}
if (s=30)
{
cout<<"学号输入错误"<<endl;break;
}
cout<<stud[k].name<<"的平均成绩为"<<(stud[k].gs+stud[k].cjj+stud[k].yy+stud[k].ls+stud[k].zz)/5<<endl;
}
void pj()
{
cout<<"请键入数字一选择课程"<<endl;
wkcj();
cin>>c;
switch(c)
{
case 1:{for (i=1;i<=30;i++) s=s+stud[i].gs;
ave=s/30;};cout<<"高数平均成绩"<<ave<<endl;break;
case 2:{for (i=1;i<=30;i++) s=s+stud[i].cjj;
ave=s/30;};cout<<"C++平均成绩"<<ave<<endl;break;
case 3:{for (i=1;i<=30;i++) s=s+stud[i].cjj;
ave=s/30;};cout<<"英语平均成绩"<<ave<<endl;break;
case 4:{for (i=1;i<=30;i++) s=s+stud[i].cjj;
ave=s/30;};cout<<"历史平均成绩"<<ave<<endl;break;
case 5:{for (i=1;i<=30;i++) s=s+stud[i].cjj;
ave=s/30;};cout<<"政治平均成绩"<<ave<<endl;break;
}
}
void rate()
{
int i,s=0,c;
cout<<"请键入数字一选择课程"<<endl;
wkcj();
cin>>c;
switch(c)
{
case 1:{for (i=1;i<=30;i++){ if (stud[i].gs>=60)
s=s+1;
}}
case 2:{for (i=1;i<=30;i++){ if (stud[i].cjj>=60)
s=s+1;
}}
case 3:{for (i=1;i<=30;i++){ if (stud[i].yy>=60)
s=s+1;
}}
case 4:{for (i=1;i<=30;i++){ if (stud[i].ls>=60)
s=s+1;
}}
case 5:{for (i=1;i<=30;i++){ if (stud[i].zz>=60)
s=s+1;
}}
}
rate=s/30;
cout<<"该门课程及格率为"<<rate<<endl;
}
//======================最大值计算=============================
int max()
{
int i,m,c;
cout<<"请键入数字一选择课程"<<endl;
wkcj();
cin>>c;
switch(c)
{
case 1:{m=stud[0].gs;for (i=1;i<=30;i++){if (stud[i].gs>stud[0].gs)
m=stud[i].gs}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
case 2:{m=stud[0].cjj;for (i=1;i<=30;i++){if (stud[i].cjj>stud[0].cjj)
m=stud[i].cjj}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
case 3:{m=stud[0].yy;for (i=1;i<=30;i++){if (stud[i].yy>stud[0].yy)
m=stud[i].yy}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
case 4:{m=stud[0].ls;for (i=1;i<=30;i++){if (stud[i].ls>stud[0].ls)
m=stud[i].ls}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
case 5:{m=stud[0].zz;for (i=1;i<=30;i++){if (stud[i].zz>stud[0].zz)
m=stud[i].zz}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
}
}
//=====================最小值计算==================
int min()
{
int i,m,c;
cout<<"请键入数字一选择课程"<<endl;
wkcj();
cin<<c;
switch(c)
{
case 1:{m=stud[0].gs;for (i=1;i<=30;i++){if (stud[i].gs<stud[0].gs)
m=stud[i].gs}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
case 2:{m=stud[0].cjj;for (i=1;i<=30;i++){if (stud[i].cjj<stud[0].cjj)
m=stud[i].cjj}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
case 3:{m=stud[0].yy;for (i=1;i<=30;i++){if (stud[i].yy<stud[0].yy)
m=stud[i].yy}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
case 4:{m=stud[0].ls;for (i=1;i<=30;i++){if (stud[i].ls<stud[0].ls)
m=stud[i].ls}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
case 5:{m=stud[0].zz;for (i=1;i<=30;i++){if (stud[i].zz<stud[0].zz)
m=stud[i].zz}cout<<"姓名"<<stud[i].name<<"最大值为"<<m};break;
}
}
//=============================定义课程查询界面===========================
void akc()
{while(choose!=0){
cout<<"1.查询某门课平均成绩(输入课程,输出平均成绩)"<<endl;
cout<<"查询某门课及格率(输入课程,输出及格率)"<<endl;
cout<<"查询某门课程最小成绩(输入课程,输出姓名、最小成绩)"<<endl;
cout<<"查询某门课程最大成绩(输入课程,输出姓名、最大成绩)"<<endl;
cin>>choose;
switch(choose)
{
case 1:pj();break;
case 2:rate();break;
case 3:min();break;
case 4:max();break;
default:cout<<"\t\t
输入错误或返回主界面"<<'\n';break;}}}
//==================定义学号查询界面====================
void axh()
{while(choose!=0){
cout<<"1.查询某学生某门课成绩(输入学号,输出成绩)"<<endl;
cout<<"2.查询某学生平均成绩(输入学号,输出成绩)"<<endl;
cout<<"输入要进行操作的编号"<<endl;
cin>>choose;
switch(choose)
{case 1:km();break;
case 2:average();break;
default:cout<<"\t\t
输入错误或返回主界面"<<'\n';break;}}}
//-----------------定义主界面---------------------
int main()
{while(choose!=0){
cout<<"输入学生成绩"<<endl;
cout<<"学生成绩查询"<<endl;
cout<<"课程成绩查询"<<endl;
cout<<"填加学生及相应课程成绩"<<endl;
cout<<"删除学生及相应课程成绩"<<endl;
cin>>choose;
switch(choose)
{case 1: input();break;
case 2: axh();break;
case 3: akc();break;
case 4: SC();break;
case 5: XG();break;
default:cout<<"\t\t\t
输入错误,返回"<<endl;break;}}
return 0;
}