c语言课程设计之学生成绩管理系统设计的程序

2024-11-28 12:32:43
推荐回答(4个)
回答(1):

#include
#include
#include
#include

#define MAX 80
#define max 3

int nu=0;

struct classname
{
char name[20];
float score;
};

struct student
{
char no[20];
char std_name[20];
struct classname km[max];
float ave;
float sum;
int save;
};

struct student stu[MAX],*p;

void chushi()
{
int i,j;
for(i=0;i {
for(j=0;j<20;j++)
{
stu[i].no[j]=NULL;
stu[i].std_name[j]=NULL;
stu[i].km[j].name[j]=NULL;
stu[i].km[j].score=0;
}
stu[i].ave=0;
stu[i].sum=0;
stu[i].save=0;
}
}

void av()/*求平均值*/
{
int i;
for(i=0;i {
stu[i].sum=stu[i].km[1].score+stu[i].km[2].score+stu[i].km[3].score;
stu[i].ave=stu[i].sum/3;
}
}

void first_check()
{
FILE *p;
int i,j;
struct classname frist[max];
for(i=0;i {
for(j=0;j<20;j++)
frist[i].name[j]=NULL;
frist[i].score=0;
}
if ((p=fopen("c:\\kemu.txt","r"))==NULL)
{
printf("您好,欢迎使用学生成绩管理系统\n\n因为您是第一次使用,请输入科目名称(三科)\n\n");
p=fopen("c:\\kemu.txt","w");
printf("输入课程1名称:");
scanf("%s",frist[0].name);
fprintf(p,"%s\n",frist[0].name);
printf("输入课程2名称:");
scanf("%s",frist[1].name);
fprintf(p,"%s\n",frist[1].name);
printf("输入课程3名称:");
scanf("%s",frist[2].name);
fprintf(p,"%s\n",frist[2].name);
}
system("cls");
fclose(p);
}

void save_nu()
{
FILE *p;
p=fopen("c:\\renshu.txt","w");
fprintf(p,"%d\n",nu);
fclose(p);
}

void Save_add(int n)
{
FILE * p;
int i;
p= fopen("c:\\cheji.txt","at");
if (p == NULL)
{
printf("文件不存在!!\n");
exit(0);
}
save_nu();
for (i = 0;i if(stu[i].save==1)
{
stu[i].sum=stu[i].km[1].score+stu[i].km[2].score+stu[i].km[3].score;
stu[i].ave=stu[i].sum/3;
fprintf(p,"%s %s %2.1f %2.1f %2.1f %2.1f %2.1f \n",stu[i].no,stu[i].std_name,stu[i].km[0].score,stu[i].km[1].score,stu[i].km[2].score,stu[i].ave,stu[i].sum);
}
fclose(p);
}

void Save()
{
FILE * p;
int i;
p= fopen("c:\\cheji.txt","w");
if (p == NULL)
{
printf("文件不存在!!\n");
exit(0);
}
save_nu();
for (i = 0;i if(stu[i].save==1)
{
av();
fprintf(p,"%s %s %2.1f %2.1f %2.1f %2.1f %2.1f \n",stu[i].no,stu[i].std_name,stu[i].km[0].score,stu[i].km[1].score,stu[i].km[2].score,stu[i].ave,stu[i].sum);
}
fclose(p);
}

int read_nu()
{
FILE *p;
char ch,s[10]={'\0'};
int i=0;
p=fopen("c:\\renshu.txt","r");
if(p==NULL)
{
save_nu();
return 0;
}
ch=fgetc(p);
while(ch!='\n')
{
s[i]=ch;
ch=fgetc(p);
i++;
}
nu=atoi(s);
fclose(p);
return 0;
}

int read_km()
{
FILE *p;
int i,j=0;
char s[20]={'\0'};
chushi();
p=fopen("c:\\kemu.txt","r");
if(p==NULL)
{
printf("ERROR read_km");
return 0;
}
fgets(s,20,p);
while(strlen(s)!=0)
{
for(i=0;i if(s[i]==10)
{
s[i]='\0';
break;
}
for(i=0;i<=nu;i++)
strcpy(stu[i].km[j].name,s);
for(i=0;i<20;i++)
s[i]='\0';
j++;
fgets(s,20,p);
}
}

void read()
{
FILE *p;
int i,j,n,k,z=0;
char s[50]={'\0'};
char o[10]={'\0'};
p=fopen("c:\\cheji.txt","r");
if(p==NULL)
printf("ERROR_read");
chushi();
read_km();
fgets(s,50,p);
while(strlen(s)!=0)
{
j=0;
for(i=0;i<50;i++)
{
if(s[i]!='\n')
{
n=0;
while(j==0)
{
if(s[i]!=' ')
{
stu[z].no[n]=s[i];
n++;i++;
}
else
break;
}
while(j==1)
{
if(s[i]!=' ')
{
stu[z].std_name[n]=s[i];
n++;i++;
}
else
break;
}
while(j==2)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[0].score=atoi(o);
break;
}
}
while(j==3)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[1].score=atoi(o);
break;
}
}
while(j==4)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[2].score=atoi(o);
break;
}
}
while(j==5)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].ave=atoi(o);
break;
}
}
while(j==6)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].sum=atoi(o);
break;
}
}
for(k=0;k<10;k++)
o[k]='\0';
}
else
break;
j++;
}
for(i=0;i<50;i++)
s[i]='\0';
fgets(s,50,p);
z++;
}
}

