c的管理系统参照.docx
《c的管理系统参照.docx》由会员分享,可在线阅读,更多相关《c的管理系统参照.docx(37页珍藏版)》请在冰点文库上搜索。
![c的管理系统参照.docx](https://file1.bingdoc.com/fileroot1/2023-6/25/5a8dd2c1-ee40-4ed9-b069-804100e06ded/5a8dd2c1-ee40-4ed9-b069-804100e06ded1.gif)
c的管理系统参照
怎样用C语言编这样一个程序:
学生成绩管理系统
功能要求:
1.能按学期,按班级完成对学生成绩的录入,修改
2.能按班级统计学生的成绩,求学生的总分及平均分,并能根据学生的平均成绩进行排序
3.能查询学生成绩,不及格科目及学生名单
4.能按班级输出学生的成绩单
#include
----基本功能实现了,修改一下就可以了,好运!
#include
#include
#include
#defineInputRcd1
#defineUpdateRcd2
#defineSelectRcd3
#defineExit4
#defineNAMELEN16/*姓名长度限制为16个字符*/
#defineCLASSLEN6/*班级编号限制为6个字符*/
structrecord{
charclassID[CLASSLEN];
intterm;
charname[NAMELEN];
intchinese,math,english;
};
/*程序信息*/
voidshowProgInform()
{
printf("-------------------------------------------------\n");
printf("|***STUDENTS'SCOREPLATFORM***|\n");;
printf("-------------------------------------------------\n\n");
}
/*指令菜单*/
voidshowMenu(){
system("cls");
showProgInform();
printf("PleaseselectanoperationfothefollowingMENU:
\n");
printf("1.Inputarecord\n");
printf("2.Updatearecord\n");
printf("3.Selectrecord(s)\n");
printf("4.Exit.\n");
}
voidinputRecord(){
structrecordinscr;
FILE*fp;
/*用户输入相应信息*/
system("cls");
showProgInform();
printf("Mention:
Youaretoaddnewrecord\n\n");
printf("Pleaseinputbythefollowinginstructions:
\n");
printf("ClassID:
");
scanf("%s",inscr.classID);
printf("TermNumber:
");
scanf("%d",&(inscr.term));
printf("StudentName:
");
scanf("%s",inscr.name);
printf("Chinesescore:
");
scanf("%d",&(inscr.chinese));
printf("Mathscore:
");
scanf("%d",&(inscr.math));
printf("EnglishScore:
");
scanf("%d",&(inscr.english));
getchar();
/*将信息写进文件*/
if((fp=(fopen("stu_score.rcd","ab+")))==NULL){
printf("Inputrecordfailed!
\n");
return;
}
/*写一条记录*/
fwrite(&inscr,sizeof(structrecord),1,fp);
fclose(fp);
/*写进记事本文件*/
if((fp=fopen("stu_score.txt","ab+"))==NULL){
return;
}
fprintf(fp,"%s-%d%s:
%d%d%d\r\n",inscr.classID,inscr.term,inscr.name,inscr.chinese,inscr.math,inscr.english);;
fclose(fp);
}
voidshowSingleRecord(structrecordrc){
printf("%s-%d%s:
(CHI)%d(MAT)%d(ENG)%d\n",rc.classID,rc.term,rc.name,rc.chinese,rc.math,rc.english);
}
voidupdateRecord()
{
longfsize,arraySize,i;
structrecord*allRecords,newRcd;/*数组的作用*/
inthasFound=0;
FILE*fp;
FILE*txt;
system("cls");
showProgInform();
/*打开记录文件*/
if((fp=fopen("stu_score.rcd","rb"))==NULL){
printf("!
Norecords,cannotoperate\n");
return;
}
/*输入数据*/
printf("Mention:
Youaretoupdaterecord\n\n");
printf("Pleasetherecordyouwanttoupdatebythefollowmention:
\n");
printf("ClassId:
");
scanf("%s",newRcd.classID);
printf("Termnumber:
");
scanf("%d",&newRcd.term);
printf("Studentname:
");
scanf("%s",newRcd.name);
fseek(fp,0,SEEK_END);
fsize=ftell(fp);
arraySize=fsize/(sizeof(structrecord));
allRecords=(structrecord*)calloc(arraySize,sizeof(structrecord));
rewind(fp);
/*将所有数据读入数组块中*/
fread(allRecords,sizeof(structrecord),arraySize,fp);
/*查找*/
for(i=0;iif(strcmp(newRcd.classID,allRecords[i].classID)==0&&newRcd.term==allRecords[i].term&&strcmp(newRcd.name,allRecords[i].name)==0){
printf("Findthematchingrecord:
");
showSingleRecord(allRecords[i]);
printf("InputnewScore:
\n");
printf("NewChineseScore:
");
scanf("%d",&(allRecords[i].chinese));
printf("NewMathScore:
");
scanf("%d",&(allRecords[i].math));
printf("NewEnglishScore:
");
scanf("%d",&(allRecords[i].english));
printf("Afterupdate,therecordsis:
\n\t");
showSingleRecord(allRecords[i]);
printf("\n");
hasFound=1;
break;
}
}
fclose(fp);
if(!
hasFound){
printf("Nomatchingrecordhasfound!
\n");
/*释放动态空间*/
free(allRecords);
return;
}
/*将修改后的记录回写*/
if((fp=fopen("stu_score.rcd","w"))==NULL){
printf("Writefilestu_score.rcdfailed\n");
return;
}
if((txt=fopen("stu_score.txt","w"))==NULL){
printf("Writefilestu_score.txtfailed\n");
return;
}
fwrite(allRecords,sizeof(structrecord),arraySize,fp);
for(i=0;ifprintf(txt,"%s-%d%s:
%d%d%d\r\n",allRecords[i].classID,allRecords[i].term,allRecords[i].name,allRecords[i].chinese,allRecords[i].math,allRecords[i].english);
}
/*释入动态分配的空间*/
free(allRecords);
/*关闭文件*/
fclose(fp);
fclose(txt);
}
voidshowSelectMenu(charclassID[],intterm){
system("cls");
showProgInform();
printf("Mention:
AllthefollowingopertionbasedonclassID:
%s,Term:
%d\n\n",classID,term);
printf("Mention:
Youaretoselecttherecords\n\n");
printf("\tPleasechooseanoperation:
\n");
printf("\t1.SelectallrecordsoftheclassID.\n");
printf("\t2.Sortbytheaveragescore.\n");
printf("\t3.Selectnopassedrecord.\n");
printf("\tOther.Returnthehighlevelmenu.\n\n");
}
/*显示一班级一学期的所有统计数据*/
voidshowStatistic(structrecord*r,longsize,charclassID[],intterm){
inttotal;
floatave;
longi;
system("cls");
showProgInform();
printf("Allrecordsforclass:
%s,term:
%d;totalrecordnubmer:
%ld\n",classID,term,size);
printf("********************************************************\n");
for(i=0;itotal=r[i].chinese+r[i].english+r[i].math;
ave=(float)total/3;
printf("%s:
(CHI)%d(MAT)%d(ENG)%d(Total)%d(Ave)%.2f\r\n",r[i].name,r[i].chinese,r[i].math,r[i].english,total,ave);
}
printf("********************************************************\n\n");
printf("PressEntertoreturnSelectsubmenu\n");
getchar();
}
/*对某一班级一学期的所有记录按平均分排序*/
voidsortSelectByAve(structrecord*r,longsize){
FILE*fp;
structrecordtemp;
floatouterAve,innerAve;
inttotal;
longi,j;
system("cls");
showProgInform();
printf("\nSortedtherecordsbyaveragescore\n");
for(i=0;iouterAve=(float)(r[i].chinese+r[i].math+r[i].english)/3;
for(j=i+1;jinnerAve=(float)(r[j].chinese+r[j].math+r[j].english)/3;
if(innerAve>outerAve){
/*由于是同一班级同一学期,所以只需修改以下四项*/
strcpy(temp.name,r[j].name);
temp.chinese=r[j].chinese;
temp.math=r[j].math;
temp.english=r[j].english;
strcpy(r[j].name,r[i].name);
r[j].chinese=r[i].chinese;
r[j].math=r[i].math;
r[j].english=r[i].english;
strcpy(r[i].name,temp.name);
r[i].chinese=temp.chinese;
r[i].math=temp.math;
r[i].english=temp.english;
}
}
}
printf("\nshowsortedrecords\n");
printf("********************************************\n");
for(i=0;itotal=r[i].chinese+r[i].math+r[i].english;
innerAve=(float)total/3;
printf("%s:
%d%d%d%d%f\n",r[i].name,r[i].chinese,r[i].math,r[i].english,total,innerAve);
}
printf("********************************************\n");
/*输出排序后结果到文件中*/
printf("writesortedrecordsto\"sorted.txt\"\n");
if((fp=fopen("sorted.txt","w"))==NULL){
printf("opensort.txtfailed\n");
return;
}
for(i=0;itotal=r[i].chinese+r[i].math+r[i].english;
innerAve=(float)total/3;
fprintf(fp,"(CLASS-TERM)%s-%d(NAME)%s:
(CHI)%3d(MAT)%3d(ENG)%3d(TOTAL)%4d(AVERG)%.2f\r\n",r[i].classID,r[i].term,r[i].name,r[i].chinese,r[i].math,r[i].english,total,innerAve);
}
printf("writefilesorted.txtfinished\n");
fclose(fp);
printf("\nPressanykeytoreturnSelectsubMenu\n");
}
voidnoPass(structrecord*r,intsize){
longi=0,j=0;
FILE*fp;
if((fp=fopen("no-pass.txt","w"))==NULL){
printf("createno-pass.txtfailed");
return;
}
system("cls");
showProgInform();
printf("Mention:
ThefollowingoperationwillbeallontheclassIdandtermyouinput\n\n");
printf("\nShowstudentthatonesubjectisno-pass\n");
printf("***********************************************\n");
for(i=0;iif(r[i].chinese<60||r[i].math<60||r[i].english<60){
printf("%s-%d%s:
",r[i].classID,r[i].term,r[i].name);
fprintf(fp,"%s-%d%s:
",r[i].classID,r[i].term,r[i].name);
if(r[i].chinese<60){
printf("(Chinese)%d",r[i].chinese);
fprintf(fp,"(Chinese)%d",r[i].chinese);
}
if(r[i].math<60){
printf("(Math)%d",r[i].math);
fprintf(fp,"(Math)%d",r[i].math);
}
if(r[i].english<60){
printf("(English)%d",r[i].english);
fprintf(fp,"(English)%d",r[i].english);
}
printf("\r\n");
fprintf(fp,"\r\n");
}
}
printf("***********************************************\n");
fclose(fp);
printf("PressEntertoreturn\"Select\"submenu\n");
}
/*查询记录*/
voidselectRecord(){
charclassID[CLASSLEN];
intterm;
FILE*fp;
longfsize=0,arraySize=0,thisSize=0,i=0,j=0;
structrecord*allRcd,*thisClass;
system("cls");
showProgInform();
printf("Mention:
ThefollowingoperationwillbeallontheclassIdandtermyouinput\n\n");
printf("Mention:
pleaseoperatebythefollowinginstructions\n\n");
printf("InputClassID:
");
scanf("%s",classID);
printf("Inputtermnumber:
");
scanf("%d",&term);
/*选出班级学期对应的数据暂存起来*/
if((fp=fopen("stu_score.rcd","r"))==NULL){
printf("\nWarining:
Norecordexists!
\n");
return;
}
fseek(fp,0,SEEK_END);
fsize=ftell(fp);
arraySize=fsize/(sizeof(structrecord));
allRcd=(structrecord*)calloc(arraySize,sizeof(structrecord));
rewind(fp);
fread(allRcd,sizeof(structrecord),arraySize,fp);
printf("PressEntertoshowthesubmenuofSelectmenu\n");
for(i=0;iif(strcmp(classID,allRcd[i].classID)==0&&term==allRcd[i].term){
thisSize++;
}
}
if(thisSize==0){
printf("\nWaring:
NorecordforClass%sTerm%d\n",classID,term);
fclose(fp);
free(allRcd);
return;
}
/*本班的数据空间,用于后在面的计算,排序,显示等功能*/
thisClass=(structrecord*)calloc(thisSize,sizeof(structrecord));
j=0;
for(i=0;iif(strcmp(classID,allRcd[i].classID)==0&&term==allRcd[i].term){
strcpy(thisClass[j].classID,classID);
thisClass[j].term=term;
strcpy(thisClass[j].name,allRcd[i].name);
thisClass[j].chinese=allRcd[i].chinese;
thisClass[j].ma