自考新教材-p243_5_
Posted duanqibo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自考新教材-p243_5_相关的知识,希望对你有一定的参考价值。
源程序:
#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;
}
运行结果:
以上是关于自考新教材-p243_5_的主要内容,如果未能解决你的问题,请参考以下文章