c的管理系统参照.docx

上传人:b****1 文档编号:14621738 上传时间:2023-06-25 格式:DOCX 页数:37 大小:24.11KB
下载 相关 举报
c的管理系统参照.docx_第1页
第1页 / 共37页
c的管理系统参照.docx_第2页
第2页 / 共37页
c的管理系统参照.docx_第3页
第3页 / 共37页
c的管理系统参照.docx_第4页
第4页 / 共37页
c的管理系统参照.docx_第5页
第5页 / 共37页
c的管理系统参照.docx_第6页
第6页 / 共37页
c的管理系统参照.docx_第7页
第7页 / 共37页
c的管理系统参照.docx_第8页
第8页 / 共37页
c的管理系统参照.docx_第9页
第9页 / 共37页
c的管理系统参照.docx_第10页
第10页 / 共37页
c的管理系统参照.docx_第11页
第11页 / 共37页
c的管理系统参照.docx_第12页
第12页 / 共37页
c的管理系统参照.docx_第13页
第13页 / 共37页
c的管理系统参照.docx_第14页
第14页 / 共37页
c的管理系统参照.docx_第15页
第15页 / 共37页
c的管理系统参照.docx_第16页
第16页 / 共37页
c的管理系统参照.docx_第17页
第17页 / 共37页
c的管理系统参照.docx_第18页
第18页 / 共37页
c的管理系统参照.docx_第19页
第19页 / 共37页
c的管理系统参照.docx_第20页
第20页 / 共37页
亲,该文档总共37页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

c的管理系统参照.docx

《c的管理系统参照.docx》由会员分享,可在线阅读,更多相关《c的管理系统参照.docx(37页珍藏版)》请在冰点文库上搜索。

c的管理系统参照.docx

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;i

if(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;i

fprintf(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;i

total=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;i

outerAve=(float)(r[i].chinese+r[i].math+r[i].english)/3;

for(j=i+1;j

innerAve=(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;i

total=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;i

total=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;i

if(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;i

if(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;i

if(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

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2