完整word版-c++课程设计任务书1421813-15.doc
上传人:小沛****文章 上传时间:2024-09-10 格式:DOC 页数:15 大小:129KB 金币:10 举报 版权申诉
预览加载中,请您耐心等待几秒...

完整word版-c++课程设计任务书1421813-15.doc

完整word版-c++课程设计任务书1421813-15.doc

预览

免费试读已结束,剩余 5 页请下载文档后查看

10 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

《面向对象程序设计课程设计》任务书一、课程设计的目的与要求1、教学目的综合运用所学过的知识进行实际程序设计。2、教学要求从课程设计的目的出发,用C++编写简单的的程序,程序要求如下:(1)算法正确,容错性能好;(2)完成从用户需求分析、到上机编程、调试和应用等全过程。二、课程设计的题目、内容及要求Part1:小程序练习(必须全部完成)1函数重载定义重载函数max3用于计算三个数的最大值(参数类型分别为int和double)。#include<iostream>usingnamespacestd;intmax3(inta,intb,intc){if(b>a)a=b;if(c>a)a=c;returna;}doublemax3(doublea,doubleb,doublec){if(b>a)a=b;if(c>a)a=c;returna;}intmain(){intmax3(inta,intb,intc);doublemax3(doublea,doubleb,doublec);inti1,i2,i3,i;cout<<”请输入三个数:”<<endl;cin>>i1>>i2>>i3;i=max3(i1,i2,i3);cout<<"i.max3="<<i<<endl;doubled1,d2,d3,d;cin>>d1>>d2>>d3;d=max3(d1,d2,d3);cout<<"d.max3="<<d<<endl;}2类的组合定义point类,数据成员包括x,y,成员函数包括构造函数,拷贝构造函数和析构函数,以及setx,getx,sety,gety四个属性函数。定义line类,端点由两个point类的对象组成,包括构造函数,析构函数以及计算线段长度的函数getlength。在main函数中,定义line的对象,并输出其长度。#include<iostream>#include<cmath>usingnamespacestd;classpoint{private:intx,y;public:point(intx,inty):x(x),y(y){}point(point&p);intgetx(){returnx;}voidsetx(intx){this->x=x;}intgety(){returny;}voidsety(inty){this->y=y;}~point(){}};point::point(point&p){x=p.x;y=p.y;}classline{private:pointp1,p2;doublelen;public:line(pointpt1,pointpt2);line(line&l);doublegetlen(){returnlen;}~line(){}};line::line(pointpt1,pointpt2):p1(pt1),p2(pt2){doublex=p1.getx()-p2.getx();doubley=p1.gety()-p2.gety();len=sqrt(x*x+y*y);}line::line(line&l):p1(l.p1),p2(l.p2){len=l.len;}intmain(){pointpo1(1,2),po2(3,4);lineline(po1,po2);cout<<"thelengthoflineis:"<<endl;cout<<line.getlen()<<endl;}3对象数组和函数定义student类,数据成员包括姓名name和成绩score,成员函数包括构造函数,拷贝构造函数和析构函数。定义函数voidhighestscore(students[]),输出分数最高的学生姓名和分数。在main函数中定义students[N],调用highestscore函数,输出分数最高的学生姓名和分数。#include<iostream>#include<string>constintN=3;usingnamespacestd;classstudent{private:stringname;intscore;public:student(stringn="",ints=0):name(n),score(s){}student(student&stu){name=stu.name;score=stu.score;}~student(){}friendistream&operator>>(istream&is,student&stu)