You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.6 KiB

#include <stdio.h>
#include <stdlib.h>
#define N 3 // ѧ<><D1A7><EFBFBD><EFBFBD>Ŀ
struct student {
int id; // ѧ<><D1A7>
float math, physics, english, total, average; // <20><>ѧ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>Ӣ<EFBFBD><D3A2><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD>ܳɼ<DCB3><C9BC><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>ɼ<EFBFBD>
};
void input(struct student stu[]) {
int i;
printf("Please input info of the three students:\n");
for (i = 0; i < N; i++) {
scanf("%d%f%f%f", &stu[i].id, &stu[i].math, &stu[i].physics, &stu[i].english);
stu[i].total = stu[i].math + stu[i].physics + stu[i].english;
stu[i].average = stu[i].total / 3.0;
}
int j;
struct student temp;
for (i = 0; i < N - 1; i++) {
for (j = 0; j < N - 1 - i; j++) {
if (stu[j].total > stu[j + 1].total) {
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
}
}
}
for (i = 0; i < N; i++) {
printf("%d,%.1f,%.1f\n", stu[i].id, stu[i].total, stu[i].average);
}
}
void output(struct student stu[]) {
int i;
printf("Output student info:\n");
for (i = 0; i < N; i++) {
printf("Student %d,%.1f,%.1f,%.1f,%.1f\n", stu[i].id, stu[i].math, stu[i].physics, stu[i].english, stu[i].total);
}
}
void order(struct student stu[]) {
int i, j;
struct student temp;
for (i = 0; i < N - 1; i++) {
for (j = 0; j < N - 1 - i; j++) {
if (stu[j].total > stu[j + 1].total) {
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
}
}
}
for (i = 0; i < N; i++) {
printf("Student %d,%.1f,%.1f,%.1f,%.1f,%.1f\n", stu[i].id, stu[i].total, stu[i].average);
}
}
int main() {
struct student stu[N];
char choice;
while (1) {
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
printf("Please input info of the three students:\n");
scanf("%c", &choice);
switch (choice) {
case 'i':
input(stu);
break;
case 'o':
output(stu);
break;
case 'r':
order(stu);
break;
case 'q':
printf("You are about to Quit\n");
exit(0);
case 'm':
printf("You are trying to Make things ordered\n");
break;
default:
printf("Wrong input\n");
break;
}
}
return 0;
}