5-1.txt

来自「对卡车和小汽车的重量进行判断」· 文本 代码 · 共 65 行

TXT
65
字号
#include<iostream.h>
class Vehicle
{
protected:
	int wheels,weight;
public:
	Vehicle(int wh,int we)
	{
		wheels=wh;
		weight=we;
	}
	void disp()
	{
		cout<<"wheels is:"<<wheels<<endl;
		cout<<"weight is:"<<weight<<endl;
	}
};
class Car:private Vehicle
{
	int passenger_load;
public:
	Vehicle::disp;
	Car(int wh,int we,int pas):Vehicle(wh,we)
	{
		passenger_load=pas;
	}
	void show()
	{
		cout<<"The car's wheels is:"<<wheels<<endl;
		cout<<"The car's weight is:"<<weight<<endl;
		cout<<"The car's passage_load is:"<<passenger_load<<endl;
		cout<<"	"<<endl;
}
};
class Truck:private Vehicle
{
	int passenger_load,pay_load;
public:
	Vehicle::disp;
	Truck(int wh,int we,int pas,int pay):Vehicle(wh,we)
	{
		passenger_load=pas;
		pay_load=pay;
	}
	void show()
	{	
		cout<<"The truck's wheels is:"<<wheels<<endl;
		cout<<"The truck's weight is:"<<weight<<endl;
		cout<<"The truck's passage_load is:"<<passenger_load<<endl;
		cout<<"The truck's pay_load is:"<<pay_load<<endl;
		cout<<"	"<<endl;
}
};
void main()
{
	Car c(4,5000,4); 
	c.disp();
	c.show();
	
	Truck t(6,8000,2,5000);
	t.disp();
	t.show();
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?