第5章习题参考答案.docxVIP

  • 19
  • 0
  • 约6.79千字
  • 约 18页
  • 2020-10-11 发布于天津
  • 举报
PAGE PAGE # / 19 9.假定车可分为货车和客车,客车又可分为轿车、面包车和公共汽车。请设 计相应的类层次结构。 说明:可以把轿车、面包车和公共汽车定义为客车类的对象 参考程序: #includeiostream using namespace std; class vehicle { public:// 定义基类 vehicle // 公有函数成员 vehicle(int in_wheels,float in_weight); // 给数据成员初始化 intget_wheels();// 获取车轮数 float get_weight();// 获取汽车重量 void setWeels(int wls); void setWeight(float wt); void display(){ cout 车轮数: wheels 汽车重量: weightendl; } private:// 私有数据成员 int wheels;// 车轮数 float weight;// 表示汽车承重 }; vehicle::vehicle(int in_wheels,float in_weight){ } float vehicle::get_weight(){ } int vehicle::get_wheels(){ return wheels; } void vehicle::s

文档评论(0)

1亿VIP精品文档

相关文档