Last active
January 7, 2018 01:49
-
-
Save batkiz/43ab2d4db0b221b2b9b4b5f49ed10eb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define N 11 | |
typedef struct info { | |
int id, Chinese, Math, English; | |
char name[32], sex[32], class[32]; | |
double ave; | |
} Info; // 定义结构体并定义别名,方便调用 | |
void input(Info *j[]) | |
{ | |
int m; | |
printf("请按以下格式输入学生信息\n学号 姓名 性别 语文成绩 数学成绩 英语成绩\n"); | |
for (m = 0; m < N; m++) | |
{ | |
printf("请输入学生信息(进度%d/%d)\n", m + 1, N - 1); | |
scanf("%d %s %s %d %d %d", | |
&j[m]->id, j[m]->name, j[m]->sex, &j[m]->Chinese, &j[m]->Math, &j[m]->English); | |
} // 利用循环输入学生信息 | |
} | |
void ave(Info *k[]) | |
{ | |
int i; | |
for (i = 0; i < N; i++) | |
k[i]->ave = (k[i]->Chinese + k[i]->Math + k[i]->English) / 3; | |
} | |
void swap(Info *x, Info *y) | |
{ | |
Info temp = *x; | |
*x = *y; | |
*y = temp; | |
} | |
void sort_id(Info a[]) | |
{ | |
int i, j; | |
for (i = 0; i < N - 1; i++) | |
{ | |
for (j = N - 1; j > i; j--) | |
{ | |
if (a[j - 1].id > a[j].id) | |
swap(&a[j - 1], &a[j]); | |
} | |
} | |
} | |
void sort_ave(Info a[]) | |
{ | |
int i, j; | |
for (i = 0; i < N - 1; i++) | |
{ | |
for (j = N - 1; j > i; j--) | |
{ | |
if (a[j - 1].ave > a[j].ave) | |
swap(&a[j - 1], &a[j]); | |
} | |
} | |
} | |
void search(Info a[]) | |
{ | |
int i, s; | |
printf("请输入学号:"); | |
scanf("%d", &s); | |
for (i = 0; i < N; i++) | |
{ | |
if (s = a[i].ave) | |
{ | |
printf("%d\t%s\t%d\t%d\t%d\t%.2f\n", | |
a[i].id, a[i].name, a[i].Chinese, a[i].Math, a[i].English, a[i].ave); | |
break; | |
} | |
} | |
} | |
void output(Info a[]) | |
{ | |
int i; | |
printf("学号\t姓名\t语文\t数学\t英语\t平均分\n"); | |
for (i = 0; i < N; i++) | |
{ | |
printf("%d\t%s\t%d\t%d\t%d\t%.2f\n", | |
a[i].id, a[i].name, a[i].Chinese, a[i].Math, a[i].English, a[i].ave); | |
} | |
} | |
int main(void) | |
{ | |
Info student[N]; | |
int selection; // 用于实现菜单选项 | |
printf("请输入选项编号(1 ~ 6)\n1--输入信息\n2--求平均分\n3--排序\n4--查询\n5--输出\n6--退出\n"); | |
// 主菜单选项 | |
scanf("%d", &selection); // 选择 | |
while (selection != 6) // 选择 6 即退出 | |
{ | |
switch (selection) | |
{ | |
case 1 : input(&student); break; // 调用 input 函数,输入信息 | |
case 2 : ave(&student); break; // 调用 ave 函数,求平均分 | |
case 3 : { | |
printf(" 排序菜单\n请输入选项编号(1 ~ 2)\n1--按平均分排序\n2--按学号排序\n"); | |
// 菜单 | |
int sel; // 实现选择 | |
scanf("%d", &sel); | |
switch (sel) | |
{ | |
case 1 : break; | |
case 2 : break; | |
default : printf("\a请输入选项编号(1 ~ 2)!\n"); break; | |
} | |
break; | |
} | |
case 4 : search(student); break; | |
case 5 : output(student); break; | |
default : printf("\a请输入项目编号(1 ~ 6)!\n"); | |
} | |
printf("请输入选项编号(1 ~ 6)\n1--输入信息\n2--求平均分\n3--排序\n4--查询\n5--输出\n6--退出\n"); | |
scanf("%d", &selection); // 选择 | |
} | |
return 0; | |
} | |
/* | |
coursdes.c: In function 'main': | |
coursdes.c:110:28: warning: passing argument 1 of 'input' from incompatible pointer type [-Wincompatible-pointer-types] | |
case 1 : input(&student); break; // 调用 input 函数,输入信息 | |
^ | |
coursdes.c:18:6: note: expected 'Info ** {aka struct info **}' but argument is of type 'Info (*)[11] {aka struct info (*)[11]}' | |
void input(Info *j[]) | |
^~~~~ | |
coursdes.c:111:26: warning: passing argument 1 of 'ave' from incompatible pointer type [-Wincompatible-pointer-types] | |
case 2 : ave(&student); break; // 调用 ave 函数,求平均分 | |
^ | |
coursdes.c:30:6: note: expected 'Info ** {aka struct info **}' but argument is of type 'Info (*)[11] {aka struct info (*)[11]}' | |
void ave(Info *k[]) | |
^~~ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
过来转一圈赶紧跑(