From 42c0741807542f629d54fed97ec13c4105e8794d Mon Sep 17 00:00:00 2001 From: pwpf9t6n3 <3345098807@qq.com> Date: Mon, 13 Nov 2023 17:17:19 +0800 Subject: [PATCH] ADD file via upload --- s2.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 s2.c diff --git a/s2.c b/s2.c new file mode 100644 index 0000000..ad0ab7d --- /dev/null +++ b/s2.c @@ -0,0 +1,90 @@ +#include +//定义结构组 +typedef struct { + int student_id; + float math_grade; + float physics_grade; + float english_grade; + float total_grade; +} Student; + +//录入学生信息 +void inputInfo() { + printf("Please input info of the three students:\n"); + + Student students[3]; + + for (int i = 0; i < 3; i++) { + //其实有printf注明以下正在录入的信息是什么更好 + //printf("ID"); + scanf("%d", &students[i].student_id); + //printf("math grade"); + scanf("%f", &students[i].math_grade); + //printf("physics grade"); + scanf("%f", &students[i].physics_grade); + //printf("english grade"); + scanf("%f", &students[i].english_grade); + + students[i].total_grade = students[i].math_grade + students[i].physics_grade + students[i].english_grade; + + } + + // 排序 + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 2 - i; j++) { + if (students[j].total_grade > students[j + 1].total_grade) { + + Student temp = students[j]; + students[j] = students[j + 1]; + students[j + 1] = temp; + } + } + } + + //输出学号 高数 物理 英语 总成绩 + for (int i = 0; i < 3; i++) { + printf("%d %.1f %.1f %.1f %.1f\n", students[i].student_id, students[i].math_grade,students[i].physics_grade,students[i].english_grade,students[i].total_grade); + } +} + +void outputInfo() { + printf("You are trying to Output info.\n"); +} + +void makeOrdered() { + printf("You are trying to Make things ordered.\n"); +} + +//菜单 +int main() { + char choice; + + printf("Main Menu:\n"); + printf("%30s 1.Input\n", ""); + printf("%30s 2.Output\n", ""); + printf("%30s 3.Order\n", ""); + printf("%30s 4.Quit\n", ""); + printf("Please enter your choice: "); + scanf(" %c", &choice); + +//选择 + switch (choice) { + case 'i': + inputInfo(); + break; + case 'o': + outputInfo(); + break; + case 'm': + makeOrdered(); + break; + case 'q': + printf("You are about to Quit.\n"); + break; + default: + printf("Wrong input.\n"); + break; + } + + return 0; +}