第5章习题考答案.docVIP

  • 60
  • 0
  • 约18.74万字
  • 约 21页
  • 2016-12-14 发布于河南
  • 举报
9. 假定车可分为货车和客车,客车又可分为轿车、面包车和公共汽车。请设计相应的类层次结构。 说明:可以把轿车、面包车和公共汽车定义为客车类的对象 参考程序: #includeiostream using namespace std; class vehicle // 定义基类vehicle { public: // 公有函数成员 vehicle(int in_wheels,float in_weight); // 给数据成员初始化 int get_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){ wheels = in_whe

文档评论(0)

1亿VIP精品文档

相关文档