自考新教材-p243_5_(1)

源程序:

#include <iostream>
using namespace std;

class vehicle
{
public:
int wheels;
float weight;
public:
vehicle(int wheels1, float weight1)
{
wheels = wheels1;
weight = weight1;
}
int get_wheels()
{
return wheels;
}
float get_weight()
{
return weight;
}
void show()
{
cout << "轮胎数:"<<wheels << "," << "车重:"<<weight << endl;
}
~vehicle()
{}
};

class car :public vehicle
{
protected:
int speed_max;
car(int wheels2, float weight2, int speedmax) :vehicle(wheels2, weight2)
{
speed_max = speedmax;
cout << "最大速度:"<<speed_max << endl;
}

~car()
{}
};
class toyota_car :public car
{
private:
double length, width, height;
public:
toyota_car(int wheels3, float weight3, int speedmax3, double length3, double width3, double height3) :car(wheels3, weight3, speedmax3)
{
length = length3;
width = width3;
height = height3;
}
void show3()
{
cout << "车长:"<<length << "," << "车宽:" << width << "," << "车高:" << height << endl;
}
~toyota_car()
{}
};

int main()
{
vehicle ve(4,2.4);
ve.show();
toyota_car tcar(4,2.4,240,4.8,1.85,1.65);

tcar.show3();
system("pause");
return 1;
}

运行结果:

 

posted @ 2020-02-04 19:37  bobo哥  阅读(151)  评论(0编辑  收藏  举报