Add task3.cpp

main
pv3e4i5aj 4 days ago
parent 9575f75e2c
commit abd4d1c760

@ -0,0 +1,106 @@
#include <stdio.h>
//定义结构体
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);
}
}
Loading…
Cancel
Save