#include <iostream>
#include <iomanip>
struct student
{int num;
char name[20];
float score[3];
};
void average_print(student *);
void top_print(student *);
void top1_print(student *);
void top2_print(student *);
void top3_print(student *);
int main()
{ student stu[3],*p;
int i;
cout<<"请输入3个学生数据:"<<endl;
for(i=0;i<3;++i)
{cin>>stu[i].num>>stu[i].name>>stu[i].score[0]>>stu[i].score[1]>>stu[i].score[2];
}
average_print(stu) ;
int z ;
do
{cout<<"请选择相应选项:"<<endl;
cout<<"1:第一门课最高分数的信息"<<endl;
cout<<"2:第二门课最高分数的信息"<<endl;
cout<<"3:第三门课最高分数的信息"<<endl;
cout<<"4:总分最高分数的信息"<<endl;
cin>>z;
switch(z)
{ case 1:top_print(stu) ;break;
case 2:top1_print(stu) ;break;
case 3:top2_print(stu) ;break;
default:top3_print(stu) ;break;
}
}while(z!=0);
return 0;
}
void average_print(student p[])
{ float x=0,y=0,z=0;
int i;
for(i=0;i<3;++i)
{ x+=p[i].score[0];
y+=p[i].score[1];
z+=p[i].score[2];
}
cout<<"第一门课平均成绩"<<x/3<<endl;
cout<<"第二门课平均成绩"<<y/3<<endl;
cout<<"第三门课平均成绩"<<x/3<<endl;
}
void top_print(student point[])
{int i,z;
float j;
student temp ;
temp=point[0];
j=point[0].score[0];
for(i=1;i<3;++i)
{ if(j<=point[i].score[0] )
{j=point[i].score[0];
temp= point[i];}
}
cout<<"这门课最高分为:"<<temp.num<<setw(6)<<temp.name<<setw(6)<<temp.score[0]<<endl;
}
void top1_print(student point[])
{int i,z;
float j;
student temp ;
temp=point[0];
j=point[0].score[1];
for(i=1;i<3;++i)
{ if(j<=point[i].score[1] )
{j=point[i].score[1];
temp= point[i];}
}
cout<<"这门课最高分为:"<<temp.num<<setw(6)<<temp.name<<setw(6)<<temp.score[1]<<endl;
}
void top2_print(student point[])
{int i,z;
float j;
student temp ;
temp=point[0];
j=point[0].score[2];
for(i=1;i<3;++i)
{ if(j<=point[i].score[2] )
{j=point[i].score[2];
temp= point[i];}
}
cout<<"这门课最高分为:"<<temp.num<<setw(6)<<temp.name<<setw(6)<<temp.score[2]<<endl;
}
void top3_print(student point[])
{int i,z;
float j;
student temp ;
temp=point[0];
j=point[0].score[0]+point[0].score[1]+point[0].score[2];
for(i=1;i<3;++i)
{ if(j<=point[i].score[0]+point[i].score[1]+point[i].score[2])
{j=point[i].score[0]+point[i].score[1]+point[i].score[2];
temp= point[i];}
}
cout<<"这门课最高分为:"<<temp.num<<setw(6)<<temp.name<<setw(6)<<temp.score[2]+temp.score[0]+temp.score[1]<<endl;
}
温馨提示:答案为网友推荐,仅供参考