void putin()
{
int n,i=0;
char ch;
read_km();
do
{
printf("\t\t\t\t录入学员信息\n输入第%d个学员的信息\n",i+1);
printf("\n输入学生编号:");
scanf("%s",stu[i].no);
printf("\n输入学员姓名:");
scanf("%s",stu[i].std_name);
printf("\n输入课程%s的分数:",stu[0].km[0].name);
scanf("%f",&stu[i].km[0].score);
printf("\n输入课程%s的分数:",stu[0].km[1].name);
scanf("%f",&stu[i].km[1].score);
printf("\n输入课程%s的分数:",stu[0].km[2].name);
scanf("%f",&stu[i].km[2].score);
stu[i].save=1;
printf("\n\n");
i++;
n=i;
printf("是否继续输入?(Y/N)");
fflush(stdin);
ch=getch();
system("cls");
}
while(ch!='n'&&ch!='N');
system("cls");
if(nu==0)
{
nu=n;
Save();
}
else
{
nu=n+nu;
Save_add(n);
}
}

int putout()
{
int i;char s;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
read();
do
{
printf("学生成绩信息:\n\n");
for(i=0;i printf("学号:%s 姓名:%s\n%s分数:%2.1f\t%s分数:%2.1f\t%s分数:%2.1f\n平均分数:%2.1f\t总成绩:%2.1f\n\n",stu[i].no,stu[i].std_name,stu[i].km[0].name,stu[i].km[0].score,stu[i].km[1].name,stu[i].km[1].score,stu[i].km[2].name,stu[i].km[2].score,stu[i].ave,stu[i].sum);
printf("\t\t按任意键返回主菜单");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
}

int sort()/*排序数据函数*/
{
struct student temp;
int i,j;
char s;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
chushi();
read();
for(i=1;i {
for(j=1;j<=nu-i;j++)
{
if(stu[j-1].ave {
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
}
}
}
do
{
printf("学生成绩信息:\n\n");
for(i=0;i printf("学号:%s 姓名:%s 平均成绩:%2.1f\n\n",stu[i].no,stu[i].std_name,stu[i].ave);
printf("\t\t按任意键返回主菜单");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
}

void find()/*查询函数*/
{
int j,i=0;
int c=0;
char search[10]={'\0'};
char as;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
chushi();
read();
do
{
printf("输入要查询课程名称:");
scanf("%s",search);
for(j=0;j if(!strcmp(stu[i].km[j].name,search))
{
c=1;
printf("\n该课程不及格学生姓名:\n");
for(i=0;i if(stu[i].km[j].score<60)
printf("%s\n",stu[i].std_name);
}
if(c==0)
printf("无此课程!");
printf("\n\t\t按任意键返回主菜单");
fflush(stdin);
as=getch();
}
while(!as);
system("cls");
}

void tongji()
{
int j,m,z,i=0;
char s;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
chushi();
read();
for(z=0;z {
m=stu[i].km[z].score;j=0;
printf("%s 最高分: ",stu[i].km[z].name);
for(i=0;i if(m {
m=stu[i].km[z].score;
j=i;
}
printf("%s\t",stu[j].std_name);
j=0;i=0;m=stu[i].km[z].score;
printf("%s 最低分: ",stu[i].km[z].name);
for(i=0;i if(m>stu[i].km[z].score)
{
m=stu[i].km[z].score;
j=i;
}
printf("%s\t",stu[j].std_name);
m=0;j=0;i=0;
printf("%s 平均分: ",stu[i].km[z].name);
for(i=0;i m=m+stu[i].km[z].score;
printf("%d\n",m/nu);
m=0;i=0;
printf("%s 分数低于的60人数: ",stu[i].km[z].name);
for(i=0;i if(stu[i].km[z].score<60)
m++;
printf("%d\t",m);
m=0;j=0;i=0;
printf("%s 分数高于60的人数: ",stu[i].km[z].name);
for(i=0;i if(stu[i].km[z].score>60)
m++;
printf("%d\n\n",m);
}
do
{
printf("\t\t按任意键返回主菜单");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
}

void main()/*主函数*/
{
int as;
first_check();
start: printf("\n\t\t\t欢迎使用学生成绩管理系统\n");
/*一下为功能选择模块*/
do
{
printf("\n\t\t\t\t1.录入学员信息\n\t\t\t\t2.显示学员信息\n\t\t\t\t3.成绩排序信息\n\t\t\t\t4.查询不及格学生\n\t\t\t\t5.统计信息\n\t\t\t\t6.退出\n");
printf("\t\t\t\t选择功能选项:");
fflush(stdin);
read_nu();
scanf("%d",&as);
switch(as)
{
case 1:system("cls");putin();break;
case 2:system("cls");putout();break;
case 3:system("cls");sort();break;
case 4:system("cls");find();break;
case 5:system("cls");tongji();break;
case 6:system("exit");exit(0);
default:system("cls");goto start;
}
}
while(1);
/*至此功能选择结束*/
}

回答(2):

#include
#include
#include
#include

#define STU_NUM 40 /*最多的学生人数*/
#define COURSE_NUM 10 /*最多的考试科目*/

struct student
{
int number; /*每个学生的学号*/
char name[10]; /*每个学生的姓名*/
int score[COURSE_NUM]; /*每个学生M门功课的成绩*/
int sum; /*每个学生的总成绩*/
float average; /*每个学生的平均成绩*/
};
typedef struct student STU;

/*----------增加学生成绩模块-----------*/

int AppendScore(STU *head,int n,int m)
{
int j;
STU *p;
char ch;
for (p=head+n ; p {
printf("\nInput number:");
scanf("%d",&p->number);
printf("Input name:");
scanf("%s",p->name);
for (j=0 ; j {
printf("Input score%d:",j+1);
scanf("%d",p->score+j);
}
n++;
printf("Do you want to append a new node(Y/N)?");
scanf("%c",&ch);
if(ch == 'n' || ch == 'N')
return n;
}
}

/*----------------显示学生成绩模块------------------*/

void PrintScore(STU *head,int n,int m)
{
STU *p;
int i;
char str[100]={'\0'},temp[3];

strcat(str," Number Name");
for (i=1;i {
strcat(str,"Score");
itoa(i,temp,10);
strcat(str,temp);
strcat(str," ");
}
strcat(str," sum average");

printf("%s",str); /*打印表头*/
for (p=head;p {
printf("\nNo.%3d%8s",p->number,p->name);
for (i=0;i {
printf("%7d",p->score[i]);
}
printf("%11d%9.2f\n",p->sum,p->average);
}
}

/*---------------计算总成绩和平均成绩模块---------------------*/

void TotalScore(STU *head,int n,int m)
{
STU *p;
int i;

for(p=head;p {
p->sum=0;
for(i=0;i {
p->sum = p->sum + p->score[i];
}
p->average = (float)p->sum/m;
}
}

/*-----------------排序模块---------------------*/

void SortScore(STU *head,int n)
{
int i,j,k;
STU temp;

for (i=0;i {
k=i;
for (j=i;j {
if ((head+j)->sum > (head+k)->sum)
{
k=j;
}
}
if (k!=i)
{
temp=*(head+k);
*(head+k)=*(head+i);
*(head+i)=temp;
}
}
}

/*---------------------查找学生的学号模块------------------------*/

int SearchNum(STU *head,int num,int n)
{
int i;

for (i=0;i {
if((head+i)->number == num)
return i;
}
return -1;
}

/*------------------查找学生成绩并显示查找结果---------------------*/

void SearchScore(STU *head,int n,int m)
{
int number,findNo;

printf("Please Input the number you want to search:");
scanf("%d",&number);
findNo=SearchNum(head,number,n);
if(findNo == -1)
{
printf("\nNot found!\n");
}
else
{
PrintScore(head+findNo,1,m);
}
}

/*-----------------删除记录模块-------------------*/

int DeleteScore(STU *head,int n,int m)
{
int i,num;

STU *p;

printf("Please input the number to Delete:");
scanf("%d",&num);

i=SearchNum(head,num,n);

if(i==-1)
{
printf("Number not found\n");
return n;
}
for(p=head+i;p<=head+n;p++)
{
memcpy(p,p+1,sizeof(struct student));
memset(p+1,0,sizeof(struct student));
}
n--;

return n;
}

/*-------------------文件保存模块-------------------------*/

void SaveScoreFile(STU *head,const int n,const int m)
{
FILE *fp;
int i;
STU *p=head;
if((fp=fopen("record","wb"))==NULL)
{
printf("can not open file\n");
exit(1);
}
printf("\nSaving file\n");
fwrite(&n,sizeof(int),1,fp);
fwrite(&m,sizeof(int),1,fp);
for (i=0;i {
fwrite(head+i,sizeof(struct student),1,fp);
}
fclose(fp);
return;
}

/*---------------------菜单模块--------------------*/

char Menu(void)
{
char ch;
printf("#================================================#\n");
printf("# >>>>>> 学生成绩管理系统 <<<<<< #\n");
printf("#================================================#\n");
printf("# 1.增加成绩 #\n");
printf("# 2.显示成绩 #\n");
printf("# 3.删除成绩 #\n");
printf("# 4.修改成绩 #\n");
printf("# 5.查询成绩 #\n");
printf("# 6.学生排序 #\n");
printf("# 7.保存文件 #\n");
printf("# 0.退出系统 #\n");
printf("#================================================#\n");
printf("请输入0-8选择菜单项:");
scanf(" %c",&ch);
return ch;
}

/*-------------------------修改模块-----------------------*/
void ModifyScore(STU *head,int n,int m)
{
int i,j,num;
STU *p;

printf("Please input the number to modify:\n");
scanf("%d",&num);

i=SearchNum(head,num,m);

if(i==-1)
{
printf("Number not found!\n");
return;
}

p=head+i;
printf("Number:%d\n",p->number);
printf("Input name:");
scanf("%s",p->name);
for(j=0;j {
printf("Input score%d:",j+1);
scanf("%d",p->score+j);
}
TotalScore(head,n,m);
}

/*-------------------主函数模块-----------------------*/

void main()
{
char ch;
int m=3,n=0;
STU stu[STU_NUM];

while (1)
{
ch=Menu(); /*显示菜单,并读取用户信息*/
switch (ch)
{
case '1':n=AppendScore(stu,n,m); /*调用成绩添加模块*/
TotalScore(stu,n,m);
break;
case '2':PrintScore(stu,n,m); /*调用成绩显示模块*/
break;
case '3':n=DeleteScore(stu,n,m); /*调用成绩删除模块*/
PrintScore(stu,n,m);
break;
case '4':ModifyScore(stu,n,m); /*调用成绩修改模块*/
PrintScore(stu,n,m);
break;
case '5':SearchScore(stu,n,m); /*调用按学号查找模块*/
break;
case '6':SortScore(stu,n); /*调用成绩排序模块*/
printf("\nSorted result\n");
PrintScore(stu,n,m);
break;
case '7':SaveScoreFile(stu,n,m); /*保存文件*/
break;
case '0':exit(0);
printf("End of program!"); /*退出程序*/
break;
default:printf("Input error!");
break;
}
}
}

回答(3):

比较麻烦哟、、这个没有几天搞不出来呀、、上次搞一个atm模拟系统搞了三天、、特别是有界面的,函数调用比较麻烦,而且考虑的情况也很多、、后天迟不迟?、、不过我建议你自己尝试吧、、真的,如果你不尝试着自己做出来,以后你遇到这些都不懂的,但是如果这个系统你能做出来,你遇到其他要求有界面的都会一理通百理明、、我的atm模拟系统、、

回答(4):

(5)将参考模板的程序调试运行通过,并补充完整,实现完整的学生成绩管理系统C语言课程设计任务书 一、题目: 学生成绩管理 二、目的与要求 1. 目的: