C++多重继承+虚拟继承例题2-创新互联

#include#include#includeusing namespace::std;
class Vehicle
{
public:
	Vehicle();
	int weight;
	Vehicle(int WEIGHT) {
		weight = WEIGHT;
	};
	void setWeight(int);
	
};
void Vehicle::setWeight(int WEIGHT)
{
	weight = WEIGHT;
}
Vehicle::Vehicle(){}
class Car :virtual public Vehicle
{
public:
	Car();
	int aird;
	Car(int WEIGHT, int AIRD) :Vehicle(WEIGHT) {
		aird = AIRD;
	};
	void setAird(int);
	
};
Car::Car(){}
void Car::setAird(int AIRD)
{
	aird = AIRD;
}
class Boat:virtual public Vehicle
{
public:
	Boat();
	double tonnage;
	Boat(int WEIGHT, double TONNAGE) :Vehicle(WEIGHT) { tonnage = TONNAGE; };
	void setTonnage(double);
	
};
Boat::Boat() {}
void Boat::setTonnage(double TONNAGE)
{
	tonnage = TONNAGE;
}
class AmphibianCar :public Car, public Boat
{
public:
	AmphibianCar();
	AmphibianCar(int WEIGHT, int AIRD, double TONNAGE) :Vehicle(WEIGHT), Car(WEIGHT, AIRD), Boat(WEIGHT, TONNAGE) {};
	void display1() {
		cout<< "init Vehicle"<< endl;
		cout<< "init car"<< endl;
		cout<< "init Boat"<>WEIGHT >>AIRD >>TONNAGE;
	cin >>WEIGHT1 >>AIRD1 >>TONNAGE1;
	AmphibianCar Car1(WEIGHT, AIRD, TONNAGE);
	Car1.display1();
	Car1.setWeight(WEIGHT1);
	Car1.setAird(AIRD1);
	Car1.setTonnage(TONNAGE1);
	Car1.display2();
	return 0;
}

学院的题目,感觉还是挺简单的,但总感觉我的实现思路不像是学院要求的思路。大概跟上一题差不太多,但是我不懂输出reset是为了干什么。题目是水陆两用汽车类。

10年的新化网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整新化建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“新化网站设计”,“新化网站推广”以来,每个客户项目都认真落实执行。

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


本文标题:C++多重继承+虚拟继承例题2-创新互联
网页链接:http://scyanting.com/article/dsggdi.html