版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一.目标和要求经过本课程设计实践,全方面总结C++课程学习中数据类型、程序结构、数组、函数、指针、结构体、链表等基础概念,掌握其使用方法。掌握面向对象程序设计中相关类、对象、继承、重载、多态性、输入输出流类体系、文件操作基础概念,初步学会用类和对象这种面向对象程序设计方法编写应用程序。培养使用面向对象程序设计方法编写计算机程序能力。经过设计一个《学生成绩统计管理》,深入熟悉C++中类概念、类封装、继承实现方法。了解系统开发需求分析、类层次设计、模块分解、编码测试、模块组装和整体调试全过程,加深对C++了解和VisualC++环境使用;逐步熟悉程序设计方法,并养成良好编程习惯。程序设计是一门实践性很强课程,必需十分重视实践步骤。很多实际知识不是靠听课和看书学到,而是经过长时间实践积累。设计内容学生成绩管理系统基础功效:这个程序关键功效是输入学生姓名、成绩,学号,并能够对学生成绩按学号进行查询。该系统含有存贮学生数据,按学号按需要修改学生成绩,列出学生成绩和统计功效。扩展功效:学生数据添加、修改、和删除2.E—R修改数据修改数据删除数据查询数据显示数据平均数据添加数据学生成绩管理系统过程和结果关键内容以下:关键类设计,继承层次关系,代码:首先,创建了一个student类.Student类申明以下:classStudent{public: intClass,num; charname[8]; floatcpp,math,eng,ave; intorder; Student*next;public: Student(){}Student(intc1,intn1,char*n,floate1,floatc2,floatm,floate2,floats,floatp,floata, into,Student*next=NULL) { Class=c1;num=n1; strcpy(name,n); cpp=c2;math=m;eng=e2;ave=a; order=o; this->next=next; }关键功效函数设计:创建学生数据,对学生成绩录入。 代码:friendStudent*Create(Student*head,istream&in) {inty; Student*p; intClass,num; charname[8]; floatcpp,math,eng; if(&in==&cin) //cout<<"\n\n请输入学生数据(输入成绩非法,则结束),数据输入格式为:\n" //<<"班级姓名学号C++数学英语\n"; //in>>Class>>name>>num>>cpp>>math>>eng; //cout<<"\n\n请输入学生数据:\n" cout<<"班级:"<<endl; in>>Class;cout<<"姓名:"<<endl;in>>name; cout<<"学号:"<<endl;in>>num; cout<<"C++成绩:"<<endl;in>>cpp; cout<<"数学成绩:"<<endl;in>>math; cout<<"英语成绩:"<<endl;in>>eng; /*while(Valid(elec)&&Valid(cpp)&&Valid(math)&&Valid(eng)&&Valid(sport)&&Valid(polity)) {*/p=newStudent; p->Class=Class;p->num=num;strcpy(p->name,name); p->cpp=cpp;p->math=math; p->eng=eng; p->ave=(cpp+math+eng)/6; head=Insert(head,p); //in>>Class>>name>>num>>elec>>cpp>>math>>eng>>polity>>sport; cout<<"\t\t*****继续添加请按1*******\n"; cout<<"\t\t*****返回主菜单请按2*******\n"; in>>y;if(y==2) { ShowMenu(); } else{head=Create(head,cin);} SetOrder(head);//设置排名 returnhead; } 此函数为查找函数实现过程 关键代码:friendconstStudent*Lookup(constStudent*head,intnum)//查找指定学号为num结点 { while(head&&head->num!=num) head=head->next; returnhead; } friendvoidOutputOne(constStudent*head)//输出一个学生数据 { cout<<head->Class<<'\t'<<head->name<<'\t'<<head->num<<'\t' <<head->cpp<<'\t'<<head->math<<'\t' <<head->eng<<'\t' <<head->order<<endl; } 3.此函数为删除函数实现部分。 关键代码:friendStudent*DeleteStudent(Student*head,intnum) { Student*p1=head,*p2=p1; while(p2&&p2->num!=num) p1=p2,p2=p2->next; if(p2) { if(p2==p1) { head=head->next;deletep1; } else { p1->next=p2->next;deletep2; } cout<<"已删除"<<num<<"号学生数据\n"; SetOrder(head); }elsecout<<"没找到指定学生!\n"; returnhead; } 4.排序函数中平均分来排序,排序结果为降序操作。 friendvoidSetOrder(Student*head) { intorder=1; while(head) {head->order=order++;head=head->next;} }5.修改学生信息friendStudent*Modify(Student*head,intnum)//修改学号为学生数据 { Student*p1=head,*p2=p1; while(p2&&p2->num!=num)//寻求待修改结点 p1=p2,p2=p2->next; if(p2)//修改指定结点数据 { /*cout<<"\n\n请输入新数据,格式为:\n" <<"班级姓名学号C++数学英语\n"; cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math >>p2->eng;*/ cout<<"班级:"<<endl; cin>>p2->Class;cout<<"姓名:"<<endl;cin>>p2->name; cout<<"学号:"<<endl;cin>>p2->num; cout<<"C++成绩:"<<endl;cin>>p2->cpp; cout<<"数学成绩:"<<endl;cin>>p2->math; cout<<"英语成绩:"<<endl;cin>>p2->eng; while(!Valid(p2->cpp)||!Valid(p2->math)||!Valid(p2->eng) ) { cout<<"\n\n成绩数据非法!请重新输入,格式为:\n" <<"班级姓名学号C++数学英语\n"; cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math >>p2->eng; } p2->ave=(p2->cpp+p2->math+p2->eng)/3; //将修改指定结点从原链表上修改下来,并重新降序插入原链表 if(p2==p1) head=Insert(p2->next,p2); else { p1->next=p2->next; head=Insert(head,p2); } SetOrder(head); } elsecout<<"没找到指定学生!\n"; returnhead; } 6.显示数据: friendvoidOutputAll(constStudent*head)//输出全部学生数据 { if(!head){cout<<"\n\n\t\t没有任何学生数据!\n\n";return;} cout<<"\n\n\t\t学生成绩表\n\n"; cout<<"班级\t姓名\t学号\tC++\t数学\t英语\t名次\n"; while(head) { OutputOne(head);head=head->next; } }7.平均数据函数 friendvoidStatistic(constStudent*head) { inti=0; float ave_cpp=0, ave_math=0, ave_eng=0; while(head) { ave_cpp+=head->cpp; ave_math+=head->math; ave_eng+=head->eng; i++;head=head->next; } if(!i) { cout<<"\n\n没有任何学生数据!\n";return;} cout<<"\n\n\t\t各门课程平均成绩表\n\n"; cout<<"tC++\t数学\t英语\n"; cout<<ave_cpp/i<<'\t'<<ave_math/i<<'\t' <<ave_eng/i<<endl; }程序测试结果:1运行程序.会出现以下画面,根据提醒进行选择.首先选择1,然后按Enter键.根据提醒对学生情况进行输入.图:按1键能够添加多个学生成绩数据,按2返回主界面。选择5,然后按Enter键,显示刚才输入数据和排名情况。5在主界面选择2能够修改学生数据。6.在主界面选择3能够按学号查询学生成绩情况7.在主界面选择7能够按学号删除学生成绩信息设计总结这次课程设计基础上涵盖了学习到C++语言知识点,课程设计题目要求不仅要求对书本即使是网上搜来代码,但这些代码没措施运行,我把这些代码改了和增加了自己写代码,最终能够运行,而且抵达自己想要结果,这次课程设计不仅让我修补了以前学习漏洞,也让我知道一个道理:编程需要爱好和实际动手。C++语言程序设计课程设计,我从中受益匪浅,而且对C++语言程序设计这一门课程有了更深一步认识。附件程序源代码清单:#include<fstream.h>#include<string.h>classStudent{public: intClass,num; charname[8]; floatcpp,math,eng,ave; intorder; Student*next;public: Student(){}Student(intc1,intn1,char*n,floate1,floatc2,floatm,floate2,floats,floatp,floata, into,Student*next=NULL) { Class=c1;num=n1; strcpy(name,n); cpp=c2;math=m;eng=e2;ave=a; order=o; this->next=next; } friendintValid(floatscore) { return(score<0||score>100)?0:1; } friendvoidSetOrder(Student*head) { intorder=1; while(head) {head->order=order++;head=head->next;} } friendStudent*Insert(Student*head,Student*p)//在head所指链表中降序插入结点p { Student*p1,*p2; if(head==0) { head=p;p->next=0; } elseif(head->ave<=p->ave) { p->next=head;head=p; } else { p2=p1=head; while(p2->next&&p2->ave>p->ave) { p1=p2;p2=p2->next; } if(p2->ave>p->ave) { p2->next=p;p->next=0; } else{ p->next=p2;p1->next=p; } } returnhead; } friendStudent*Create(Student*head,istream&in) {inty; Student*p; intClass,num; charname[8]; floatcpp,math,eng; if(&in==&cin) //cout<<"\n\n请输入学生数据(输入成绩非法,则结束),数据输入格式为:\n" //<<"班级姓名学号C++数学英语\n"; //in>>Class>>name>>num>>cpp>>math>>eng; //cout<<"\n\n请输入学生数据:\n" cout<<"班级:"<<endl; in>>Class;cout<<"姓名:"<<endl;in>>name; cout<<"学号:"<<endl;in>>num; cout<<"C++成绩:"<<endl;in>>cpp; cout<<"数学成绩:"<<endl;in>>math; cout<<"英语成绩:"<<endl;in>>eng; /*while(Valid(elec)&&Valid(cpp)&&Valid(math)&&Valid(eng)&&Valid(sport)&&Valid(polity)) {*/p=newStudent; p->Class=Class;p->num=num;strcpy(p->name,name); p->cpp=cpp;p->math=math; p->eng=eng; p->ave=(cpp+math+eng)/6; head=Insert(head,p); //in>>Class>>name>>num>>elec>>cpp>>math>>eng>>polity>>sport; cout<<"\t\t*****继续添加请按1*******\n"; cout<<"\t\t*****返回主菜单请按2*******\n"; in>>y;if(y==2) { ShowMenu(); } else{head=Create(head,cin);} SetOrder(head);//设置排名 returnhead; } friendconstStudent*Lookup(constStudent*head,intnum)//查找指定学号为num结点 { while(head&&head->num!=num) head=head->next; returnhead; } friendvoidOutputOne(constStudent*head)//输出一个学生数据 { cout<<head->Class<<'\t'<<head->name<<'\t'<<head->num<<'\t' <<head->cpp<<'\t'<<head->math<<'\t' <<head->eng<<'\t' <<head->order<<endl; } friendvoidOutputAll(constStudent*head)//输出全部学生数据 { if(!head){cout<<"\n\n\t\t没有任何学生数据!\n\n";return;} cout<<"\n\n\t\t学生成绩表\n\n"; cout<<"班级\t姓名\t学号\tC++\t数学\t英语\t名次\n"; while(head) { OutputOne(head);head=head->next; } } friendStudent*Modify(Student*head,intnum)//修改学号为学生数据 { Student*p1=head,*p2=p1; while(p2&&p2->num!=num)//寻求待修改结点 p1=p2,p2=p2->next; if(p2)//修改指定结点数据 { /*cout<<"\n\n请输入新数据,格式为:\n" <<"班级姓名学号C++数学英语\n"; cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math >>p2->eng;*/ cout<<"班级:"<<endl; cin>>p2->Class;cout<<"姓名:"<<endl;cin>>p2->name; cout<<"学号:"<<endl;cin>>p2->num; cout<<"C++成绩:"<<endl;cin>>p2->cpp; cout<<"数学成绩:"<<endl;cin>>p2->math; cout<<"英语成绩:"<<endl;cin>>p2->eng; while(!Valid(p2->cpp)||!Valid(p2->math)||!Valid(p2->eng) ) { cout<<"\n\n成绩数据非法!请重新输入,格式为:\n" <<"班级姓名学号C++数学英语\n"; cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math >>p2->eng; } p2->ave=(p2->cpp+p2->math+p2->eng)/3; //将修改指定结点从原链表上修改下来,并重新降序插入原链表 if(p2==p1) head=Insert(p2->next,p2); else { p1->next=p2->next; head=Insert(head,p2); } SetOrder(head); } elsecout<<"没找到指定学生!\n"; returnhead; } friendStudent*DeleteStudent(Student*head,intnum) { Student*p1=head,*p2=p1; while(p2&&p2->num!=num) p1=p2,p2=p2->next; if(p2) { if(p2==p1) { head=head->next;deletep1; } else { p1->next=p2->next;deletep2; } cout<<"已删除"<<num<<"号学生数据\n"; SetOrder(head); }elsecout<<"没找到指定学生!\n"; returnhead; } friendvoidStatistic(constStudent*head) { inti=0; float ave_cpp=0, ave_math=0, ave_eng=0; while(head) { ave_cpp+=head->cpp; ave_math+=head->math; ave_eng+=head->eng; i++;head=head->next; } if(!i) { cout<<"\n\n没有任何学生数据!\n";return;} cout<<"\n\n\t\t各门课程平均成绩表\n\n"; cout<<"tC++\t数学\t英语\n"; cout<<ave_cpp/i<<'\t'<<ave_math/i<<'\t' <<ave_eng/i<<endl; } friendvoidDeleteChain(Student*head) {Student*p; while(head) { p=head;head=head->next;deletep; } } friendvoidShowMenu(void) { cout<<"\n\n"; cout<<"\t\t******欢迎使用学生成绩管理系统******\n" <<"\t\t**\n" <<"\t\t*1.从键盘录入和添加数据*\n" // <<"\t\t*2.从文件录入和添加数据*\n" <<"\t\t*2.修改数据*\n" <<"\t\t*3.查询数据*\n" <<"\t\t*4.删除数据*\n" <<"\t\t*5.显示数据*\n" <<"\t\t*6.平均数据*\n" // <<"\t\t*7.保留数据*\n" <<"\t\t**\n" <<"\t\t*0.退出系统*\n" <<"\t\t**********************************\n\n"; }};voidmain(void){ Student*head=0; intselect; while(1) { Show
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026福建省福投新能源投资股份公司招聘7人笔试备考题库及答案解析
- 2026年全挂车行业洞察报告及未来五至十年发展趋势报告
- 2026年PPP咨询服务行业洞察报告及未来五至十年发展趋势报告
- 2026年化妆工具套装行业洞察报告及未来五至十年发展趋势报告
- 复杂场景下空间目标视觉定位技术的多维探索与突破
- 2026年卫星通信技术行业洞察报告及未来五至十年发展趋势报告
- 2026年体育场地设施管理行业产业趋势报告及未来五至十年市场空间与盈利前景
- 海南西南大学东方实验中学2026-2027学年高三上学期10月阶段检测英语试题(含解析无听力原文无音频)
- 2026年孔雀行业洞察报告及未来五至十年发展趋势报告
- 冲压连续模课件
- 托育机构饮食安全隐患排查及整改措施
- 雨课堂学堂在线学堂云《工业互联网(北京航空航天)》单元测试考核答案
- 双重预防体系运行情况评审报告及记录
- 儿童生长曲线动态监测与生长发育心理行为干预
- 宜春市锂电新能源产业中长期发展规划
- 2025年人教版八年级英语上学期单词字帖(衡水体)
- 中国国新控股校招笔试题及答案
- 2025广东深圳市城市公共安全技术研究院有限公司招聘笔试历年参考题库附带答案详解
- 门球教练入门知识培训课件
- 铁路扫雪除冰安全培训课件
- 乡土中国各章题目及答案
评论
0/150
提交评论