英文编程查询(计算机编程为什么都是英文)

2023-12-01 09:47:52 数码极客 bianji01

 

求java用c语言写一个的一个关于学生的名字,学号,成绩等一些的全英文编程

学生成绩管理程序

编制一个统计学生考试分数的管理程序。

设学生成绩已以一个学生一个记录的形式存储在文件中,

每位学生记录包含的信息有:姓名,学号和各门功课的成绩。

程序具有以下几项功能:求出各门课程的总分,平均分,按姓名,

按学号寻找其记录并显示,浏览全部学生成绩和按总分由高到低显示学生信息等。

#include

#defineSWN3/*课程数*/

#defineNAMELEN20/*姓名最大字符数*/

#defineCODELEN10/*学号最大字符数*/

#defineFNAMELEN80/*文件名最大字符数*/

#defineBUFLEN80/*缓冲区最大字符数*/

/*课程名称表*/

charschoolwork[SWN][NAMELEN+1]={"Chinese","Mathematic","English"};

structrecord

charname[NAMELEN+1];/*姓名*/

charcode[CODELEN+1];/*学号*/

intmarks[SWN];/*各课程成绩*/

inttotal;/*总分*/

}stu;

structnode

charname[NAMELEN+1];/*姓名*/

charcode[CODELEN+1];/*学号*/

intmarks[SWN];/*各课程成绩*/

inttotal;/*总分*/

structnode*next;/*后续表元指针*/

}*head;/*链表首指针*/

inttotal[SWN];/*各课程总分*/

FILE*stfpt;/*文件指针*/

charstuf[FNAMELEN];/*文件名*/

/*从指定文件读入一个记录*/

intreadrecord(FILE*fpt,structrecord*rpt)

charbuf[BUFLEN];

inti;

if(fscanf(fpt,"%s",buf)!=1)

return0;/*文件结束*/

strncpy(rpt->name,buf,NAMELEN);

fscanf(fpt,"%s",buf);

strncpy(rpt->code,buf,CODELEN);

