C/C++ code/*
编一个程序:用结构体描述60位学生的信息,包括学号,姓名和三门课的成绩和总成绩,并以函数形式实现以下的功能
1:输入学生的前5项信息,并计算每个学生的总成绩
2:按总成绩的递减顺序对成绩表排序
3:输出排序后的成绩
*/
#include
#define N 60
struct student
{
int num;
char name[10];
int score[4]; //三门课的成绩和总成绩,
};
void main()
{
struct student stu[N];
void read(struct student *p,int n); //输入学生成绩,计算
void sort(struct student s[],int n); //排序
void print(struct student *p,int n); //打印
read(stu,N); sort(stu,N);print(stu,N);
}
void read(struct student *p,int n)
{
int i,j,sum=0;
for(i=0;i
scanf("%d %s",&p->num,&p->name);
for(j=0;j<3;j++)
{
scanf("%d %d %d",&p->score[j]);
sum+=p->score[j]; //计算三门课的总成绩
}
p->score[3]=sum; //把总成绩放到score[4】中
}
void sort(struct student s[],int n) //选择排序法
{
int i,j,k;
struct student temp;
for(i=0;i
{
k=i;
for(j=i+1;j
{
if(s[k].score[3]
}
if(k!=i)
{
temp=s[i];
s[i]=s[k];
s[k]=temp;
}
}
}
void print(struct student *p,int n)
{
int i,j;
for(i=0;i
printf("%6d %16s",p->num,p->name);
for(j=0;j<4;j++)
printf("%d",p->score[j]);
printf("\n");
}