04737 c++ 自学考试2019版 第六章课后练习 程序设计题 1

/*
*	04737 c++ 自学考试2019版 第六章课后练习
*	程序设计题 1 
*	需求:将第五章习题中设计的交通工具...... 
*/

#include<iostream>
#include<string>
using namespace std;

//交通工具类 
class Vehicle{
	protected:
		string vehicleCategory;//汽车类别 
	public:
		virtual void ShowV()=0;//展示交通工具信息的纯虚函数 
};

//汽车类 
class AutoMobile:public Vehicle{
	protected:
		string autoMobileCategory;//汽车类别
	public:
		void ShowV(){
			cout<<"工具类别:"<<Vehicle::vehicleCategory<<endl;
			cout<<"汽车类别:"<<autoMobileCategory<<endl;
		}
}; 

//轿车类 
class Car:public AutoMobile{
	protected:
		string carBrandName;//汽车品牌
	public:
		void ShowV(){
			AutoMobile::ShowV(); 
			cout<<"汽车品牌:"<<carBrandName<<endl;
		}
		 
};

//奥迪轿车 
class AudiCar:public Car{
	protected:
		 string seriesProducts;//产品系列
	public:
		AudiCar(string _vehicleCategory,string _autoMobileCategory,string _carBrandName,string _seriesProducts){ 
		vehicleCategory=_vehicleCategory; 
		autoMobileCategory=_autoMobileCategory;
		carBrandName=_carBrandName;
		seriesProducts=_seriesProducts;
		}//构造函数 
		void ShowV(){
			Car::ShowV(); 
			cout<<"产品系列:"<<seriesProducts<<endl;
		}
};




int main(){
	 AudiCar a("私人汽车","豪华轿车","奥迪","奥迪8系");
	 Vehicle *p = &a; 
	 p->ShowV();
}

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页