ADD file via upload

main
ptslgaequ 1 week ago
parent 2f67b0c3b0
commit 4859be6d15

@ -0,0 +1,74 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义结构体表示学生信息
typedef struct Student {
int id;
double mathScore;
double physicsScore;
double englishScore;
double totalScore;
double averageScore;
} Student;
// 交换两个学生结构体的内容
void swap(Student *a, Student *b) {
Student temp = *a;
*a = *b;
*b = temp;
}
// 按照总成绩对学生数组进行排序(冒泡排序示例,可替换为更高效的排序算法)
void sortStudents(Student students[], int numStudents) {
for (int i = 0; i < numStudents - 1; i++) {
for (int j = 0; j < numStudents - i - 1; j++) {
if (students[j].totalScore > students[j + 1].totalScore) {
swap(&students[j], &students[j + 1]);
}
}
}
}
int main() {
Student students[3];
char choice;
// 显示主菜单
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
scanf(" %c", &choice);
switch (choice) {
case 'i':
printf("Please input info of the three students:\n");
for (int i = 0; i < 3; i++) {
scanf("%d", &students[i].id);
scanf("%lf", &students[i].mathScore);
scanf("%lf", &students[i].physicsScore);
scanf("%lf", &students[i].englishScore);
students[i].totalScore = students[i].mathScore + students[i].physicsScore + students[i].englishScore;
students[i].averageScore = students[i].totalScore / 3;
}
sortStudents(students, 3);
for (int i = 0; i < 3; i++) {
printf("%d,%.1lf,%.1lf\n", students[i].id, students[i].totalScore, students[i].averageScore);
}
break;
case 'm':
printf("You are trying to Make things ordered\n");
break;
case 'q':
printf("You are about to Quit\n");
break;
default:
printf("Wrong input\n");
break;
}
return 0;
}
Loading…
Cancel
Save