#include <iostream>
using namespace std;
struct Student{
int num;
char *name;
float score;
};
int main() {
void student(Student *pstu, int num, char *name, float score);
void student_to_String(Student stu);
Student stu[5], *pstu;
pstu = stu;
char *pname[5];
pname[0] = "张三·买买提";
pname[1] = "李四·穆罕默德";
pname[2] = "王五·成吉思汗";
pname[3] = "赵六·阿拉斯加";
pname[4] = "爱新觉罗·鞑子";
Student temp;
student(pstu, 1001, pname[0], 88.1);
student((pstu + 1), 1002, pname[1], 90.0);
student((pstu + 2), 1003, pname[2], 88.7);
student((pstu + 3), 1004, pname[3], 99.6);
student((pstu + 4), 1005, pname[4], 1.2);
printf("---------*****---------\n");
printf("按照学号排序的结果如下:\n");
for(int i = 0; i < 5; i++){
student_to_String(stu[i]);
}
printf("---------*****---------\n");
int i = 0, j = 0, k = 0, n = 5;
for(i = 0; i < (n - 1); i ++){
k = i;
for(j = i + 1; j < n; j ++){
if(stu[j].score > stu[k].score){
k = j;
}
}
temp = stu[k];
stu[k] = stu[i];
stu[i] = temp;
}
printf("按照成绩排序后的结果如下:\n");
for(int i = 0; i < 5; i++){
student_to_String(stu[i]);
}
return 0;
}
void student(Student *pstu, int num, char *name, float score){
Student *stu;
stu = pstu;
(*stu).num = num;
(*stu).name = name;
(*stu).score = score;
printf("学生信息构造完毕!\n");
}
void student_to_String(Student stu){
printf("该同学的信息如下:\n");
printf("该同学的学号为:%d\n", stu.num);
printf("该同学的姓名为:%s\n", stu.name);
printf("该同学的分数为:%3.2f\n", stu.score);
printf("该同学的信息输出完毕!\n");
printf("***---------*****---------***\n");
}