Write a program that has a class Train with data members-no_of seats_sleeper, no_ of_seats_2Tier, no_of_seats_3Tier and member functions to set and display data. Derive a class Reservation that has data members-seats_Booked_sleeper, , no_ of_seats_Booked_2Tier, no_of_seats_Booked_3Tier, and a functions to book and cancel tickets, and display status
#include <iostream>
using namespace std;
class Train{
private:
int no_of_seats_sleeper, no_of_seats_2Tier, no_of_seats_3Tier;
public:
void setData(){
cout<<"Enter number of seats sleeper:\n";
int sleaper;
cin>>sleaper;
cout<<"Enter the number of seats in tier 2:\n";
int tier2;
cin>>tier2;
cout<<"Enter the number of seats in tier 3:\n";
int tier3;
cin>>tier3;
no_of_seats_sleeper = sleaper;
no_of_seats_2Tier = tier2;
no_of_seats_3Tier = tier3;
}
void output(){
cout<<"Number of seats in sleeper: "<< no_of_seats_sleeper<<endl;
cout<<"Number of seats in tier 2: "<<no_of_seats_2Tier<<endl;
cout<<"Number of seats in tier 3"<< no_of_seats_3Tier<<endl;
}
void bookSeat(){
cout<<"\nSeat booked successfully\n";
}
void cancelSeat(){
cout<<"\nSeat Cancelled successfully\n";
}
};
class Reservation:public Train{
private:
int seats_Booked_sleeper, no_of_seats_Booked_2Tier, no_of_seats_Booked_3Tier;
public:
void input(){
cout<<"Enter number of seats booked in sleeper:\n";
int sleaper;
cin>>sleaper;
cout<<"Enter the number of seats booked in tier 2:\n";
int tier2;
cin>>tier2;
cout<<"Enter the number of seats booked in tier 3:\n";
int tier3;
cin>>tier3;
seats_Booked_sleeper = sleaper;
no_of_seats_Booked_2Tier = tier2;
no_of_seats_Booked_3Tier = tier3;
}
void display(){
cout<<"Number of seats booked in sleeper: "<< seats_Booked_sleeper<<endl;
cout<<"Number of seats booked in tier 2: "<<no_of_seats_Booked_2Tier<<endl;
cout<<"Number of seats booked in tier 3"<<no_of_seats_Booked_3Tier<<endl;
}
void bookSeat(){
cout<<"\nSeat booked successfully!!";
}
void cancelSeat(){
cout<<"\nSeat Cancelled successfully!!";
}
};
int main(){
}
Comments
Leave a comment