#include<iostream.h>
/////////////////////////////////
class vehicle
{
public:
vehicle(int w,double r);
void show();
protected:
int wheels;
double range;
};
/////////////////////////////////
class car:virtual public vehicle
{
public:
car(int w,double r,int p=4);
void show();
private:
int passengers;
};
/////////////////////////////////
class truck:virtual public vehicle
{
public:
truck(int w,double r,int p=2,double a=20);
void show();
private:
int passengers;
double weight;
};
/////////////////////////////////
vehicle::vehicle(int w,double r)
{
wheels=w;
range=r;
}
/////
void vehicle::show()
{
cout<<"车轮"<<wheels<<"个\t行程"<<range<<"公里";
}
/////////////////////////////////
car::car(int w,double r,int p):vehicle(w,r)
{
passengers=p;
}
/////
void car::show()
{
cout<<"小车:";
vehicle::show();
cout<<"\t载人="<<passengers<<"位"<<endl;
}
/////////////////////////////////
truck::truck(int w,double r,int p,double a):vehicle(w,r)
{
passengers=p;
weight=a;
}
/////////////////////////////////
void truck::show()
{
cout<<"卡车:";
vehicle::show();
cout<<"\t载人="<<passengers<<"位";
cout<<"\t载重量="<<weight<<"吨"<<endl;
}
/////////////////////////////////
void main()
{
car V1(4,100000.0,3);
car V2(4,120000.0);
truck V3(8,10000.0,3,50.0);
V1.show();
V2.show();
V3.show();
}