用C语言编程实现学生成绩管理程序,要求可以根据选择实现以下功能:(90分) 1、输入5个学生的姓名

2024-11-30 20:05:07
推荐回答(3个)
回答1:

//仅作参考

#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
int studentNum = 0;
#define MAXSTUDENT (1024)
#define CheckData()\
{\
if(!studentNum)\
{\
printf("没有学生数据,按任意键返回……\n");\
getch();\
return;\
}\
}\

typedef struct Student
{
int id;
int cScore;
int mathScore;
}Student;
void ClearStudent(Student* student)
{
memset((void*)student,0,sizeof(*student));
}
void ShowMainMenu()
{
system("cls");
printf("1.增加记录\n2.计算每个学生的总成绩\n3.计算每门课程的平均成绩\n4.按座号查询学生的成绩\n5.按总分排名\n6.输出前n名的学生的成绩\n7.修改成绩\n0.退出\n");
}
void ShowCountScore(const Student* student)
{
system("cls");
CheckData();
for(int i = 0;i < studentNum;i++)
printf("学生%04d的总成绩:%d\n",(student+i)->id,(student+i)->cScore+(student+i)->mathScore);
printf("\n按任意键继续……");
getch();
}
void ShowClassAvg(const Student* student)
{
system("cls");
CheckData();
double sumc = 0;
double summath = 0;
for(int i = 0;i < studentNum;i++)
{
sumc += (student+i)->cScore;
summath += (student+i)->mathScore;
}
printf("C语言平均成绩为:%lf\n",sumc/studentNum);
printf("数学平均成绩为:%lf\n",summath/studentNum);
printf("\n按任意键继续……");
getch();
}
void AddStudent(Student* student)
{
system("cls");
if(studentNum == MAXSTUDENT)
{
printf("人数已满,按任意键返回……\n");
getch();
}
printf("分别录入座号、C语言成绩、数学成绩:\n");
int id = 0;
int cScore = 0;
int mathScore = 0;
scanf("%d%d%d",&id,&cScore,&mathScore);
for(int i = 0 ;i < studentNum;i++)
if((student+i)->id == id)
{
printf("座号重复,按任意键返回……\n");
getch();
return;
}
(student+studentNum)->id = id;
(student+studentNum)->cScore = cScore;
(student+studentNum)->mathScore = mathScore;
studentNum++;
}
void SelectFromID(const Student* student)
{
system("cls");
CheckData();
printf("输入查询ID:\n");
int id = 0;
scanf("%d",&id);
printf("查询结果:\n");
for(int i = 0;iif(id == (student+i)->id)
{
printf("C语言成绩为:%d\n数学成绩为:%d\n",(student+i)->cScore,(student+i)->mathScore);
break;
}
printf("\n按任意键继续……");
getch();
}
void SortForCount(Student* student)
{
system("cls");
CheckData();
for(int i = 0;i < studentNum;i++)
{
for(int j = studentNum -1;j > i;j--)
if(((student+j)->cScore+(student+j)->mathScore) > ((student+j-1)->cScore+(student+j-1)->mathScore))
{
Student stu;
stu = *(student+j);
*(student+j) = *(student+j-1);
*(student+j-1) = stu;
}
}
}
void SortForN(Student* student,int n)
{
SortForCount(student);
if(!studentNum)
return;
n = n>studentNum?studentNum:n;
for(int i = 0;i< n;i++)
printf("第%d名:\nID:%d\nC语言成绩为:%d\n数学成绩为:%d\n总分为:%d\n\n",i+1,(student+i)->id,(student+i)->cScore,(student+i)->mathScore,(student+i)->cScore+(student+i)->mathScore);
printf("\n按任意键继续……");
getch();
}
void UpdateScore(Student* student)
{
system("cls");
CheckData();
printf("输入修改ID:\n");
int id = 0;
scanf("%d",&id);
int i = 0;
for(;iif(id == (student+i)->id)
break;
if(i == studentNum)
printf("\n查无此人,按任意键继续……");
else
{
printf("输入欲修改的C语言成绩、数学成绩:\n");
int cScore = 0;
int mathScore = 0;
scanf("%d%d",&cScore,&mathScore);
(student+i)->cScore=cScore;
(student+i)->mathScore = mathScore;
printf("\n按任意键继续……");
}
getch();
}
void RunStudent(Student* student)
{
while(1)
{
ShowMainMenu();
char chGet = getch();
switch(chGet)
{
case  '1':
AddStudent(student);
break;
case  '2':
ShowCountScore(student);
break;
case '3':
ShowClassAvg(student);
break;
case '4':
SelectFromID(student);
break;
case  '5':
SortForCount(student);
for(int i =0;iprintf("第%d名:\nID:%d\nC语言成绩为:%d\n数学成绩为:%d\n总分为:%d\n\n",i+1,(student+i)->id,(student+i)->cScore,(student+i)->mathScore,(student+i)->cScore+(student+i)->mathScore);
printf("\n按任意键继续……");
getch();
break;
case '6':
{
int n = 0;
printf("输入N:\n");
scanf("%d",&n);
SortForN(student,n);
}
break;
case '7':
UpdateScore(student);
break;
case '0':
return;
default:
break;
}
}
}
int main()
{
Student* allStudent = (Student*)malloc(MAXSTUDENT*sizeof(Student));
memset((void*)allStudent,0,MAXSTUDENT*sizeof(Student));
RunStudent(allStudent);
return 0;
}

回答2:

学生成绩管理帮实现

回答3:

用链表实现,很简单的啊