




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、目的与要求C+课程学习中的的数据类型、程序结构、数组、函数、指针、结构体、链通过本课程设计的实践,全面总结表等基本概念,掌握其使用方法。掌握面向对象程序设计中有关类、对象、继承、重载、多态性、输入输出流类体系、文件操作的基本概念,初步学会用类与对象这种面向对象的程序设计方法编写应用程序。培养使用面向对象的程序设计方法编写计算机程序的能力。通过设计一个学生成绩统计管理,进一步熟悉C+中类的概念、类的封装、继承的实现方式。了解系统开发的需求分析、类层次设计、模块分解、编码测试、模块组装与整体调试的全过程,加深对C+的理解与VisualC+环境的使用;逐步熟悉程序设计的方法,并养成良好的编程习惯。程
2、序设计是一门实践性很强的课程,必须十分重视实践环节。许多实际的知识不是靠听课和看书学到的,而是通过长时间的实践积累的。一、设计内容学生成绩管理系统1 .基本功能:这个程序的主要功能是输入学生姓名、成绩,学号,并可以对学生的成绩按学号进行查询。该系统具有存贮学生数据,按学号按需要修改学生成绩,列出学生成绩和统计功能。2 .扩展功能:学生数据的添加、修改、与删除2.ER二、过程与结果主要内容如下:1 .关键类的设计,继承层次关系,代码:首先,创建了一个student类.Student类的声明如下:classStudentpublic:intClass,num;charname8;floatcpp,
3、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;主要功能函数的设计:1. 创建学生数据,对学生的成绩的录入。代码:friendStudent*Create(Student*
4、head,istream&in)inty;Student*p;intClass,num;charname8;floatcpp,math,eng;if(&in=&cin)/cout<<"nn请输入学生数据(输入成绩非法,则结束),数据输入格式为:n"/<<"班级姓名学号C+数学英语n"/in>>Class>>name>>num>>cpp>>math>>eng;/cout<<"nn请输入学生数据:n"cout
5、<<"班级:"<<endl;in>>Class;cout<<"姓名:"<<endl;in>>name;cout<<"学号:"<<endl;in>>num;cout<<"C+的成绩:"<<endl;in>>cpp;cout<<"数学的成绩:"<<endl;in>>math;cout<<"英语的成绩:
6、"<<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;
7、head=Insert(head,p);/in>>Class>>name>>num>>elec>>cpp>>math>>eng>>polity>>sport;cout<<"tt*继续添加请按1*n"cout<<"tt*返回主菜单请按2*n"in>>y;if(y=2)ShowMenu();elsehead=Create(head,cin);SetOrder(head);/设置排名returnhead;2. 此函数为
8、查找函数的实现过程主要代码: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&
9、lt;<'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
10、=p2,p2=p2->next;if(p2)if(p2=p1)head=head->next;deletep1;elsep1->next=p2->next;deletep2;)cout<<"已删除"<<num<<”号学生数据n"SetOrder(head);elsecout<<"没找到指定学生!n"returnhead;4 .排序函数中平均分来排序,排序结果为降序操作。friendvoidSetOrder(Student*head)intorder=1;while(head
11、)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<<"nn请输入新数据,格式为:n"<<"班级姓名学号C+数学英语n"cin>>p2->Clas
12、s>>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<<&qu
13、ot;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<<"nn成绩数据非法!请重新输入,格式为:n"<<"班级姓
14、名学号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);elsep1->next=p2->next;head=Insert(head,p2);SetO
15、rder(head);elsecout<<"8i找至ij指定学生!n"returnhead;6 .显示数据:friendvoidOutputAll(constStudent*head)/输出所有学生的数据if(!head)cout<<"nntt没有任何学生数据!nn"return;cout<<"nntt学生成绩表nn"cout<<"班级t姓名t学号tC+t数学t英语t名次n"while(head)OutputOne(head);head=head->next;7
16、 .平均数据函数friendvoidStatistic(constStudent*head)inti=0;floatave_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<<"nn没有任何学生数据!n"return;cout<<"nntt各门课程平均成绩表nn"cout<<"tC+t
17、数学t英语n"cout<<ave_cpp/i<<'t'<<ave_math/i<<'t'<<ave_eng/i<<endl;程序测试结果:1. 运行程序.会出现如下画面,按照提示进行选择.2. 首先选择1,然后按Enter键.按照提示对学生情况进行输入.如图:3. 按1键可以添加多个学生成绩的数据,按2返回主界面。4. 选择5,然后按Enter键,显示刚才输入的数据和排名的情况。5. 在主界面选择2可以修改学生的数据。6. 在主界面选择3可以按学号查询学生成绩情况7. 在主界面选择
18、7可以按学号删除学生的成绩信息三、设计总结这次课程设计基本上涵盖了学习到的C+语言知识点,课程设计题目要求不仅要求对课本虽然是网上搜来的代码,但这些代码没办法运行,我把这些代码改了和增加了自己写的代码,终于可以运行,而且到达自己想要的结果,这次课程设计不仅让我修补了以前学习的漏洞,也让我知道一个道理:编程需要兴趣和实际动手。C+语言程序设计课程设计,我从中受益匪浅,并且对C+语言程序设计这一门课程有了更深一步的认识。附件程序源代码清单:#include<fstream.h>#include<string.h>classStudentpublic:intClass,num
19、;charname8;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<
20、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所指的链表中降序插入结点Student*p1,*p2;if(head=0)head=p;p->next=0;elseif(head->ave<=p->ave)p->next=head;head=p;elsep2=p1=head;while(
21、p2->next&&p2->ave>p->ave)p1=p2;p2=p2->next;if(p2->ave>p->ave)p2->next=p;p->next=0;elsep->next=p2;p1->next=p;returnhead;friendStudent*Create(Student*head,istream&in)inty;Student*p;intClass,num;charname8;floatcpp,math,eng;if(&in=&cin)/cout<<
22、;"nn请输入学生数据(输入成绩非法,则结束),数据输入格式为:n"/<<"班级姓名学号C+数学英语n"/in>>Class>>name>>num>>cpp>>math>>eng;/cout<<"nn请输入学生数据:n"cout<<"班级:"<<endl;in>>Class;cout<<"姓名:"<<endl;in>>name;c
23、out<<"学号:"<<endl;in>>num;cout<<"C+的成绩:"<<endl;in>>cpp;cout<<"数学的成绩:"<<endl;in>>math;cout<<"英语的成绩:"<<endl;in>>eng;/*while(Valid(elec)&&Valid(cpp)&&Valid(math)&&Valid
24、(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>
25、;>polity>>sport;cout<<"tt*继续添加请按1*n"cout<<"tt*返回主菜单请按2*n"in>>y;if(y=2)ShowMenu();elsehead=Create(head,cin);SetOrder(head);设置排名returnhead;friendconstStudent*Lookup(constStudent*head,intnum)查找指定学号为num的结点while(head&&head->num!=num)head=head->
26、next;returnhead;friendvoidOutputOne(constStudent*head)/输出一个学生数据cout<<head->Class<<'t'<<head->name<<'t'<<head->num<<'t'<<head->cpp<<'t'<<head->math<<'t'<<head->eng<<'t
27、'<<head->order<<endl;friendvoidOutputAll(constStudent*head)/输出所有学生的数据if(!head)cout<<"nntt没有任何学生数据!nn"return;cout<<"nntt学生成绩表nn"cout<<"班级t姓名t学号tC+t数学t英语t名次n"while(head)OutputOne(head);head=head->next;)friendStudent*Modify(Student*h
28、ead,intnum)/修改学号为学生的数据(Student*p1=head,*p2=p1;while(p2&&p2->num!=num)/寻找待修改的结点p1=p2,p2=p2->next;if(p2)/修改指定结点数据(/*cout<<"nn请输入新数据,格式为:n"<<"班级姓名学号C+数学英语n”;cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math>>
29、p2->eng;*/cout<<"班级:"<<endl;cin>>p2->Class;cout<<"姓名:"<<endl;cin>>p2->name;cout<<"学号:"<<endl;cin>>p2->num;cout<<"C+的成绩:"<<endl;cin>>p2->cpp;cout<<"数学的成绩:"<
30、;<endl;cin>>p2->math;cout<<"英语的成绩:"<<endl;cin>>p2->eng;while(!Valid(p2->cpp)|!Valid(p2->math)|!Valid(p2->eng)(cout<<"nn成绩数据非法!请重新输入,格式为:n"<<"班级姓名学号C+数学英语n”;cin>>p2->Class>>p2->name>>p2->num>&
31、gt;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*Delet
32、eStudent(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;elsep1->next=p2->next;deletep2;cout<<"已删除"<<num<<"号学生数据n"SetOrder(head);elsecout<<"没找到指定学生!n&qu
33、ot;returnhead;friendvoidStatistic(constStudent*head)inti=0;floatave_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<<"nn没有任何学生数据!n"return;cout<<"nntt各门课程平均成绩表nn"cout<<&quo
34、t;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<<"nn"cout<<"tt*欢迎使用学生成绩管理系统*n
35、"<<"tt*n"<<"tt*1.从键盘录入与添加数据*n"/<<"tt*2.从文件录入与添加数据*n"<<"tt*2.修改数据*n"<<"tt*3.查询数据*n"<<"tt*4.删除数据*n"<<"tt*5.显示数据*n"<<"tt*6.平均数据*n"/<<"tt*7.保存数据*n"<<"tt*n"<<"tt*0.退出系统*n"<<
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年无锡中医面试题及答案
- 2025年上海小学晚托面试题及答案
- 2025年中药学试题及答案卫生
- 2025年传播学专业考试题及答案
- 村民公章协议书
- 林地承租协议书
- 林地间种协议书
- 柑橘转让协议书
- 查询授权协议书
- 2025年三基考试试题及答案妇产
- 血透护理文书书写规范
- 反恐怖主义经费保障制度
- 2023年突发急性传染病防控和应急处置技能竞赛试题库
- CT增强扫描碘对比剂外渗预防与护理规范 DB45T 2935-2024
- 各岗位应知应会“明白卡”(含矿长等)
- 科研机构安全管理措施及技术保障
- 《水电解制氢工艺》课件
- 激光设备调试报告范文
- 品管圈PDCA案例-降低留置针穿刺血管静脉炎发生率成果汇报
- 光伏电站项目前期审批流程(最终版)
- 心肺复苏课件下载
评论
0/150
提交评论