#include "stdio.h"
#include <string.h>
#define NC 100
struct studentRed { //定义学生记录,即对应表格的一行
char studName[20]; //姓名对应第一列的Student Name
char studID[20]; //学号对应第二列的Student ID 用20个字符编码,可用字母做学号
float compProgram; // score for Computer programming 用浮点数可输入小数分数
float physEducat; //score for Computer programming
float commResech; //score for Communication and Research
float averageScore; //average score
}*p, students[NC] = {//给数组变量赋值
{"John","zy001",84,86,78,0},
{"Xiaoming","zy002",77,82,90,0},
{"Xiaohua","zy003",79,82,85,0},
{"Jianguo","zy004",84,86,78,0},
{"Xiaodong","zy005",60,55,40,0},
};
int m, j, n;
float temp;
float temp1;
float temp2;
float temp3;
char jiaohuan[10];
char jiaohuan1[10];
//冒泡排序,将各科目分数与学生名和学生学号一起交换
for (m = 0; m < 5; m++) {//这一个冒泡输出compProgram科目的分数排名
for (j = 0; j < 5 - 1; j++) {
if (students[j].compProgram < students[j + 1].compProgram) {
temp = students[j].compProgram;
students[j].compProgram = students[j + 1].compProgram;
students[j + 1].compProgram = temp;
temp1 = students[j].physEducat;
students[j].physEducat = students[j + 1].physEducat;
students[j + 1].physEducat = temp1;
temp2 = students[j].commResech;
students[j].commResech = students[j + 1].commResech;
students[j + 1].commResech = temp2;
temp3 = students[j].averageScore;
students[j].averageScore = students[j + 1].averageScore;
students[j + 1].averageScore = temp3;
strcpy_s(jiaohuan, 10, students[j].studName);
strcpy_s(students[j].studName, 10, students[j + 1].studName);
strcpy_s(students[j + 1].studName, 10, jiaohuan);
strcpy_s(jiaohuan1, 10, students[j].studID);
strcpy_s(students[j].studID, 10, students[j + 1].studID);
strcpy_s(students[j + 1].studID, 10, jiaohuan1);
}
}
}
printf("Name\t ID\t\tComputer\n");
for (n = 0; n < 5; n++) {
printf("%-12s%s\t%f\n", students[n].studName, students[n].studID, students[n].compProgram);
}