码迷,mamicode.com
首页 > 其他好文 > 详细

自考新教材-p243_5_(1)

时间:2020-02-04 20:10:34      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:技术   idt   ace   cout   namespace   protect   tca   运行   dma   

源程序:

#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_(1)

标签:技术   idt   ace   cout   namespace   protect   tca   运行   dma   

原文地址:https://www.cnblogs.com/duanqibo/p/12260744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!