Write a program that has a class Train with data members seats_first_class, seats_second_class and seats_ac_2tier and member functions to set and display data. Derive a class Reservation that has data members booked_first_class, booked_second_class and booked_ac_2tier and functions to book and cancel tickets and display status.
#include <iostream>
using namespace std;
class Train{
protected:
int seats_first_class;
int seats_second_class;
int seats_ac_2tier;
public:
void setData(){
cout<<"\nEnter seats first class: ";
cin>>seats_first_class;
cout<<"\nEnter seats second class: ";
cin>>seats_second_class;
cout<<"\nEnter seats ac 2 tier: ";
cin>>seats_ac_2tier;
}
void displayData(){
cout<<"seats first class"<< seats_first_class<<endl;
cout<<"seats second class"<<seats_second_class<<endl;
cout<<"seats ac 2 tier"<< seats_ac_2tier<<endl;
}
};
class Reservation:public Train{
private:
int booked_first_class;
int booked_second_class;
int booked_ac_2tier;
public:
void bookSeat(){
cout<<"\nyou have booked the seat";
}
void cancelSeat(){
cout<<"\nyou have cancelled the seat";
}
void display(){
cout<<booked_first_class;
cout<<booked_second_class;
cout<<booked_ac_2tier;
}
};
int main()
{
Train t;
t.setData();
t.displayData();
Reservation r;
r.bookSeat();
r.cancelSeat();
r.display();
return 0;
}
Comments
Leave a comment