You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.3 KiB
91 lines
2.3 KiB
#include <stdio.h>
|
|
//定义结构组
|
|
typedef struct {
|
|
int student_id;
|
|
float math_grade;
|
|
float physics_grade;
|
|
float english_grade;
|
|
float total_grade;
|
|
float average_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;
|
|
students[i].average_grade = students[i].total_grade / 3.0;
|
|
|
|
|
|
}
|
|
|
|
// 排序
|
|
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\n", students[i].student_id,students[i].total_grade,students[i].average_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;
|
|
}
|