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

下载本文档

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

文档简介

1、一目的与要求通过本课程设计的实践,全面总结C+课程学习中的的数据类型、程序结构、数组、函数、指针、结构体、链表等基本概念,掌握其使用方法。掌握面向对象程序设计中有关类、对象、继承、重载、多态性、输入输出流类体系、文件操作的基本概念,初步学会用类与对象这种面向对象的程序设计方法编写应用程序。培养使用面向对象的程序设计方法编写计算机程序的能力。通过设计一个学生成绩统计管理,进一步熟悉C+中类的概念、类的封装、继承的实现方式。了解系统开发的需求分析、类层次设计、模块分解、编码测试、模块组装与整体调试的全过程,加深对C+的理解与Visual C+环境的使用;逐步熟悉程序设计的方法,并养成良好的编程习惯

2、。程序设计是一门实践性很强的课程,必须十分重视实践环节。许多实际的知识不是靠听课和看书学到的,而是通过长时间的实践积累的。一、 设计内容学生成绩管理系统1 基本功能: 这个程序的主要功能是输入学生姓名、成绩,学号,并可以对学生的成绩按学号进行查询。该系统具有存贮学生数据,按学号按需要修改学生成绩,列出学生成绩和统计功能。2 扩展功能:学生数据的添加、修改、与删除2.ER修改数据删除数据查询数据显示数据平均数据添加数据学生成绩管理系统 二、 过程与结果主要内容如下:1. 关键类的设计,继承层次关系,代码:首先,创建了一个student类. Student类的声明如下:class Studentp

3、ublic:int Class,num;char name8;float cpp,math,eng,ave;int order;Student *next;public:Student() Student(int c1,int n1,char*n,float e1,float c2,float m,float e2,float s,float p,float a,int o,Student *next=NULL)Class=c1;num=n1;strcpy(name,n);cpp=c2;math=m;eng=e2;ave=a;order=o;this->next=next; 主要功能函数

4、的设计:1. 创建学生数据,对学生的成绩的录入。代码:friend Student *Create(Student *head,istream& in)int y;Student *p;int Class,num;char name8;float cpp,math,eng;if(&in=&cin)/cout<<"nn请输入学生数据(输入成绩非法,则结束),数据输入格式为:n"/<<"班级 姓名 学号 C+ 数学 英语 n"/in>>Class>>name>>num>

5、>cpp>>math>>eng;/cout<<"nn请输入学生数据:n"cout<<"班级:"<<endl; in>>Class; cout<<"姓名:"<<endl; in>>name;cout<<"学号:"<<endl; in>>num;cout<<"C+的成绩:"<<endl; in>>cpp;cout&l

6、t;<"数学的成绩:"<<endl; in>>math;cout<<"英语的成绩 :"<<endl; in>>eng;/*while(Valid(elec)&&Valid(cpp)&&Valid(math)&&Valid(eng)&&Valid(sport)&&Valid(polity)*/p=new Student;p->Class=Class;p->num=num;strcpy(p->na

7、me,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<<"tt*继续添加请按1*n"cout<<"tt*返回主菜单请按2*n" in>>y;

8、if(y=2) ShowMenu(); elsehead=Create(head,cin);SetOrder(head); /设置排名return head;2. 此函数为查找函数的实现过程 主要代码:friend const Student * Lookup(const Student *head,int num) /查找指定学号为num的结点 while(head && head->num!=num)head=head->next;return head;friend void OutputOne(const Student* head) /输出一个学生数据co

9、ut<<head->Class<<'t'<<head->name<<'t'<<head->num<<'t'<<head->cpp<<'t'<<head->math<<'t'<<head->eng<<'t'<<head->order<<endl;3.此函数为删除函数的实现部分。 主要代码:fri

10、end Student *DeleteStudent(Student *head,int num)Student *p1=head,*p2=p1;while(p2&&p2->num!=num)p1=p2,p2=p2->next;if(p2)if(p2=p1)head=head->next;delete p1;else p1->next=p2->next;delete p2;cout<<"已删除"<<num<<"号学生数据n"SetOrder(head);else cout&

11、lt;<"没找到指定学生!n"return head;4.排序函数中平均分来排序,排序结果为降序操作。friend void SetOrder(Student*head) int order=1;while(head)head->order=order+;head=head->next;5修改学生的信息friend Student *Modify(Student *head,int num) /修改学号为学生的数据Student *p1=head,*p2=p1;while(p2&&p2->num!=num) /寻找待修改的结点p1=p

12、2,p2=p2->next;if(p2) /修改指定结点数据/*cout<<"nn请输入新数据,格式为:n"<<"班级 姓名 学号 C+ 数学 英语 n"cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math>>p2->eng;*/ cout<<"班级:"<<endl; cin>>p2->Class; cou

13、t<<"姓名:"<<endl; cin>>p2->name;cout<<"学号:"<<endl; cin>>p2->num;cout<<"C+的成绩:"<<endl; cin>>p2->cpp;cout<<"数学的成绩:"<<endl; cin>>p2->math;cout<<"英语的成绩 :"<<endl

14、; 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>>p2->cpp>>p2->math>>p2->eng;p2->ave=(p2

15、->cpp+p2->math+p2->eng)/3;/将修改的指定结点从原链表上修改下来,并重新降序插入原链表if(p2=p1)head=Insert(p2->next,p2);elsep1->next=p2->next; head=Insert(head,p2);SetOrder(head);else cout<<"没找到指定学生!n"return head;6.显示数据:friend void OutputAll(const Student*head) /输出所有学生的数据if(!head) cout<<&qu

16、ot;nntt没有任何学生数据!nn" return;cout<<"nntt学生成绩表nn"cout<<"班级t姓名t学号tC+t数学t英语t名次n"while(head)OutputOne(head);head=head->next;7.平均数据函数friend void Statistic(const Student *head)int i=0;float ave_cpp=0,ave_math=0,ave_eng=0;while(head)ave_cpp+=head->cpp;ave_math+=head

17、->math;ave_eng+=head->eng;i+;head=head->next;if(!i)cout<<"nn没有任何学生数据!n"return;cout<<"nntt各门课程平均成绩表nn"cout<<"tC+t数学t英语n"cout<<ave_cpp/i<<'t'<<ave_math/i<<'t'<<ave_eng/i<<endl;程序测试结果:1运行程序.会出现如

18、下画面,按照提示进行选择.2. 首先选择1,然后按Enter键.按照提示对学生情况进行输入.如图:3. 按1键可以添加多个学生成绩的数据,按2返回主界面。4. 选择5, 然后按Enter键,显示刚才输入的数据和排名的情况。5在主界面选择2可以修改学生的数据。6.在主界面选择3可以按学号查询学生成绩情况7. 在主界面选择7可以按学号删除学生的成绩信息 三、 设计总结这次课程设计基本上涵盖了学习到的C+ 语言知识点,课程设计题目要求不仅要求对课本虽然是网上搜来的代码,但这些代码没办法运行,我把这些代码改了和增加了自己写的代码,终于可以运行,而且到达自己想要的结果,这次课程设计不仅让我修补了以前学习

19、的漏洞,也让我知道一个道理:编程需要兴趣和实际动手。C+语言程序设计课程设计,我从中受益匪浅,并且对C+语言程序设计这一门课程有了更深一步的认识。附件程序源代码清单:#include <fstream.h>#include <string.h>class Studentpublic:int Class,num;char name8;float cpp,math,eng,ave;int order;Student *next;public:Student() Student(int c1,int n1,char*n,float e1,float c2,float m,fl

20、oat e2,float s,float p,float a,int o,Student *next=NULL)Class=c1;num=n1;strcpy(name,n);cpp=c2;math=m;eng=e2;ave=a;order=o;this->next=next; friend int Valid(float score) return (score<0|score>100) ?0:1;friend void SetOrder(Student*head) int order=1;while(head)head->order=order+;head=head-

