C语言做一个学生成绩管理系统,有个问题想请教一下!
C语言做了一个非常简单的学生成绩管理系统,想加一个求平均分的功能,但是不会,所以想请教一下各位大神!感激不尽!源代码如下:#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct student
{
char num[20]; /*学号*/
char name[20]; /*姓名*/
char subject[20]; /*科目*/
float grade; /*分数*/
}
stu[3];
void menu()
{
printf(" ======================================================\n");
printf(" || 模拟简单学生成绩管理系统 ||\n");
printf(" || ╭──────╮ ||\n");
printf(" || │★功能菜单★┃ ||\n");
printf(" || ╰━━━━━━╯ ||\n");
printf(" || 1 输入学生成绩 ||\n");
printf(" || 2 输出学生成绩 ||\n");
printf(" || 3 查询学生成绩 ||\n");
printf(" || 0 退出管理系统 ||\n");
printf(" ======================================================\n");
}
void input()
{
printf("\t\t请按顺序输入三个学生姓名,学号,学科,成绩:\n");
printf("\n");
for (int i = 0; i<3; i++)
scanf("%s%s%s%f", stu[i].name, stu[i].num, stu[i].subject, &stu[i].grade);
printf("\n");
}
void show()
{
printf("\n");
printf("姓名\t\t学号\t\t科目\t\t成绩\n");
for (int i = 0; i<3; i++)
printf("%s\t\t%s\t\t%s\t\t%f\n", stu[i].name, stu[i].num, stu[i].subject, stu[i].grade);
printf("\n");
}
void search()
{
char num[20];
printf("\t\t请输入要查询的学号:");
scanf("%s", num);
for (int i = 0; i<3; i++)
{
if (0 == strcmp(num, stu[i].num))
{
printf("\n");
printf("姓名\t\t学号\t\t科目\t\t成绩\n");
printf("%s\t\t%s\t\t%s\t\t%f\n", stu[i].name, stu[i].num, stu[i].subject, stu[i].grade);
printf("\n");
}
}
}
int main()
{
int selection;
while (1)
{
menu();
printf("\t\t请选择0--3:");
scanf("%d", &selection);
switch (selection)
{
case 1: input(); break;
case 2: show(); break;
case 3: search(); break;
case 0: exit(0); break;
default: printf("\t\t输入有误,请重新输入!\n");
}
}
return 0;
}