该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
typedef struct stuInfo
{
int stuId;
char name[13];
int cs;
int English;
int math;
}stuInfo;
typedef struct stuGrade
{
float maxAveageGrade;
int stuId;
}stuGrade;
stuInfo input(stuInfo arr[], int arrLength);
stuGrade max(const stuInfo arr[], const int length);
void sort(stuInfo arr[], int start, int end);
int partition(stuInfo arr[], int low, int high);
void output(const stuInfo arr[],int arrLength);
int main()
{
/*测试数据
98023 LiLi 80 85 80
98044 WangTao 79 69 90
99764 ZhangXiaobao 77 79 67
99812 LiuLifang 95 90 91
*/
stuInfo arr[4];
int arrLength = sizeof(arr)/sizeof(arr[0]);
input(arr,arrLength);
stuGrade sg = max(arr,arrLength);
int i;
printf("平均数最大的学生学号是:%d,平均分为:%.2f\n",sg.stuId,sg.maxAveageGrade); //最大平均分
output(arr,arrLength); //信息输出
printf("\n");
printf("信息排序后输出:\n");
printf("学号\t姓名\t 平均分\n");
sort(arr,0,arrLength - 1); //平均分从低到高排序
for(i = 0; i < arrLength; i++)
{
printf("%d\t%-13s\t%.2f\n",arr[i].stuId,arr[i].name,(arr[i].cs + arr[i].English + arr[i].math)/3.0);
}
return 0;
}
stuInfo input(stuInfo arr[], int arrLength){
int i = 0;
for(i = 0; i < arrLength; i++)
{
scanf("%d %s %d %d %d",&arr[i].stuId,&arr[i].name,&arr[i].cs,&arr[i].English,&arr[i].math);
}
}
stuGrade max(const stuInfo arr[], const int length){
stuGrade sg;
//printf("arr[0].cs = %d\n",arr[0].cs);
sg.maxAveageGrade = (arr[0].cs + arr[0].English + arr[0].math)/3.0;
//printf("arr[0].maxAveageGrade = %f\n",maxAveageGrade);
sg.stuId = arr[0].stuId;
//printf("arr[0].stuId = %d\n",arr[0].stuId);
int i;
for(i = 1; i < length; i++)
{
if((arr[i].cs + arr[i].English + arr[i].math)/3.0 > sg.maxAveageGrade)
{
sg.maxAveageGrade = (arr[i].cs + arr[i].English + arr[i].math)/3.0;
sg.stuId = arr[i].stuId;
//printf("arr[%d].stuId = %d\n",i,arr[i].stuId);
}
}
return sg;
}
int partition(stuInfo arr[], int low, int high){
stuInfo key;
key = arr[low];
while(low
while(low = (key.cs + key.English + key.math)/3.0)
high--;
if(low
arr[low++] = arr[high];
while( low
low++;
if(low
arr[high--] = arr[low];
}
arr[low] = key;
return low;
}
void sort(stuInfo arr[], int start, int end){
int pos;
if (start
pos = partition(arr, start, end);
sort(arr,start,pos-1);
sort(arr,pos+1,end);
}
return;
}
void output(const stuInfo arr[],int arrLength){
printf("学生信息输出:\n");
printf("学号\t姓名\t\t 计算机成绩\t 英语成绩\t\t数学成绩\t平均分\n");
int i;
for(i = 0; i < arrLength; i++)
{
printf("%d\t%-13s\t\t%d\t\t%d\t\t%d\t\t%.2f\n",arr[i].stuId,arr[i].name, arr[i].cs,arr[i].English,arr[i].math,(arr[i].cs + arr[i].English + arr[i].math)/3.0);
}
}

被折叠的 条评论
为什么被折叠?



