#include
#include
using namespace std;
class Vehicle
{
protected:
string colour; //汽车颜色
string License_Plate_Number; //汽车车牌
public:
Vehicle(string col=" ",string LPNum=" "):colour(col),License_Plate_Number(LPNum){}
void display()
{
cout<<"汽车颜色:"<
~Vehicle(){};
};
class Trucks:public Vehicle
{
private:
int truck; //最大载重
string goods; //所载货物
public:
Trucks(string col,string LPNum,int tru,string goo):Vehicle(col,LPNum){truck=tru;goods=goo;}
void Trucksdisplay()
{
display();
cout<<"最大载重量:"<
~Trucks(){}
};
class Publics:public Vehicle
{
private:
string begin_and_end; //客车的起点和终点
public:
Publics(string col,string LPNum,string bae):Vehicle(col,LPNum)
{begin_and_end=bae;}
void Publicsdisplay()
{
display();
cout<<"客车起点和终点:"<
~Publics(){}
};
class Cars:public Publics
{
private:
string carmodel;
int capacity; //轿车最大载客量
public:
Cars(string col,string LPNum,string bae,string cmo,int cap):Publics(col,LPNum,bae)
{carmodel=cmo;capacity=cap;}
void Carsdisplay()
{
Publicsdisplay();
cout<<"轿车型号:"<
~Cars(){}
};
class Vans:public Publics
{
private:
string carmodel;
int vcapacity; //面包车最大载客量
public:
Vans(string col,string LPNum,string bae,string cmo,int vcap):Publics(col,LPNum,bae)
{carmodel=cmo;vcapacity=vcap;}
void Vansdisplay()
{
Publicsdisplay();
cout<<"面包车型号:"<
~Vans(){}
};
class Buss:public Publics
{
private:
string carmodel;
int bcapacity; //公共汽车最大载客量
public:
Buss(string col,string LPNum,string bae,string cmo,int bcap):Publics(col,LPNum,bae)
{carmodel=cmo;bcapacity=bcap;}
void Bussdisplay()
{
Publicsdisplay();
cout<<"公共汽车车型号:"<
~Buss(){}
};
int main()
{
Trucks truck1("yellow","粤A5225",2,"蔬菜");
truck1.Trucksdisplay();
cout<
Cars car1("red","桂B356","起点:柳州。终点:桂林。","宝马",2);
car1.Carsdisplay();
cout<
Vans van1("white","桂c216","起点:联达。终点:阳朔。","五菱",8);
van1.Vansdisplay();
cout<
Buss bus1("green","京A999","起点:北京。终点:桂林。","奔驰大巴",100);
bus1.Bussdisplay();
cout<
return 0;
}
继承啦
class 车
class 货车 : public 车
class 客车 : public 车
class 轿车 : public 客车
class 面包车 : public 客车
class 公共汽车 : public 客车
定义个基类车 class car;
class car
{
//成员表
};
客车作为车的派生类;
客车 class bus:public car
{
//成员表
};
面包车作为客车的派生类;
面包车 class van:public bus
{
//成员表
};
class car//定义基类
{
//成员表
};
class bus:public car//客车作为车的派生类;
{
//成员表
};
class huo:public car//货车作为车的派生类;
{
//成员表
};
class van:public bus//面包车作为客车的派生类;
{
//成员表
};
class sal:public bus//轿车作为客车的派生类;
{
//成员表
};