#include "struct.h"
void H_help()
{
for (int i = 0; i < 46; i++)
{
printf("*");
}
printf("\n");
printf(" *\t学生成绩管理系统————帮助菜单\t *\n");
for (int i = 0; i < 46; i++)
{
printf("*");
}
printf("\n");
printf(" *\tH = 显示帮助菜单\t\t *\n");
printf(" *\tT = 成绩录入\t\t\t *\n"); //少
printf(" *\tA = 计算学生平均分\t\t *\n"); //
printf(" *\tL = 列出成绩表\t\t\t *\n"); //
printf(" *\tP = 按平均成绩由高到低排序\t *\n"); //多2
printf(" *\tS = 按学号查询学生成绩\t\t *\n"); //多1
printf(" *\tC = 清屏\t\t\t *\n"); //少3
printf(" *\tQ = 退出系统\t\t\t *\n"); //少2
for (int i = 0; i < 46; i++)
{
printf("*");
}
printf("\n");
printf(" *\tCopyright <C> 2011.06.12 By 姓名 *\n");
for (int i = 0; i < 46; i++)
{
printf("*");
}
printf("\n");
}
void T_Type(int num)
{
int i;
printf("请输入%d名学生的三门课成绩:\n", num);
printf("学号 语文 数学 外语\n");
for (i = 0; i < num; i++)
{
scanf("%d %f %f %f", &stdt[i].id, &stdt[i].Languages, &stdt[i].math, &stdt[i].Foreign);
}
}
void L_List(int num)
{
int i;
printf("学生成绩如下:\n");
if (stdt[0].average != 0)
{
printf("学号\t语文\t数学\t外语\t平均分\n");
for (i = 0; i < num; i++)
{
printf("%d\t%.1f\t%.1f\t%.1f\t%.1f\n", stdt[i].id, stdt[i].Languages, stdt[i].math, stdt[i].Foreign, stdt[i].average);
}
}
else
{
printf("学号\t语文\t数学\t外语\n");
for (i = 0; i < num; i++)
{
printf("%d\t%.0f\t%.0f\t%.0f\n", stdt[i].id, stdt[i].Languages, stdt[i].math, stdt[i].Foreign);
}
}
}
int main(int argc, char const *argv[])
{
char orders;
int order, i, id;
char arr[10] = {'H', 'T', 'A', 'L', 'P', 'S', 'C', 'Q'};
H_help();
printf("请输入命令=");
scanf("%c", &orders);
getchar();
int num = 0;
while (num == 0)
{
if (orders != 'T')
{
printf("成绩表为空!请先使用命令 T 录入学生成绩。\n");
printf("请输入命令=");
scanf("%c", &orders);
}
else if (orders == 'T')
{
printf("请输入学生人数:");
scanf("%d", &num);
T_Type(num);
break;
}
}
while (num > 0)
{
getchar();
printf("请输入命令=");
scanf("%c", &orders);
for (i = 0; i < 8; i++)
{
if (orders == arr[i])
{
order = i + 1;
break;
}
}
if (orders == 'Q')
{
exit(0);
}
else
{
switch (order)
{
case H:
H_help();
break;
case T:
T_Type(num);
break;
case A:
average(stdt, num);
break;
case L:
L_List(num);
break;
case P:
sort(stdt, num);
break;
case S:
find();
break;
case C:
system("clear");
}
}
}
return 0;
}