for(i=0;i

fscanf(fpt,"%d",&rpt->marks[i]);

for(rpt->total=0,i=0;i

rpt->total+=rpt->marks[i];

return1;

/*对指定文件写入一个记录*/

writerecord(FILE*fpt,structrecord*rpt)

inti;

fprintf(fpt,"%s\n",rpt->name);

fprintf(fpt,"%s\n",rpt->code);

for(i=0;i

fprintf(fpt,"%d\n",rpt->marks[i]);

return;

/*显示学生记录*/

displaystu(structrecord*rpt)

inti;

printf("\nName:%s\n",rpt->name);

printf("Code:%s\n",rpt->code);

printf("Marks:\n");

for(i=0;i

printf("%-15s:%4d\n",schoolwork[i],rpt->marks[i]);

printf("Total:%4d\n",rpt->total);

/*计算各单科总分*/

inttotalmark(char*fname)

FILE*fp;

structrecords;

intcount,i;

if((fp=fopen(fname,"r"))==NULL)

printf("Cantopenfile%s.\n",fname);

return0;

for(i=0;i

total[i]=0;

count=0;

while(readrecord(fp,&s)!=0)

for(i=0;i

total[i]+=s.marks[i];

count++;

fclose(fp);

returncount;/*返回记录数*/

/*列表显示学生信息*/

voidliststu(char*fname)

FILE*fp;

structrecords;

if((fp=fopen(fname,"r"))==NULL)

printf("Cantopenfile%s.\n",fname);

return;

while(readrecord(fp,&s)!=0)

displaystu(&s);

printf("\nPressENTERtocontinue...\n");

while(getchar()!=\n);

fclose(fp);

return;

/*构造链表*/

structnode*makelist(char*fname)

FILE*fp;

structrecords;

structnode*p,*u,*v,*h;

inti;

if((fp=fopen(fname,"r"))==NULL)

printf("Cantopenfile%s.\n",fname);

returnNULL;

h=NULL;

p=(structnode*)malloc(sizeof(structnode));

while(readrecord(fp,(structrecord*)p)!=0)

while(v&&p->total<=v->total)

v=v->next;

if(v==h)

u->next=p;

p->next=v;

p=(structnode*)malloc(sizeof(structnode));

free(p);

fclose(fp);

returnh;

/*顺序显示链表各表元*/

voiddisplaylist(structnode*h)

while(h!=NULL)

displaystu((structrecord*)h);

printf("\nPressENTERtocontinue...\n");

while(getchar()!=\n);

h=h->next;

return;

/*按学生姓名查找学生记录*/

intretrievebyn(char*fname,char*key)

FILE*fp;

intc;

structrecords;

if((fp=fopen(fname,"r"))==NULL)

printf("Cantopenfile%s.\n",fname);

return0;

while(readrecord(fp,&s)!=0)

if(strcmp(s.name,key)==0)

displaystu(&s);

fclose(fp);

if(c==0)

printf("Thestudent%sisnotinthefile%s.\n",key,fname);

return1;

/*按学生学号查找学生记录*/

intretrievebyc(char*fname,char*key)

FILE*fp;

intc;

structrecords;

if((fp=fopen(fname,"r"))==NULL)

printf("Cantopenfile%s.\n",fname);

return0;

while(readrecord(fp,&s)!=0)

if(strcmp(s.code,key)==0)

displaystu(&s);

break;

fclose(fp);

if(c==0)

printf("Thestudent%sisnotinthefile%s.\n",key,fname);

return1;

main()

inti,j,n;

charc;

charbuf[BUFLEN];

FILE*fp;

structrecords;

clrscr();

printf("Pleaseinputthestudentsmarksrecordfilesname:");

scanf("%s",stuf);

if((fp=fopen(stuf,"r"))==NULL)

printf("Thefile%sdoesntexit,doyouwanttocreatit?(Y/N)",stuf);

getchar();

c=getchar();

if(c==Y||c==y)

fp=fopen(stuf,"w");

printf("Pleaseinputtherecordnumberyouwanttowritetothefile:");

scanf("%d",&n);

for(i=0;i

printf("Inputthestudentsname:");

scanf("%s",&s.name);

printf("Inputthestudentscode:");

scanf("%s",&s.code);

for(j=0;j

printf("Inputthe%smark:",schoolwork[j]);

scanf("%d",&s.marks[j]);

writerecord(fp,&s);

fclose(fp);

fclose(fp);

getchar();

/*clrscr();*/

puts("Nowyoucaninputacommandtomanagetherecords.");

puts("m:meanofthemarks.");

puts("t:totalofthemarks.");

puts("n:searchrecordbystudentsname.");

puts("c:searchrecordbystudentscode.");

puts("l:listalltherecords.");

puts("s:sortandlisttherecordsbythetotal.");

puts("q:quit!");

while(1)

puts("Pleaseinputcommand:");

scanf("%c",&c);/*输入选择命令*/

if(c==q||c==Q)

puts("\nThankyouforyourusing.");

break;/*q,结束程序运行*/

switch(c)

casem:/*计算平均分*/

caseM:

if((n=totalmark(stuf))==0)

puts("Error!");

break;

printf("\n");

for(i=0;i

printf("%-15ssaverageis:%.2f.\n",schoolwork[i],(float)total[i]/n);

break;

caset:/*计算总分*/

caseT:

if((n=totalmark(stuf))==0)

puts("Error!");

break;

printf("\n");

for(i=0;i

printf("%-15sstotalmarkis:%d.\n",schoolwork[i],total[i]);

break;

casen:/*按学生的姓名寻找记录*/

caseN:

printf("Pleaseinputthestudentsnameyouwanttosearch:");

scanf("%s",buf);

retrievebyn(stuf,buf);

break;

casec:/*按学生的学号寻找记录*/

caseC:

printf("Pleaseinputthestudentscodeyouwanttosearch:");

scanf("%s",buf);

retrievebyc(stuf,buf);

break;

casel:/*列出所有学生记录*/

caseL:

liststu(stuf);

break;

cases:/*按总分从高到低排列显示*/

caseS:

if((head=makelist(stuf))!=NULL)

displaylist(head);

break;

default:break;

本回答由网友推荐

声明:易趣百科所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系315127732@qq.com
广告位招租
横幅广告