#include #include struct Student { int student_id; float math_score; float physics_score; float english_score; float total_score; float average_score; } Student; void swap(struct Student *a, struct Student *b) { struct Student temp; temp = *a; *a = *b; *b = temp; } void sortStudentsByTotalScore(struct Student students[], int num) { int i,j; for (i = 0; i < num- 1; i++) { for (j = 0; j < num - i - 1; j++) { if (students[j].total_score > students[j + 1].total_score) { swap(&students[j], &students[j + 1]); } } } } void display_menu() { printf("%30s 1. Input\n", ""); printf("%30s 2. Output\n", ""); printf("%30s 3. Order\n", ""); printf("%30s 4. Quit\n", ""); } void input_students(struct Student *students) { printf("Please input info of the three students:\n"); int i; for (i = 0; i < 3; i++) { scanf("%d", &students[i].student_id); scanf("%f", &students[i].math_score); scanf("%f", &students[i].physics_score); scanf("%f", &students[i].english_score); students[i].total_score = students[i].math_score + students[i].physics_score + students[i].english_score; students[i].average_score = students[i].total_score / 3.0; } sortStudentsByTotalScore(students, 3); for (i = 0; i < 3; i++) { printf("%d,%.1f,%.1f\n", students[i].student_id, students[i].total_score, students[i].average_score); } } int main() { struct Student students[3]; char user_input[2]; while (1) { display_menu(); scanf("%1s", user_input); switch (user_input[0]) { case 'i': input_students(students); break; case 'o': printf("%30s You are trying to Output info\n"," "); break; case 'm': printf("%30s You are trying to Make things ordered\n", ""); break; case 'q': printf("%30s You are about to Quit\n", ""); default: printf("%30s Wrong input\n", ""); break; } } return 0; }