皮卡指的是由轿车的后备箱改造成的卡车似的后厢,可以兼运少量货物。汽车类可以说明为虚
基类,以避免在皮卡类中出现两组汽车类的数据,请与未说明为虚基类的情况对比。
[程序]
# include <iostream>
# include <string>
using namespace std;
class automobilel
protected:
string model;
double cylinders_capability;
int wheels;
double price:
automobile(string mod= "#", double cl=0,int wh=4, double pr=0)1
model =mod;
cylinders_capability = cl;
wheels = wh:
price = pr;
/型号
//排量
//轮数
//价格
publie:
void display( )
cout << “汽车型号:” << model << '\t' << “排量:" << cylinders_capability << "升" << endl;
cout << "轮数:” << wheels << '\t' << “价格:" << price << endl;
-
class car : public virtual automobilel
protected:
int seats:
int safeguards;
public:
car(string mod= "#", double cl=0, int wh=4, double pr=0,int st=5,int
saf=0):automobile(mod,cl, wh,pr);
seats=st;
safeguards =saf;
void display( )
automobile: :display();
cout << “座位数:” << seats << '\t' << “保护措施数量 :<< safeguards << endl;
//座位数
//保护措施数量