1.用C语言编写一个简单的学生信息管理程序,能实现对学生信息的简单管理。
2.建立一个包含10名学生的信息登记表,每个学生的信 息包括:学号,姓名,性别、年龄和3门课的成绩(mathematics,English, program design)。3.程序运行时显示一个简单的菜单,4.实现功能(1) 信息输入、删除、排序:初始状态已包含5名学生信息,在此基础上可对学生信息进行输入、删除、按学号排序等操作。2) 成绩统计:要求能对学生的成绩进行统计,计算出总分和平均分,并按总分降序排列显示出来。要求当输入科目名称时能统计出该科的平均分,能显示出最高分和最低分。3)查询:要求输入一个学生的学号后可显示出该学生的相关信息。
最佳答案
#include <Windows.h>#define NUM_LEN 11#define NAME_LEN 11struct _stu{ char num[NUM_LEN]; char name[NAME_LEN]; int fox; int c; int English;}stu[4];struct{ int index; int total;}score[4];void main(){ char select; int i, j; memset(stu, -1, sizeof(stu)); while (true) { system("cls"); printf("**********欢迎使用学生信息管理程序**********\n"); printf("1.信息输入\n2.总分统计\n3.总分排序\n4.查询\n5.退出程序\n"); while ((select = getch()) < '1' || select > '5'); switch (select) { case '1': { for (i = 0; i < 4; ++i) { printf("请输入第%d位学生的学号(小于%d个字符):\n", i+1, NUM_LEN); scanf("%s", stu[i].num); printf("请输入第%d位学生的姓名(小于%d个字符):\n", i+1, NAME_LEN); scanf("%s", stu[i].name); printf("请输入第%d位学生的 fox 成绩:\n", i+1); scanf("%d", &(stu[i].fox)); printf("请输入第%d位学生的 c 成绩:\n", i+1); scanf("%d", &(stu[i].c)); printf("请输入第%d位学生的 English 成绩:\n", i+1); scanf("%d", &(stu[i].English)); score[i].index = i; score[i].total = stu[i].fox + stu[i].c + stu[i].English; } printf("输入完毕,按任意键返回!\n"); getch(); } break; case '2': { if (stu[0].c == -1) { printf("请先输入学生信息!\n"); break; } for (i = 0; i < 4; ++i) printf("%s 的总分为:%d\n", stu[i].name, stu[i].fox + stu[i].c + stu[i].English); system("pause"); } break; case '3': { for (i = 0; i < 3; ++i) { for (j = i+1; j < 4; ++j) { if (score[i].total < score[j].total) { int t = score[i].total; score[i].total = score[j].total; score[j].total = t; t = score[i].index; score[i].index = score[j].index; score[j].index = t; } } } for (i = 0; i < 4; ++i) printf("第%d名:学号:%s 姓名:%s 总分:%d\n", i+1, stu[score[i].index].num, stu[score[i].index].name, score[i].total); system("pause"); } break; case '4': { if (stu[0].c == -1) { printf("请先输入学生信息!\n"); break; } char cha[NAME_LEN]; printf("请输入要查询的学号:\n"); scanf("%s", cha); for (i = 0; i < 4; ++i) { if (strcmp(cha, stu[i].name) == 0) { printf("学号:%s 姓名:%s fox:%d c:%d English:%d\n", stu[i].num, stu[i].name, stu[i].fox, stu[i].c, stu[i].English); break; } } if (i >= 4) printf("没有此学号的学生!\n"); system("pause"); } break; case '5': printf("**********谢谢使用学生信息管理程序**********\n"); getch(); return; } }}
其他回答
暂无其它回答!