第十四周实验内容1

第十四周实验内容1

ID:1971576

大小:202.50 KB

页数:26页

时间:2017-11-14

第十四周实验内容1_第1页
第十四周实验内容1_第2页
第十四周实验内容1_第3页
第十四周实验内容1_第4页
第十四周实验内容1_第5页
资源描述:

《第十四周实验内容1》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、第十四周实验内容:继承与派生1.编程【问题描述】:开发一个名为Vehicle的类的层次体系。创建两个类Taxi和Truck,均以公有模式从类Vehicle中继承而来。Taxi类中应包含一个数据成员说明其是否载客。Truck类应包含一个数据成员说明其是否载货。添加必要的函数来控制和访问类的数据。编写一段测试程序,将Truck对象和Taxi对象打印到屏幕。【实例输出】【程序模板】共7个文件(Vehicle.h、Vehicle.cpp、Taxi.h、Taxi.cpp、Truck.h、Truck.cpp、driver.cpp)//vehicle

2、.h#ifndefVEHICLE_H#defineVEHICLE_H#includeusingnamespacestd;classVehicle{public:Vehicle(constintdoors,constintcylinders,charcolor,doubleinitialFuel,constinttransmission);~Vehicle();voidsetColor(charcolor);voidsetFuelLevel(doubleamount);constchargetColor()const;

3、doublegetFuelLevel()const;constintgetTransmissionType()const;constintgetNumberOfDoors()const;constintgetNumberOfCylinders()const;voidsetClassName(constchar);constchargetClassName()const;voidprintVehicle();private:constintnumberOfDoors;//门的个数constintnumberOfCylinders;//汽缸

4、的个数charvehicleColor;//交通工具的颜色doublefuelLevel;//constinttransmissionType;charclassName;};#endif//vehicle.cpp#include#include#include"vehicle.h"usingnamespacestd;Vehicle::Vehicle(constintdoors,constintcylinders,charcolor,doubleinitialFuel,constinttransmi

5、ssion):numberOfDoors(doors),numberOfCylinders(cylinders),transmissionType(transmission)/实现Vehicle类的构造函数定义/Vehicle::~Vehicle(){delete[]vehicleColor;delete[]className;}voidVehicle::printVehicle(){cout<

6、ers:"<0.0&&amount<=20.0)fuelLevel=amount;elsefuelLevel=5.

7、0;}//callerisresponsiblefordeletingmemoryconstcharVehicle::getColor()const{returnvehicleColor;}doubleVehicle::getFuelLevel()const{returnfuelLevel;}constintVehicle::getTransmissionType()const{returntransmissionType;}constintVehicle::getNumberOfDoors()const{returnnumberOfD

8、oors;}constintVehicle::getNumberOfCylinders()const{returnnumberOfCylinders;}voidVehicle::setClassName(c

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

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

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