学生信息管理系统编程(c语言)

2024-11-02 08:29:41
推荐回答(1个)
回答1:

挺好的一个题目啊

但我可不愿意帮人写作业

网上很多类似的,你可以参考下:
#include
#include struct student {
char name[30];
float math;
float chinese;
float english;
float average;
};

int MenuChoice(void);
int EnterAccount(void);
void Enter(struct student *fst);
void Amend(struct student *src);
void Delete(struct student *next);
void Print(struct student *out);

main()
{
struct student one[100] = {0}, *look = one;
int menu, t;

while ((menu = MenuChoice()) != 0)

if (menu >= 1 && menu <= 4 && (t = EnterAccount())) {
look = one + t;

switch (menu) {
case 1:
Enter(look);
break;
case 2:
if (strcmp(look->name, ""))
printf("学号:%d\n姓名: %s\n语文成绩: %.1f\n数学成绩:%.1f\n英语成绩: %f\n平均"成绩:%.1f\n",
t, look->name, look->chinese, look->math, look->english, look->average);
else
printf("对不起,该学号不存在!\n");
break;
case 3:
Amend(look);
break;
case 4:
Delete(look);
break;
}
}
else if (menu == 5)
Print(one);
else
printf("错误的请求!\n");

return 0;
}

int MenuChoice(void)
{
int choice;

printf("请选择:\n"
"1 - 新建学生信息\n"
"2 - 查找学生信息\n"
"3 - 修改学生信息\n"
"4 - 删除学生信息\n"
"5 - 打印学生信息\n"
"0 - 退出\n");
scanf("%d", &choice);

return choice;
}

int EnterAccount(void)
{
int ret;

printf("请输入学号:\n");
scanf("%d", &ret);

if (ret >= 1 && ret <= 100)
return ret -1;

return 0;
}

void Enter(struct student *fst)
{
printf("请输入学生姓名、语文成绩、数学成绩、英语成绩和平均成绩\n");
scanf("%s%f%f%f%f", fst->name, &fst->chinese, &fst->math, &fst->english, &fst->average);
}

void Amend(struct student *src)
{
int t;

printf("请选择:\n"
"1 - 修改学生姓名\n"
"2 - 修改学生语文成绩\n"
"3 - 修改学生数学成绩\n"
"4 - 修改学生英语成绩\n"
"5 - 修改学生平均成绩\n");
scanf("%d", &t);

switch (t) {
case 1:
printf("请输入学生的新名字\n");
scanf("%s", src->name);
break;
case 2:
printf("请输入学生新的语文成绩\n");
scanf("%f", &src->chinese);
break;
case 3:
printf("请输入学生新的数学成绩\n");
scanf("%f", &src->math);
break;
case 4:
printf("请输入学生新的英语成绩\n");
scanf("%f", &src->english);
break;
case 5:
printf("请输入学生新的平均成绩\n");
scanf("%f", &src->average);
break;
}

}

void Delete(struct student *next)
{
strcpy(next->name, "");
next->math = next->english = next->chinese = next->average = 0.0;
}

void Print(struct student *out)
{
struct student *up;

for (up = out; out < &up[100]; out++)

if (strcmp(out->name, ""))
printf("学号:%d\n姓名: %s\n语文成绩: %.1f\n数学成绩:%.1f\n英语成绩: %.1f\n平均成绩:%.1f\n",
out-up + 1, out->name, out->chinese, out->math, out->english, out->average);
}