69,382
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
struct student
{
int num;
char name[10];
int score1;
int score2;
int score3;
float aver;
};
void main()
{
void input(struct student stu[]);
void scoresort(struct student stu[]);
void output(struct student stu[]);
struct student stu[3],*p=stu;
input(p);
scoresort(p);
output(p);
}
void input(struct student stu[])
{
int i;
printf("NUM\tNAME\tSCORE1\tSCORE2\tSCORE3\n");
for(i=0;i<3;i++)
{
scanf("%d%s%d%d%d",&stu[i].num,stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
stu[i].aver=(stu[i].score1+stu[i].score2+stu[i].score3)/3;
}
printf("\n");
cout<<"Before Sort:"<<endl;
printf("NUM\tNAME\tSCORE1\tSCORE2\tSCORE3\tAVERAGE\n");
for(i=0;i<3;i++)
printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].aver);
printf("\n");
}
void scoresort(struct student stu[])
{
int i=0,j,k;
struct student p;
for(;i<2;i++)
{ k=i;
for(j=i+1;j<3;j++)
if(stu[j].aver>stu[k].aver) k=j;
if(k!=i)
{
p=stu[i];stu[j]=stu[k];stu[k]=p;
}
}
void output(struct student stu[])
{
int i;
cout<<"After Sort:"<<endl;
printf("NUM\tNAME\tSCORE1\tSCORE2\tSCORE3\tAVERAGE\n");
for(i=0;i<3;i++)
printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].aver);
printf("\n");
}
#include<iostream>
using namespace std;
struct student
{
int num;
char name[10];
int score1;
int score2;
int score3;
float aver;
};
void main()
{
void input(struct student stu[]);
void scoresort(struct student stu[]);
void output(struct student stu[]);
struct student stu[3],*p=stu;
input(p);
scoresort(p);
output(p);
}
void input(struct student stu[])
{
int i;
printf("NUM\tNAME\tSCORE1\tSCORE2\tSCORE3\n");
for(i=0;i<3;i++)
{
scanf("%d%s%d%d%d",&stu[i].num,stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
stu[i].aver=(stu[i].score1+stu[i].score2+stu[i].score3)/3;
}
printf("\n");
cout<<"Before Sort:"<<endl;
printf("NUM\tNAME\tSCORE1\tSCORE2\tSCORE3\tAVERAGE\n");
for(i=0;i<3;i++)
printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].aver);
printf("\n");
}
void scoresort(struct student stu[])
{
int i=0,j,k;
struct student p;
for(;i<2;i++)
{ k=i;
for(j=i+1;j<3;j++)
if(stu[j].aver>stu[k].aver) k=j;
if(k!=i)
{
p=stu[i];stu[j]=stu[k];stu[k]=p;
}
}
}
void output(struct student stu[])
{
int i;
cout<<"After Sort:"<<endl;
printf("NUM\tNAME\tSCORE1\tSCORE2\tSCORE3\tAVERAGE\n");
for(i=0;i<3;i++)
printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].aver);
printf("\n");
}