21、>next;friend Student* Insert(Student *head,Student *p) /在head所指的链表中降序插入结点p Student*p1,*p2;if(head=0)head=p;p->next=0;else if(head->ave<=p->ave)p->next=head;head=p;elsep2=p1=head;while(p2->next&&p2->ave>p->ave)p1=p2;p2=p2->next;if(p2->ave>p->ave)p2-&g

22、t;next=p;p->next=0;else p->next=p2;p1->next=p;return head;friend Student *Create(Student *head,istream& in)int y;Student *p;int Class,num;char name8;float cpp,math,eng;if(&in=&cin)/cout<<"nn请输入学生数据(输入成绩非法,则结束),数据输入格式为:n"/<<"班级 姓名 学号 C+ 数学 英语 n"/in

23、>>Class>>name>>num>>cpp>>math>>eng;/cout<<"nn请输入学生数据:n"cout<<"班级:"<<endl; in>>Class; cout<<"姓名:"<<endl; in>>name;cout<<"学号:"<<endl; in>>num;cout<<"C+的成绩:

24、"<<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=new Student;p->C

25、lass=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<<"tt*继续添加请按1*n"cout<<

26、;"tt*返回主菜单请按2*n" in>>y; if(y=2) ShowMenu(); elsehead=Create(head,cin);SetOrder(head); /设置排名return head;friend const Student * Lookup(const Student *head,int num) /查找指定学号为num的结点 while(head && head->num!=num)head=head->next;return head;friend void OutputOne(const Student*

27、 head) /输出一个学生数据cout<<head->Class<<'t'<<head->name<<'t'<<head->num<<'t'<<head->cpp<<'t'<<head->math<<'t'<<head->eng<<'t'<<head->order<<endl;friend

28、void OutputAll(const Student*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;friend Student *Modify(Student *head,int num) /修改学号为学生的数据Student *p1=hea

29、d,*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>>p2->eng;*/ cout<<

30、"班级:"<<endl; cin>>p2->Class; cout<<"姓名:"<<endl; cin>>p2->name;cout<<"学号:"<<endl; cin>>p2->num;cout<<"C+的成绩:"<<endl; cin>>p2->cpp;cout<<"数学的成绩:"<<endl; cin>&g

31、t;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>>p2-&g

32、t;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);SetOrder(head);else cout<<"没找到指定学生!n"return head;friend Student *DeleteStude

33、nt(Student *head,int num)Student *p1=head,*p2=p1;while(p2&&p2->num!=num)p1=p2,p2=p2->next;if(p2)if(p2=p1)head=head->next;delete p1;else p1->next=p2->next;delete p2;cout<<"已删除"<<num<<"号学生数据n"SetOrder(head);else cout<<"没找到指定学生!n&q

34、uot;return head;friend void Statistic(const Student *head)int i=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<<"nn没有任何学生数据!n"return;cout<<"nntt各门课程平均成绩表nn"cout<

35、<"tC+t数学t英语n"cout<<ave_cpp/i<<'t'<<ave_math/i<<'t'<<ave_eng/i<<endl;friend void DeleteChain(Student *head)Student *p;while(head)p=head;head=head->next;delete p;friend void ShowMenu(void)cout<<"nn"cout<<"tt

36、*欢迎使用学生成绩管理系统*n"<<"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.退出系统

温馨提示

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

评论

0/150

提交评论