已阅读5页,还剩23页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
面向对象的程序设计课程设计报告姓 名: 学 号: 班 级: 院 系: 数学与计算机学院 日 期: 2015.1.3 1. 课程题目 题目1:通过组合和派生构成新的类本设计题目的任务是使用Point类产生Line类。分别通过组合类及派生类两种方法实现,并要求分别给出使用类模板实现的程序。本设计题的目的是使学生掌握在不同的实现方法中,如何设计相应的构造函数和拷贝构造函数,进一步理解程序调用它们及析构函数的执行顺序,掌握组合类和派生类。另外本设计题目要让学生进一步掌握和理解类模板的技术及其实现方法。题目2:成绩管理系统 输入一个班级的学生基本信息(包括学号,姓名,性别,科目),对N门考试的成绩进行管理(例N=5) 要求 l 用户录入每个学生每门课程的分数; l 能够计算每个学生的各门功课总分和平均分,并按总分将成绩排序,显示每个学生的总分和排名; l 计算全班各门功课的平均分,显示每门课程中低于平均分的每一个学生的学号,姓名,性别,科目,成绩等信息; l 显示每门科目中,成绩在90分以上的学生信息。另外还输出每门科目中不及格的学生信息; l 能按姓名或者学号查找,增加,删除和保存各个学生的信息。2. 设计分析题目1:point1,point2作为point类的对象,两个点确定一条直线。题目2:3. 代码设计题目一:A:组合类#include #include using namespace std; template class Point protected: T x; T y; public : Point(); Point(T,T); Point(Point &); Point(); void setX(T); T getX(); void setY(T); T getY(); void displayPoint(); ; template Point:Point() x=0; y=0; coutPoint 类默认构造函数!endl; template Point:Point(T x,T y) this-x=x; this-y=y; coutPoint 类带参构造函数!endl; template Point:Point(Point &newPoint) this-x=newPoint.x; this-y=newPoint.y; coutPoint 类拷贝构造函数!endl; template Point:Point() coutPoint 类析构函数!endl; template void Point:setX(T x) this-x=x; template T Point:getX() return this-x; template void Point:setY(T y) this-y=y; template T Point:getY() return this-y; template void Point:displayPoint() cout (x,y)endl; template class Line private: Point point1; Point point2; public: Line(); Line(Point,Point); Line(T,T,T,T); Line(Line &); Line(); void setPoint1(Point); Point getPoint1(); void setPoint2(Point); Point getPoint2(); void displayLine(); T length(); ; template Line:Line() coutLine类默认构造函数!endl; template Line:Line(Point p1,Point p2) this-point1=p1; this-point2=p2; coutLine类带参构造函数!endl; template Line:Line(T x1,T y1,T x2,T y2):point1(x1,y1),point2(x2,y2) coutLine类构造函数!endl; template Line:Line(Line &line):point1(line.point1),point2(line.point2) coutLine类拷贝构造函数!endl; template Line:Line() coutLine类析构函数!endl; template void Line:setPoint1(Point point1) this-point1=point1; template Point Line:getPoint1() return this-point1; template void Line:setPoint2(Point point2) this-point2=point2; template Point Line:getPoint2() return this-point2; template T Line:length() return sqrt(fabs(point1.getX()-point2.getX()*(point1.getX()-point2.getX()+fabs(point1.getY()-point2.getY()*(point1.getY()-point2.getY(); template void Line:displayLine() cout!endl; coutLine直线上两点是:endl; point1.displayPoint(); point2.displayPoint(); coutLine两点之间的距离是:length()endl; cout!endl; ;void main() Line line(2,3,7,7); line.displayLine();B:派生类:#include #include using namespace std; template class Point protected: T x; T y; public : Point(); Point(T,T); Point(Point &); Point(); void setX(T); T getX(); void setY(T); T getY(); void displayPoint(); ; template Point:Point() x=0; y=0; coutPoint 类默认构造函数!endl; template Point:Point(T x,T y) this-x=x; this-y=y; coutPoint 类带参构造函数!endl; template Point:Point(Point &newPoint) this-x=newPoint.x; this-y=newPoint.y; coutPoint 类拷贝构造函数!endl; template Point:Point() coutPoint 类析构函数!endl; template void Point:setX(T x) this-x=x; template T Point:getX() return this-x; template void Point:setY(T y) this-y=y; template T Point:getY() return this-y; template void Point:displayPoint() cout (x,y)endl; template class Line:public Point private: T x1; T y1; public : Line(); Line(T,T); Line(T,T,T,T); Line(Line &); Line(); void setX1(T); T getX1(); void setY1(T); T getY1(); void displayLine(); T length(); ; template Line:Line() coutLine 类的默认构造函数!endl; template Line:Line(T x1,T y1) this-x1=x1; this-y1=y1; coutLine类的带参构造函数!endl; template Line:Line(T x1,T y1,T x ,T y):Point(x,y) this-x1=x1; this-y1=y1; coutLine类的带参构造函数!endl; template Line:Line(Line &newLine):Point(newLine) this-x1=newLine.x1; this-y1=newLine.y1; coutLine类的拷贝构造函数!endl; template Line:Line() coutLine 类的析构函数!endl; template void Line:setX1(T x1) this-x1=x1; template T Line:getX1() return this-x1; template void Line:setY1(T y1) this-y1=y1; template T Line:getY1() return this-y1; template T Line:length() return sqrt(fabs(x-x1)*(x-x1)+fabs(y-y1)*(y-y1); template void Line:displayLine() cout!endl; coutLine直线上两点是:endl; cout (x1,y1)endl; displayPoint(); coutLine两点之间的距离是:length()endl; cout!endl; void main() Line line(2,3,7,7); line.displayLine();题目2:#include#include#includeusing namespace std;class studentpublic:char name20;double maths,Chinese,English,physics,chemistry,average,sum;student()coutstudent的默认构造函数被调用!endl;student(char n20,double m,double C,double e,double p,double c)strcpy(name,n);maths=m;Chinese=C;English=e;physics=p;chemistry=c;coutstudent带参数的构造函数被调用!endl;double getsum()sum=maths+Chinese+English+physics+chemistry;return sum;double getaverage()average=getsum()/5;return average;friend main();main(void)cout请选择您需要的操作:endl; cout操作数据:endl; cout(0)数据录入endl;cout(1)增加人员endl; cout(2)删除人员endl; cout(3)修改数据endl; cout查询数据:endl; cout(4)按总成绩查询endl;cout(5)按姓名查询endl; cout(6)输出所有学生的数据endl; cout成绩排名:endl; cout(7)按总分查询排名endl; cout(8)按数学查询排名endl;cout(9)按语文查询排名endl; cout(10)按英语查询排名endl; cout(11)按物理查询排名endl;cout(12)按化学查询排名endl;coutp; if(p=0&p=12) flag2=1; else cout指令错误!请重新输入:endl; while(flag2=0);doswitch(p)case 0:char c; char name20;double Chinese,maths,English,physics,chemistry; do coutname; coutChinese; coutmaths; coutEnglish; coutphysics;coutchemistry;filej=new ofstream(d:document,ios:ate); *filej姓名:name数学成绩maths语文成绩Chinese英语成绩English物理成绩physics化学成绩chemistryendl;j+;si=new student(name, maths, Chinese, English,physics,chemistry); i+; cout数据录入成功,想继续录入吗(y/n)c; flag2=0;do if(c!=y&c!=n) cout指令错误!请重新输入!c; else flag2=1; while(flag2=0); while(c=y); break; case 1: char name20;double Chinese,maths,English,physics,chemistry; char c; do coutname; coutChinese; coutmaths; coutEnglish; coutphysics;coutchemistry;filej=new ofstream(d:document,ios:ate); *filej姓名:name语文成绩Chinese数学成绩maths外语成绩English物理成绩physics化学成绩chemistryendl; j+; si=new student(name, maths, Chinese, English,physics,chemistry); i+;cout数据录入成功,想继续录入吗?(y/n)c; if(c!=y&c!=n) cout指令错误!请重新输入!c; while(c=y); break; case 2: char name20;bool flag3=0;char c; do cout请输入您要删除的学生姓名:name; for(int h=0;hname)=0) flag3=1;i-; do sh=sh+1; h+; while(h=i); if(flag3=0) cout您要求删除的对象本来就不存在!请检查输入的正确性!; cout要继续删除吗?(y/n)c; if(c!=y&c!=n) cout指令错误!请重新输入!c; while(c=y);break; case 3: char name20;double mat,Chin,Eng,phy,che;flag2=0; char c;do coutname;for(int h=0;hname)=0) flag2=1; coutChin; coutmat; coutEng; coutphy; coutche;sh-maths=mat; sh-Chinese=Chin;sh-English=Eng; sh-physics=phy;sh-chemistry=phy;cout数据修改成功!; if(flag2=0) cout您要修改的学生本来就不存在!请检查重新输入!endl; cout想继续修改吗?(y/n)c; if(c!=y&c!=n) cout指令错误!请重新输入!c; while(c=y); break; case 4: double t;char c; do int flag1=0; cout请输入你要查询学生的总成绩:t;for(int q=0;qgetsum()=t) flag1=1; cout”要查询的学生是:(*sq).nameendl; if(flag1=0) cout对不起,您要查询的学生不存在!endl; cout您想继续查询吗?(y/n)c;if(c!=y&c!=n) cout指令错误!请重新输入!c; while(c=y); break; case 5: char n20;int j=0;char c; do int flag=0; coutn; for(int j=0;ji;j+) if(strcmp(n,(*sj).name)=0) flag=1; cout您要查询的学生是:(*sj).nameendl; cout(*sj).name 语文:(*sj).Chinese 数学:(*sj).maths 英语:(*sj).English 物理:(*sj).physics 化学:(*sj).chemistryendl的总成绩成绩是(*sj).getsum() 平均成绩是:(*sj).getaverage()endl; if(flag=0) cout对不起!您要查询的学生不存在!endl; cout您想继续查询吗?(y/n)c; if(c!=y&c!=n) cout指令错误!请重新输入!c; while(c=y); break; case 6: cout本系统所有学生数据如下:endl; if(i=0) cout管理系统中没有录入数据或者数据已经被删除!endl;for(int k=0;ki;k+) coutk+1姓名:name 语文:Chinese 数学:maths 英语:English 物理:physics 化学:chemistry 总分:(*sk).getsum() 平均分:(*sk).getaverage()endl; break; case 7: int t;student b; cout本系统所以学生排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;ygetsum()getsum() t=y; if(t!=x) b=*sx; *sx=*st; *st=b; if(i=0) cout管理系统中没有录入数据或者数据已经被删除!;for(int k=0;ki;k+) coutk+1 姓名: name语文: Chinese数学: maths 英语: English物理: physics化学: chemistry总分: (*sk).getsum() 平均分: (*sk).getaverage()endl; break; case 8: int t;student b; cout本系统所以学生数学排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;ymaths)maths) t=y; if(t!=x) b=*st; *st=*sx; *sx=b; if(i=0) cout管理系统中没有录入数据或者数据已经被删除!;for(int k=0;ki;k+) coutk+1 姓名: name语文: Chinese数学: maths 英语: English物理: physics化学: chemistry总分: (*sk).getsum() 平均分: (*sk).getaverage()endl;break;case 9: int t;student b; cout本系统所以学生语文排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;yChinese)Chinese) t=y; if(t!=x) b=*st; *st=*sx; *sx=b; if(i=0) cout管理系统中没有录入数据或者数据已经被删除!;for(int k=0;ki;k+) coutk+1 姓名: name语文: Chinese数学: maths 英语: English物理: physics化学: chemistry总分: (*sk).getsum() 平均分: (*sk).getaverage()endl;break;case 10: int t;student b; cout本系统所以学生英语排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;yEnglish)English) t=y; if(t!=x) b=*st; *st=*sx; *sx=b; if(i=0) cout管理系统中没有录入数据或者数据已经被删除!;for(int k=0;ki;k+) coutk+1 姓名: name语文: Chinese数学: maths 英语: English物理: physics化学: chemistry总分: (*sk).getsum() 平均分: (*sk).getaverage()endl;break;case 11: int t;student b; cout本系统所以学生物理排名如下:endl; for(int x=0;xi-1;x+) t=x; for(int y=x+1;yphysics)physics) t=y; if(t!=x) b=*st; *st=*sx; *sx=b; if(i=0) cout
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 手术部位水肿的护理
- 护理教学课件:放射科护理与防护知识
- 护理安全安全风险沟通技巧
- 洗护方法图示资源
- 商贸企业的单据流转及业务流程优化
- 民航法规试卷及答案
- 2026春人教版六年级语文下册必背古诗文言文(原文+译文+默写版)
- 借货还货合同范本
- 协议合同书的区别
- 2026年小区健身器材维护合同协议
- 2026年深圳市盐田区初三二模语文试卷(含答案)
- 2026年甘肃八年级地生会考真题试卷+答案
- 核心素养导向下的小学五年级英语Unit 3 What would you like 大单元教学设计与实施教案
- 英语河北保定市2026届高三年级第一次模拟考试(保定一模)(4.7-4.9)
- 20kV及以下配电网工程预算定额(2022版)全5册excel版
- 2022年温州保安员考试官方指定模拟试题及答案全解
- 骨科护理饮食与营养康复
- 派出所内部卫生制度
- 国企员工行为规范管理制度
- 中学语文课本剧《杜甫诗话》剧本
- 教师论文写作培训课件
评论
0/150
提交评论