#include
#include
#include
class stu
{
char name[20];
double math,chinese,english,average,sum;
public:
stu()
{
}
stu(char n[20],double ma,double chin,double eng)
{
strcpy(name,n);
math=ma;
chinese=chin;
english=eng;
}
double getsum()
{
sum=chinese+english+math;
return sum;
}
double getaver()
{
average=getsum()/3;
return average;
}
friend void main();
};
void main()
{
cout<<"请选择您需要的操作!"<
stu *s[50];
ofstream *file[50];
int i=0;
int j=0;
bool flag2=0;
do
{
cin>>p;
if((p>='0'&&p<='10'))
flag2=1;
else
cout<<"指令错误!请重新输入:"<
do
{
switch(p)
{
case '0':
{
char c;
char name[20];double math,chinese,english;
do{
cout<<"请输入姓名"<
cout<<"请输入数学成绩:"<
cout<<"请输入语文成绩:"<
cout<<"请输入外语成绩:"<
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<
s[i]=new stu(name, math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<
flag2=0;
do
{
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
else
flag2=1;
}while(flag2==0);
}while(c=='y');
break;
}
case '4':
{
double t;char c;
do
{
int flag1=0;
cout<<"请输入你要查询学生的总成绩"<
for(int q=0;q{
if(s[q]->getsum()==t)
{
flag1=1;
cout<<"您要查询的学生是:"<<(*s[q]).name<
}
if(flag1==0)
cout<<"对不起!您要查询的学生不存在!"<
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
}
while(c=='y');
break;
}
case '5':
{
char n[20];int j=0;char c;
do{
int flag=0;
cout<<"请输入你要查询的学生姓名"<
for(int j=0;j{
if(strcmp(n,(*s[j]).name)==0)
{
flag=1;
cout<<"您要查询的学生是:"<<(*s[j]).name<
}
if(flag==0)
cout<<"对不起!您要查询的学生不存在!"<
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
}
while(c=='y');
break;
}
case '1':
{
char name[20];double math,chinese,english;
char c;
do
{
cout<<"请输入您要增加的学生的姓名:"<
cout<<"请输入数学成绩:"<
cout<<"请输入语文成绩:"<
cout<<"请输入外语成绩:"<
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<
s[i]=new stu(name, math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
}while(c=='y');
break;
}
case '2':
{
char name[20];bool flag3=0;char c;
do{
cout<<"请输入您要删除的学生姓名:"<
for(int h=0;h{
if(strcmp(name,s[h]->name)==0)
{
flag3=1;
i--;
do{
s[h]=s[h+1];
h++;
}while(h<=i);
}
}
if(flag3==0)
cout<<"您要求删除的对象本来就不存在!请检查输入的正确性!";
cout<<"要继续删除吗?(y/n)"<
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
}while(c=='y');
break;
}
case '3':
{
char name[20];double mat,chin,eng;flag2=0;
char c;
do
{
cout<<"请输入您要修改的学生的姓名:"<
for(int h=0;h{
if(strcmp(name,s[h]->name)==0)
{
flag2=1;
cout<<"请输入新的数学成绩:"<
cout<<"请输入新的语文成绩:"<
cout<<"请输入新的外语成绩:"<
s[h]->chinese=chin;
s[h]->math=mat;
s[h]->english=eng;
cout<<"数据修改成功!";
}
}
if(flag2==0)
{
cout<<"您要修改的学生本来就不存在!请检查重新输入!"<
cout<<"想继续修改吗(y/n)"<
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
}while(c=='y');
break;
}
case '6':
{
cout<<"本系统所有学生数据如下:"<
cout<<"管理系统中没有录入数据或者数据已经被删除!"<
cout<
"语文:"<<" "<chinese<<"数学:"<<" "<math
<<"外语:"<<" "<english<<"总分:"<<" "<<(*s[k]).getsum()
<<"平均分:"<<" "<<(*s[k]).getaver()<
break;
}
case '7':
{
int t;stu b;
cout<<"本系统所以学生排名如下:"<
t=x;
for(int y=x+1;y{
if((s[t]->getsum())<(s[y]->getsum()))
t=y;
if(t!=x)
{
b=*s[x];
*s[x]=*s[t];
*s[t]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k{
cout<
"语文:"<<" "<chinese<<"数学:"<<" "<math
<<"外语:"<<" "<english<<"总分:"<<" "<getsum()
<<"平均分:"<<" "<getaver()<
break;
}
case '8':
{
int t;stu b;
cout<<"本系统所以学生语文排名如下:"<
t=x;
for(int y=x+1;y{
if((s[t]->chinese)<(s[y]->chinese))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k{
cout<
"语文:"<<" "<chinese<<"数学:"<<" "<math
<<"外语:"<<" "<english<<"总分:"<<" "<getsum()
<<"平均分:"<<" "<getaver()<
break;
}
case '9':
{
int t;stu b;
cout<<"本系统所以学生数学排名如下:"<
t=x;
for(int y=x+1;y{
if((s[t]->math)<(s[y]->math))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k{
cout<
"语文:"<<" "<chinese<<"数学:"<<" "<math
<<"外语:"<<" "<english<<"总分:"<<" "<getsum()
<<"平均分:"<<" "<getaver()<
break;
}
case 'y':
{
int t;stu b;
cout<<"本系统所以学生英语排名如下:"<
t=x;
for(int y=x+1;y{
if((s[t]->english)<(s[y]->english))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k{
cout<
"语文:"<<" "<chinese<<"数学:"<<" "<math
<<"外语:"<<" "<english<<"总分:"<<" "<getsum()
<<"平均分:"<<" "<getaver()<
}
break;
}
cout<<"您想继续进行其他操作吗?(y/n)"<
do
{
cin>>w;
if(w!='y'&&w!='n')
cout<<"指令错误!请重新输入!"<
flag4=1;
}while(flag4==0);
if(w=='y')
cout<<"请输入操作代码(0 录入/4 按总分查询/5 按姓名查询/1 增加人员/2 删除人员/3 修改数据/6 显示所有成员数据/7 按总分排名/8 按语文排名/9按数学排名/y按英语排名)"<
}while(w=='y');
for(int x=0;x{
delete s[x];
cout<<"delete all members!"<
}
胡````````````
太麻烦了