c++编程题

c++编程题

ID:47426716

大小:91.00 KB

页数:10页

时间:2020-01-10

c++编程题_第页
预览图正在加载中,预计需要20秒,请耐心等待
资源描述:

《c++编程题》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、4.1测试一个名为rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积。解:源程序:#includeclassRectangle{public:Rectangle(inttop,intleft,intbottom,intright);~Rectangle(){}intGetTop()const{returnitsTop;}intGetLeft()const{returnitsLeft;}intGetBottom()const{returnitsBottom;}i

2、ntGetRight()const{returnitsRight;}voidSetTop(inttop){itsTop=top;}voidSetLeft(intleft){itsLeft=left;}voidSetBottom(intbottom){itsBottom=bottom;}voidSetRight(intright){itsRight=right;}intGetArea()const;private:intitsTop;intitsLeft;intitsBottom;intitsRight;};Rectan

3、gle::Rectangle(inttop,intleft,intbottom,intright){itsTop=top;itsLeft=left;itsBottom=bottom;itsRight=right;}intRectangle::GetArea()const{intWidth=itsRight-itsLeft;intHeight=itsTop-itsBottom;return(Width*Height);}intmain(){RectangleMyRectangle(100,20,50,80);intAre

4、a=MyRectangle.GetArea();cout<<"Area:"<using namespace std;   class Box  {public:  float L; float getBMJ(){return L*L*6;}  float getTJ(){return 

5、L*L;}  Box(float in){L=in;}  };    void main()  {    Box r(10);   cout<<"边长:10表面积:"<

6、#includeclassvehicle  //汽车类,包含车轮数和车重{ public:  vehicle(int,float);  intget_wheels();  floatget_weight();  voidshow(); protected:  intwheels;    //车轮数  floatweight;   //车重量,单位吨};classcar:privatevehicle  //小车类是汽车类的私有派生类,包含载客数{ public:  car(i

7、ntwheels,floatweight,intpassengers);  intget_passengers();  voidshow(); private:  intpassenger_load;  //额定载客数};classtruck:privatevehicle  //卡车类是汽车类的私有派生类,包含载人数和载重量{ public:  truck(intwheels,floatweight,intpassengers,floatmax_load);  intget_passengers();  voidsho

8、w(); private:  intpassenger_load;  //额定载人数  floatpayload;   //额定载重量,单位吨};vehicle::vehicle(intwl,floatwt){ wheels=wl; weight=wt;}intvehicle::get_wheels(){ returnwheels

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。