学生成绩管理系统C++程序设计_第1页
学生成绩管理系统C++程序设计_第2页
学生成绩管理系统C++程序设计_第3页
学生成绩管理系统C++程序设计_第4页
学生成绩管理系统C++程序设计_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

工程设计题目〔学生成绩管理系统〕学号:姓名:自评成绩:成绩:1.选题意义、依据学生成绩系统的设计从学生的应用中而来,学生了解该系统的组成和运行过程,它贴近学生的生活能使学生更加方便的使用各个语句、函数、结构体等。依据学生期末成绩表的格式。2.系统功能设计与分析〔功能模块说明〕系统主要用于从一个文件夹读入学生信息(101张三857887102李斯575960103王红847987104赵子龙727576105李洪磊889889),包括学生学号、姓名、成绩〔数学、英语、数据库〕,程序中引用了八个函数voidCscore(int);voidRank(intave);voidListnumber(inti);voidListscore(inti);voidLookup(int);voidAlter(int);voidDele(int&i);voidInsert(int&i);系统主要实现的功能有:查询、修改、删除、插入、成绩单〔以学号排名〕和成绩单〔以名次排名〕。Cscore函数主要是对学生进行排名。具有相同总分的学生具有相同的名次,例如:第三名和第四名具有相同的总分那么在表中不会出现第四名,将出现两个第三名紧接着出现第五名学生的情况。Rank函数主要用于按平均分对学生进行备注。把学生分为四个等级:>90分为excellent,80—90分为medium,60—80分为qualified,<60分为disqualified。Listnumber函数主要用于把学生的信息〔学号姓名数学英语数据库总分平均分名次备注〕以学号排名的顺序用表的形式输出,方便学生查看。Listnumber函数中还调用了Cscore和Rank函数。Listscore函数是把学生的信息以总成绩排名的形式输出。Lookup函数主要运用学号或姓名形式查询单个学生信息,如果存在那么输出该学生信息〔学号姓名数学英语数据库总分平均分名次备注〕,否那么输出“Inputmessageiserror.〞。Alter函数是修改指定学号的学生信息。主要用于修改指定学号学生的各科成绩并输出修改后的学生信息〔学号姓名数学英语数据库总分平均分名次备注〕。Delete函数用于删除指定学生的信息。可用两种方式删除:以学号形式删除学生信息,以姓名形式删除学生信息。假设要删除了学生不存在那么输出“messageerror.〞。Insert函数用来插入学生的信息,一次调用Insert函数可以添加多个学生的信息。Insert函数中还调用了Cscore和Rank函数。〔1〕系统主要运用了函数的声明、定义、调用〔值调用和地址调用〕。对文件的读入操作。在平均分的求取上采用四舍五入的方式,运用了类型转换。屡次运用if和for嵌套,在for嵌套中又运用了break语句。运用了switch。对字符数组的比拟中运用了strcmp,还运用toupper把小写字母转换成大写。对学生信息进行的插入和有序删除操作。运用iomanip对输出进行美观。创新性说明〔怎么解决〕创新性:系统可以对具有相同总分学生的学生输出相同的名次。假设存在三个相同的分数都为第二名,那么在输出时出现三个第二名不会出现第三、四名,紧接着出现第五名。解决方法:〔1〕用一个数组记录具有相同分数的人数,数组下标和学生信息所具有的下标相同;〔2〕删除相同的总分只保存其中一个分数;〔3〕对删除相同总分的分数按从高到底进行排序;〔4〕对各个学生的总分进行排名。源代码//******************************************************************//Studentachievementprogram//Thisprogramhaseightfunctionsofstudentsgrade,includinglist//scoreranking,lookup,alter,delete,insertandrank.Fromthefilereadin//studentachievement.Scoresofpeoplehavethesamesameplace.//******************************************************************#include<iostream>#include<string>#include<cctype>#include<cstring>#include<iomanip>#include<fstream>voidCscore(int);voidRank(intave);voidListnumber(inti);voidListscore(inti);voidLookup(int);voidAlter(int);voidDele(int&i);voidInsert(int&i);usingnamespacestd;constintMAX=100;structstudent//定义学生信息结构体{intnum; charname[8]; intmath; intenglish; intdatabase; intsum; intaverage; intscore;}stu[MAX];intmain()//主函数{ inti,k; charch; stringfilename; ifstreaminfile; cout<<"Pleaseinputthefilenames:"; cin>>filename; infile.open(filename.c_str()); if(!infile) { cout<<"Can'topentheinputfile."<<endl;return1; } for(i=0;i<MAX&&infile;i++) { infile>>stu[i].num>>stu[i].name>>stu[i].math>>stu[i].english>>stu[i].database; stu[i].sum=stu[i].math+stu[i].english+stu[i].database; stu[i].average=int(float(stu[i].sum)/3+0.5); } i=i-1;cout<<endl<<"Welcometo学生成绩管理系统"<<endl;cout<<"YorN进入菜单栏"<<endl;cin>>ch;ch=toupper(ch);while(ch=='Y'){ cout<<endl<<"菜单:"<<endl<<"1)查询"<<endl<<"2)修改"<<endl<<"3)删除"<<endl<<"4)插入"<<endl <<"5)成绩单(以学号排名)"<<endl<<"6)成绩单(以名次排名)"<<endl;cout<<"***请选择1--4中任何一个:"<<endl;cin>>k;cout<<endl;switch(k) { case1:Lookup(i);break;case2:Alter(i);break;case3:Dele(i);break;case4:Insert(i);break; case5:Listnumber(i);break; case6:Listscore(i);break;default:cout<<"errorinput!"<<endl; }cout<<endl<<"继续选择YorN?"<<endl;cin>>ch;ch=toupper(ch);}cout<<"Thankyouforusing!"<<endl<<"Byebye!"<<endl; infile.close(); return0;}//endmainvoidCscore(inti)//对学生分数进行排名{ inth[MAX],b[MAX],score[MAX+1],n,k,j; intsum0[MAX],s; n=i; for(j=0;j<i;j++) { sum0[j]=stu[j].sum; } for(j=0;j<i;j++) { h[j]=0; for(k=0;k<i;k++) { if(sum0[j]==sum0[k]) { h[j]++;//具有同一分数的人数 } }//endfor }//endfor for(j=0;j<i;j++)//删除多个同一分数只保存其中一个分数 { for(k=j+1;k<i;k++) { if(sum0[j]==sum0[k]) { sum0[k]=sum0[i-1]; i--; k--; } } }//endfor for(j=0;j<i;j++)//按从高到底的顺序对总分进行排名 { for(k=j+1;k<i;k++) { if(sum0[j]<sum0[k]) { s=sum0[j]; sum0[j]=sum0[k]; sum0[k]=s; }//endif}//endfor }//endfor b[0]=0; score[0]=1; for(j=0;j<i;j++)//对学生成绩进行排名 { for(k=0;k<n;k++) { if(sum0[j]==stu[k].sum) { score[j+1]=score[j]+b[j]; stu[k].score=score[j+1]; b[j+1]=h[k]; }//endif }//endfor }//endfor}voidRank(intave)//对学生等级输出{ if(ave>=90) { cout<<"excellent"; } elseif(ave>=80) { cout<<"medium"; } elseif(ave>=60) { cout<<"qualified"; } else { cout<<"disqualified"; } cout<<endl;}voidListnumber(inti){ intj; Cscore(i); cout<<"学号姓名数学英语数据库总分平均分名次备注"<<endl; for(j=0;j<i;j++) { cout<<setw(1)<<stu[j].num<<setw(9)<<stu[j].name<<setw(4)<<stu[j].math<<setw(6) <<stu[j].english<<setw(6)<<stu[j].database; cout<<setw(8)<<stu[j].sum<<setw(7)<<stu[j].average; cout<<setw(7); cout<<stu[j].score<<""; Rank(stu[j].average); }}voidListscore(inti){ intj,k; Cscore(i); cout<<"学号姓名数学英语数据库总分平均分名次备注"<<endl; for(j=1;j<i+1;j++) { for(k=0;k<i;k++) { if(stu[k].score==j) { cout<<setw(1)<<stu[k].num<<setw(9)<<stu[k].name<<setw(4)<<stu[k].math<<setw(6) <<stu[k].english<<setw(6)<<stu[k].database; cout<<setw(8)<<stu[k].sum<<setw(7)<<stu[k].average; cout<<setw(7); cout<<stu[k].score<<""; Rank(stu[k].average); } } }}voidLookup(inti)//运用学号或姓名形式查询单个学生信息{ intj,k,n,numb; charname1[8];cout<<"Pleaseselectyoucheckscoreways."<<endl; cout<<"1isusenumber,0isusename."<<endl; cin>>n; if(n)//以学号形式查询学生信息 { cout<<"Pleaseinputstudentnumber:"; cin>>numb; for(j=0;j<i;j++) { if(numb==stu[j].num) { k=j; break; } } } else//以姓名形式查询学生信息 { cout<<"Pleaseinputstudentname:"; cin>>name1; for(j=0;j<i;j++) if(strcmp(stu[j].name,name1)==0) { k=j; break; } } if(k==MAX) { cout<<"Inputmessageiserror."<<endl; } else//如果学生存在那么输出学生信息 { Cscore(i); cout<<"学号姓名数学英语数据库总分平均分名次备注"<<endl; cout<<setw(1)<<stu[j].num<<setw(9)<<stu[j].name<<setw(4)<<stu[j].math<<setw(6) <<stu[j].english<<setw(6)<<stu[j].database; cout<<setw(8)<<stu[j].sum<<setw(7)<<stu[j].average; cout<<setw(7); cout<<stu[j].score<<""; Rank(stu[j].average); }}voidAlter(inti)//修改指定学号的学生信息{ intnumb,j;cout<<"alterbegin..."<<endl;cout<<"Pleaseinputnumber:";cin>>numb;for(j=0;j<i;j++){ if(numb==stu[j].num) { cout<<"findout:"<<endl;cout<<"学号:"<<stu[j].num<<"姓名:"<<stu[j].name<<endl;cout<<"Pleaseinputnewresult:数学英语数据库"<<endl;cin>>stu[j].math>>stu[j].english>>stu[j].database; stu[j].sum=stu[j].math+stu[j].english+stu[j].database; stu[j].average=int(float(stu[j].sum)/3.0+0.5); Cscore(i); //输出修改后该学号学生的信息 cout<<"学号姓名数学英语数据库总分平均分名次备注"<<endl; cout<<setw(1)<<stu[j].num<<setw(9)<<stu[j].name<<setw(4)<<stu[j].math<<setw(6) <<stu[j].english<<setw(6)<<stu[j].database; cout<<setw(8)<<stu[j].sum<<setw(7)<<stu[j].average; cout<<setw(7); cout<<stu[j].score<<""; Rank(stu[j].average); break; }}}voidDele(int&i)//删除指定学生的信息{ intnumb,j,k; charname0[8]; cout<<"deletebegin..."<<endl; cout<<"Pleaseselect:"<<endl;cout<<"[1]以学号形式删除学生信息"<<endl; cout<<"[0]以姓名形式删除学生信息"<<endl; cin>>k; if(k)//以学号形式删除学生的信息 { cout<<"Pleaseinputdeletenumber:"; cin>>numb; for(j=0;j<i;j++) { if(numb==stu[j].num) break; } } else//以姓名形式删除学生的信息 { cout<<"Pleaseinputdeletename:"; cin>>name0; for(j=0;j<i;j++) { if(strcmp(name0,stu[j].name)==0) break; } } if(j<i) { for(;j<i-1;j++) { stu[j].num=stu[j+1].num; strcpy(stu[j].name,stu[j+1].name); stu[j].math=stu[j+1].math; stu[j].english=stu[j+1].english; stu[j].database=stu[j+1].database; stu[j].sum=stu[j+1].sum; stu[j].average=stu[j+1].average; } i=i-1; Cscore(i); } else cout<<"messageerror."<<endl;}voidInsert(int&i)//插入学生的信息{ intj,n; cout<<"insertbegin..."<<endl; cout<<"Pleaseinputinsertnumberofpeople:"; cin>>n; i=i+n; cout<<"Pleaseinputinsertmessage.form:"<<endl; cout<<"学号姓名数学英语数据库"<<endl; for(j=i-n;j<i;j++) { cin>>stu[j].num>>stu[j].name>>stu[j].math>>stu[j].english>>stu[j].database; stu[j].sum=stu[j].math+stu[j].english+stu[j].database; stu[j].average=int(float(stu[j].sum)/3.0+0.5); } Cscore(i); cout<<"学号姓名数学英语数据库总分平均分名次备注"<<endl; for(j=i-n;j<i;j++) { cout<<setw(1)<<stu[j].num<<setw(9)<<stu[j].name<<setw(4)<<stu[j].math<<setw(6) <<stu[j].english<<setw(6)<<stu[j].database; cout<<setw(8)<<stu[j].sum<<setw(7)<<stu[j].average; cout<<setw(7); cout<<stu[j].score<<"";Rank(stu[j].average); }}运行结果与分析运行结果:分析:系统根本上能实现对成绩的查询、、修改、删除、插入、成绩单〔以学号排名〕和成绩单〔以名次排名〕等功能,并且可以插入多个学生的信息。但在插入学生后未不能成绩单以学号排名的形式输出。为了改良程序对Insert函数进行了一下修改。Insert函数代码如下:voidInsert(int&i)//插入学生的信息{ intj,k,n,m,first,last,mid; intnum0,math0,english0,database0; charname0[8]; cout<<"insertbegin..."<<endl; cout<<"Pleaseinputinsertnumberofpeople:"; cin>>n; m=i+n; first=0; last=i-1; mid=(first+last)/2; cout<<"Pleaseinputinsertmessage.form:"<<endl; cout<<"学号姓名数学英语数据库"<<endl; for(j=i;j<m;j++) { i=i+1; cin>>stu[j].num>>stu[j].name>>stu[j].math>>stu[j].english>>stu[j].database; while(first<=last) { if(stu[j].num<stu[mid].num) { last=mid-1; } elsei

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论