Assume that vehicle class is defined as base class with price and year of manufacturing. Derive two classes namely bus and truck from base class with bus with seating capacity and truck with loading capacity. Develop classes with necessary member functions to get and put data. Demonstrate its use in main ().
#include<iostream.h>
#include<conio.h>
class vehicle
{
public:
double price;
int year;
void get_basic()
{
cout<<"\nEnter Price of the Vehicle : ";
cin>>price;
cout<<"Enter Year of Manufacture : ";
cin>>year;
}
};
class bus : public vehicle
{
int s_cap;
public:
void get_bus_cap()
{
cout<<"Enter Sitting Capacity : ";
cin>>s_cap;
}
void disp_bus()
{
cout<<endl<<"\n#############################";
cout<<"\nVehicle Type : BUS";
cout<<"\nPrice : "<<price;
cout<<"\nYear of Manfacture : "<<year;
cout<<"\nSitting Capacity : "<<s_cap;
}
};
class truck : public vehicle
{
int l_cap;
public:
void get_truck_cap()
{
cout<<"Enter Loading Capacity(Tons) : ";
cin>>l_cap;
}
void disp_truck()
{
cout<<endl<<"\n#############################";
cout<<"\nVehicle Type : TRUCK";
cout<<"\nPrice : "<<price;
cout<<"\nYear of Manfacture : "<<year;
cout<<"\nLoading Capacity : "<<l_cap<<" Tons";
}
};
void main()
{
clrscr();
bus b;
truck t;
cout<<"BUS : ";
b.get_basic();
b.get_bus_cap();
cout<<"\nTRUCK : ";
t.get_basic();
t.get_truck_cap();
b.disp_bus();
t.disp_truck();
getch();
}
Output :
No comments:
Post a Comment