定义一个交通工具类属性成员包括长、宽、高和重量等并从中派生出一个汽车类Car。添加Car类的颜色数据成员访问属性为私有通过SetColor和GetColor成员函数来对颜色进行设置和获取。分别为基类和派生类添加相应的构造函数和析构函数的框架图
基类交通工具类的构造函数和析构函数框架图:
class Vehicle {
private:
float length;
float width;
float height;
float weight;
public:
Vehicle(float len, float wid, float hei, float wei);
~Vehicle();
};
派生类汽车类Car的构造函数和析构函数框架图:
class Car : public Vehicle {
private:
string color;
public:
Car(float len, float wid, float hei, float wei, string col);
~Car();
void SetColor(string col);
string GetColor();
};
原文地址: http://www.cveoy.top/t/topic/hv6R 著作权归作者所有。请勿转载和采集!