c语言程序设计:学生成绩管理系统

2024-11-24 16:17:47
推荐回答(2个)
回答1:


include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;

void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("Cannot reading this file.\n");
exit(0);
}
for(i=0;i<=1000;i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;j {
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}

void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];

} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}

fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{

printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为黄色*/
textbackground(BLUE); /*设置背景颜色为蓝色*/
window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr();
printf("*************welcome to use student manage******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>shuru 2>xiugai * \n");
printf("* 3>shanchu 4>chazhao * \n");
printf("* 5>xianshi 6>exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
}
}
}
在tc中运行

回答2:

这是我的课设,学生成绩管理,希望对你有用!
#include
#include
#include
#include
#define M 3
/*定义结构体变量*/
typedef struct students
{ char name[20];
char num[15];
float score[M];
float average;
float total;
}MESSA;
MESSA stu[20];int S;
/*函数声明*/
void menu(void);
void choose(void);
void input(void);
void savescore(void);
void loadscore(void);
void choosec(void);
void average(void);
void total(void);
void name(void);
void number(void);
void show(void);
void excellent(void);
void passing(void);
void personal(void);
void Exit();
/*主函数调用*/
void main()
{ menu();
choose();
}

/*菜单系统*/
void menu(void)
{
system("CLS");
printf("\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
printf("\t^* *^\n");
printf("\t^* WELCOM TO USE THE STUDENT'S RESULT SEARCH SYSTERM *^\n");
printf("\t^* *^\n");
printf("\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
printf("\n");
printf("\tThe menu is following:\n\n");
printf("\t#########################################################\n");
printf("\t# Input the students' scores...........1 #\n");
printf("\t# Search the students' scores..........2 #\n");
printf("\t# Search the students' excellent rate..3 #\n");
printf("\t# Search the students' passing rate....4 #\n");
printf("\t# Search personal student's score......5 #\n");
printf("\t# Exit.................................6 #\n");
printf("\t#########################################################\n");
printf("\n\tPlease choose:\n");
}
/*菜单选择*/
void choose(void)
{
int x,flag=0;
while(flag==0)
{
fflush(stdin);
scanf("%d",&x);
getchar();
switch(x)
{ case 1:input();savescore();loadscore();menu();choose();flag=1;break;
case 2:choosec();flag=1;break;
case 3:excellent();flag=1;break;
case 4:passing();flag=1;break;
case 5:personal();flag=1;break;
case 6:Exit();flag=1;
default:printf("\tSorry,your choose doesn't exist! please choose again!\n");
}
}
}
/*输入学生成绩*/
void input(void)
{
int flag=1,j,i;char k;float pp=0;
for(i=0;flag==1;i++)
{
printf("\tInput the N.%hd student's information:\n",i+1);
puts("Name:");
fflush(stdin);
gets(stu[i].name);
fflush(stdin);
puts("Num:");
fflush(stdin);
gets(stu[i].num);
puts("\tScore:\tMath\tEnglish\tProgramm");
for(j=0;j scanf("%f",&stu[i].score[j]);
puts("\tDo you want to continue?(Y/N)");
while(1)
{ puts("\tplease choose.......");
fflush(stdin);
scanf("%c",&k);
if(k!='N'&&k!='Y')
puts("\tError,please try again!");
else if(k=='N')
{
flag=0;S=i;break;
}
else break;
}
}
for(i=0;i<=S;i++)
{
for(j=0,stu[i].total=0.0;j stu[i].total+=stu[i].score[j];
stu[i].average=stu[i].total/M;
}
}
/*保存数据*/

void savescore(void)
{
int i,flag=1;FILE *fp;char m;
puts("\tDo you want to save thease scores?(Y/N)");
while(1)
{
fflush(stdin);
scanf("%c",&m);
if(m=='Y')
{
if((fp=fopen("D:\\score.txt","w"))==NULL)
{
printf("\tSorry,can't open the file....\n");
exit(0);
}
for(i=0;i<=S;i++)
if(fwrite(&stu[i],sizeof(struct students),1,fp)!=1)
{
puts("\tSorry,file write in a wrong way!");
flag=0;
}

if(flag==1)
for(i=0;i<=S;i++)
printf("\tOk,the N.%d student's score have been saved.....\n",i+1);
fclose(fp);
break;
}
else if(m!='N'&&m!='Y')
puts("\tSorry,your choose is wrong,please choose again!");
else
break;
}

}
/*读取文件中保存的数据*/
void loadscore(void)
{
FILE *fp;char n;MESSA restu[20];int i,j,flag=0;
char read[5][10]={"Num","Name","Math","English","Programm"};
puts("\tDo you want to load the savescores just now?(Y/N)");
while(1)
{
fflush(stdin);
scanf("%c",&n);
if(n=='Y')
{
if((fp=fopen("D:\\score.txt","r"))==NULL)
{
fprintf(stderr,"\tOpen %s error!!!\n","score.txt");
exit(0);
}
for(i=0;i<=S;i++)
fread(&restu[i],sizeof(struct students),1,fp);
system("CLS");
puts("\tLoading the information.................");
printf("\tOk,file has been loaded!...........\n");
printf("\n");
printf("\t$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$\n");
printf("\t$**$ $**$\n\t");
printf("$**$ ");
for(i=0;i<5;i++)
printf("%-10s",read[i]);
printf(" $**$");
printf("\n");
for(i=0;i<=S;i++)
{ printf("\t$**$ ");
printf("%-10s%-10s",restu[i].num,restu[i].name);
for(j=0;j<3;j++)
printf("%-10.2f",restu[i].score[j]);
printf(" $**$\n");
}
printf("\t$**$ $**$");
printf("\n\t$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$\n");
fclose(fp);
break;
}
else if(n=='N')
break;
else
printf("\tSorry,the character you input is wrong,try again!\n");
}
puts("\tpress any key to return to the main menu..............\n");
getchar();
getchar();
}
/*选择查分的子菜单及子菜单选择*/
void choosec(void)
{
int biao,i,flag=0;FILE *fp;

if((fp=fopen("D:\\score.txt","r"))==NULL)
{
printf("\tSorry,you haven't input any information! Can't find the file!\n\n\n");
printf("\tPress any key to back to the main menu!!\n");
getchar();
getchar();
menu();
choose();
}
for(i=0;i<=S;i++)
fread(&stu[i],sizeof(struct students),1,fp);
fclose(fp);
system("CLS");
printf("\tThe following is second menu:\n");
printf("\n");
printf("\t%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$\n");
printf("\t%%$ search by the average from higher to lower....1 %%$\n");
printf("\t%%$ Search by the total from higher to lower......2 %%$\n");
printf("\t%%$ Search by the number from higher to lower.....3 %%$\n");
printf("\t%%$ Search by the name from higher to lower.......4 %%$\n");
printf("\t%%$ Back to the main menu.........................5 %%$\n");
printf("\t%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$%%$\n");
printf("\n\tPlease choose the way to search:\n");
while(flag==0)
{
fflush(stdin);
scanf("%d",&biao);
getchar();
switch(biao)
{ case 1:flag=1;average();show();break;
case 2:flag=1;total();show();break;
case 3:flag=1;number();show();break;
case 4:flag=1;name();show();break;
case 5:flag=1;menu();choose();break;
default:printf("\tSorry,your choose doesn't exist! please choose again!\n");
}
}
}
/*显示分数*/
void show(void)
{
int i,j,n,flag=0;
char head[7][10]={"Num","Name","Math","English","Programm","Total","Average"};
system("CLS");
puts("\tLoading the information.................");
printf("\n");
printf("\t$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$\n\n\t");
for(i=0;i<7;i++)
printf("%-10s",head[i]);
printf("\n\t");
for(i=0;i<=S;i++)
{
printf("%-10s%-10s",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%-10.2f",stu[i].score[j]);
printf("%-10.2f",stu[i].total);
printf("%-10.2f",stu[i].average);
printf("\n\t");
}
printf("\n\t$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$**$\n");
printf("\nYou want :(1 or 2)\n");
puts("\t1.back to the second menu!\n");
puts("\t2.back to the main menu!\n");
while(flag==0)
{
fflush(stdin);
scanf("%d",&n);
getchar();
switch(n)
{ case 1:flag=1;choosec();break;
case 2:flag=1;menu();choose();break;
default:printf("\tError!Please choose again!\n");
}
}
}
/*按平均分由高到低*/
void average(void)
{
int i,j,k;MESSA t;
for(i=0;i {
k=i;
for(j=i+1;j<=S;j++)
if(stu[k].average k=j;
if(k!=i)
{
t=stu[k];
stu[k]=stu[i];
stu[i]=t;
}
}
}
/*按总分由高到低*/
void total(void)
{
int i,j,k;MESSA t;
for(i=0;i {
k=i;
for(j=i+1;j<=S;j++)
if(stu[k].total k=j;
if(k!=i)
{
t=stu[k];
stu[k]=stu[i];
stu[i]=t;
}
}
}
/*按学号降序*/
void number(void)
{
int i,j,k;MESSA t;
for(i=0;i {
k=i;
for(j=i+1;j<=S;j++)
if(strcmp(stu[k].num,stu[j].num)<0)
k=j;
if(k!=i)
{
t=stu[k];
stu[k]=stu[i];
stu[i]=t;
}
}
}
/*按姓名降序*/
void name(void)
{
int i,j,k;MESSA t;
for(i=0;i {
k=i;
for(j=i+1;j<=S;j++)
if(strcmp(stu[k].name,stu[j].name)<0)
k=j;
if(k!=i)
{
t=stu[k];
stu[k]=stu[i];
stu[i]=t;
}
}
}
/*优秀率*/
void excellent(void)
{
int i,j,k,w,flag=0;float m;FILE *fp;
char head2[3][10]={"Math","English","Programm"};
if((fp=fopen("D:\\score.txt","r"))==NULL)
{
printf("\tSorry,you haven't input any information! Can't find the file!\n\n\n");
printf("\tPress any key to back to the main menu!!\n");
getchar();
getchar();
menu();
choose();
}
for(i=0;i<=S;i++)
fread(&stu[i],sizeof(struct students),1,fp);
fclose(fp);
system("CLS");
for(i=0;i {
printf("\tThe excellent students in %s is following:\n",head2[i]);
for(j=0,k=0;j<=S;j++)
if(stu[j].score[i]>=85.00)
{ k++;
printf("\t%s\t%s",stu[j].num,stu[j].name);
printf("\t%.2f\n",stu[j].score[i]);
}
m=(k*1.0/(S+1))*100;
printf("\tThe excellent rate is %.2f%%\n",m);
}
printf("\n\n");
puts("\tWhat do you want to do next?\n");
printf("\t1.Exit the systerm!\n");
printf("\t2.Back to the main menu!\n");
printf("\t3.back to the second menu!\n");
puts("\tPlease choose:\n");
while(flag==0)
{
fflush(stdin);
scanf("%d",&w);
getchar();
switch(w)
{ case 1:Exit();flag=1;
case 2:menu();choose();flag=1;break;
case 3:choosec();flag=1;break;
default:printf("\tSorry,your choose doesn't exist! please choose again!\n");
}
}
}
/*及格率*/
void passing(void)
{

int i,j,k,w,flag=0;float m;FILE *fp;
char head2[3][10]={"Math","English","Programm"};
if((fp=fopen("D:\\score.txt","r"))==NULL)
{
printf("\tSorry,you haven't input any information! Can't find the file!\n\n\n");
printf("\tPress any key to back to the main menu!!\n");
getchar();
getchar();
menu();
choose();
}
for(i=0;i<=S;i++)
fread(&stu[i],sizeof(struct students),1,fp);
fclose(fp);
system("CLS");
for(i=0;i {
printf("\tThe passing students in %s is following:\n",head2[i]);
for(j=0,k=0;j<=S;j++)
if(stu[j].score[i]>=60.0)
{ k++;
printf("\t%s\t%s",stu[j].num,stu[j].name);
printf("\t%.2f\n",stu[j].score[i]);
}
m=(k*1.0/(S+1))*100;
printf("\tThe passing rate is %.2f%%\n",m);
}
printf("\n\n");
puts("\tWhat do you want to do next?\n");
printf("\t1.Exit the systerm!\n");
printf("\t2.Back to the main menu!\n");
printf("\t3.back to the second menu!\n");
puts("\tPlease choose:\n");
while(flag==0)
{
fflush(stdin);
scanf("%d",&w);
getchar();
switch(w)
{ case 1:Exit();flag=1;
case 2:menu();choose();flag=1;break;
case 3:choosec();flag=1;break;
default:printf("\tSorry,your choose doesn't exist! please choose again!\n");
}
}
}
/*个人学生成绩查询*/
void personal(void)
{
int i,j,f,w,flag=0;char b[10],a;FILE *fp;
char head3[7][10]={"Num","Name","Math","English","Programm","Total","Average"};
if((fp=fopen("D:\\score.txt","r"))==NULL)
{
printf("\tSorry,you haven't input any information! Can't find the file!\n\n\n");
printf("\tPress any key to back to the main menu!!\n");
getchar();
getchar();
menu();
choose();
}
for(i=0;i<=S;i++)
fread(&stu[i],sizeof(struct students),1,fp);
fclose(fp);
puts("\tPlease input the student you want to search:\n");
puts("\tThe name is following.........\n");
for(i=0;i<=S;i++)
printf("\t%s",stu[i].name);
puts("\t\nYour choose is :\n");
while(1)
{
fflush(stdin);
gets(b);
for(i=0;i<=S;i++)
if(strcmp(b,stu[i].name)==0)
{
printf("\tThe name you choose is %s?(Y/N)\n",stu[i].name);
f=i;
}
fflush(stdin);
scanf("%c",&a);
if(a=='Y')
{
system("CLS");
puts("\tLoading the information.................");
printf("\n");
printf("\t**************************************************************\n\n\t");
for(i=0;i<7;i++)
printf("%-10s",head3[i]);
printf("\n\t");
printf("%-10s%-10s",stu[f].num,stu[f].name);
for(j=0;j<3;j++)
printf("%-10.2f",stu[f].score[j]);
printf("%-10.2f",stu[f].total);
printf("%-10.2f",stu[f].average);
printf("\n");
printf("\t**************************************************************\n");
break;
}
else
printf("\tError!please choose again!\n");
}
puts("\tWhat do you want to do next?\n");
printf("\t1.Exit the systerm!\n");
printf("\t2.Back to the main menu!\n");
printf("\t3.back to the second menu!\n");
puts("\tPlease choose:\n");
while(flag==0)
{
fflush(stdin);
scanf("%d",&w);
getchar();
switch(w)
{ case 1:Exit();flag=1;
case 2:menu();choose();flag=1;break;
case 3:choosec();flag=1;break;
default:printf("\tSorry,your choose doesn't exist! please choose again!\n");
}
}
}
/*退出系统*/
void Exit(void)
{
system("CLS");
printf("\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
printf("\t^* *^\n");
printf("\t^* THANKS FOR USING THE STUDENT'S RESULT SEARCH SYSTERM *^\n");
printf("\t^* *^\n");
printf("\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
exit(0);
}