From abd4d1c760f42ce60933a8678af874c0dc11d86c Mon Sep 17 00:00:00 2001 From: pv3e4i5aj Date: Sun, 17 Nov 2024 14:58:05 +0800 Subject: [PATCH] Add task3.cpp --- task3.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 task3.cpp diff --git a/task3.cpp b/task3.cpp new file mode 100644 index 0000000..5201d87 --- /dev/null +++ b/task3.cpp @@ -0,0 +1,106 @@ +#include +//定义结构体 +struct Student +{ + int ID;//学号 + float math_grade; + float physics_grade; + float English_grade; + float sum; + float average; +}; +void Show_The_Main_interface() +{ + //显示主界面 + for(int i=1;i<=30;i++) + { + printf(" "); + } + printf("1.Input\n"); + for(int i=1;i<=30;i++) + { + printf(" "); + } + printf("2.Output\n"); + for(int i=1;i<=30;i++) + { + printf(" "); + } + printf("3.Order\n"); + for(int i=1;i<=30;i++) + { + printf(" "); + } + printf("4.Quit\n"); +} + +void Output_Prompts(char choice) +{ + //输出提示信息 + if(choice=='i') + { + printf("Please input info of the three students:\n"); + } + else if(choice=='o') + { + printf("You are trying to Output info\n"); + } + else if(choice=='m') + { + printf("You are trying to Make things ordered\n"); + } + else if(choice=='q') + { + printf("You are about to Quit\n"); + } + else + { + printf("Wrong input\n"); + } +} +int main() +{ + //显示主界面 + Show_The_Main_interface(); + //用户输入 + char choice; + scanf("%c",&choice); + //输出提示信息 + Output_Prompts(choice); + + //输入学生信息 + struct Student information[3]; + for(int i=0;i<3;i++) + { + scanf("%d%f%f%f",&information[i].ID,&information[i].math_grade,\ + &information[i].physics_grade,&information[i].English_grade); + information[i].sum=information[i].math_grade+information[i].physics_grade\ + +information[i].English_grade; + information[i].average=information[i].sum/3.0; + } + + //排序 + for(int i=0;i<3;i++) + { + for(int j=0;j<3-i-1;j++) + { + if(information[j].sum>information[j+1].sum) + { + //此处我们直接交换结构体 + struct Student tmp; + tmp=information[j]; + information[j]=information[j+1]; + information[j+1]= tmp; + } + } + } + + //按要求输出 + for(int i=0;i<3;i++) + { + printf("%d,%.1f,%.1f\n",information[i].ID,\ + information[i].sum,information[i].average); + } +} + +