Answer to Question #214410 in C++ for Hemambar

Question #214410

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.


1
Expert's answer
2021-07-12T07:17:56-0400
#include <iostream>
using namespace std;
class Train
{
    protected :
    int seats_first_class,seats_second_class,seats_ac_2tier;
    public :
   
    void settingSeats()
    {
        cout<<"\nEnter the seats in 1st class \t";
		cin>>seats_first_class;
        cout<<"\nEnter the seats in 2nd class.. \t"; 
		cin>>seats_second_class; cout<<endl;
        cout<<"\nEnter the seats in AC 2 tier.. \t"; 
		cin>>seats_ac_2tier; cout<<endl;
    }
    void DisplayData()
    {
        cout<<"The number of seats in booked by you in 1st class are\t "<<seats_first_class<<endl;
        cout<<"The number of seats in booked by you in 2nd class are \t"<<seats_second_class<<endl;
        cout<<"The number of seats in booked by you in AC 2 tier class are \t"<<seats_ac_2tier<<"\n";
    }
};
//Deriving class Reservation from the Train class
class Reservation : public Train
{
    protected :
    bool booked_first_class=0,booked_second_class=0,booked_ac_2tier=0;
    public :
    bool evaluvate_seat()
    {
        char ch;
        cout<<"Have you booked tickets for 1st class\n"; cin>>ch;
        if(ch='y')
            return booked_first_class=true;
        cout<<"Have you booked tickets for 2nd class\n"; cin>>ch;
        if(ch='y')
            return booked_second_class=true;
        cout<<"Have you booked tickets for AC 2 tier\n"; cin>>ch;
        if(ch='y')
            return booked_ac_2tier=true;
    }
    void statusDisplay(bool a)
    {
        
        if(a==true)
            cout<<"Status : Reserved"<<endl;
        else
            cout<<"Status : Not Reserved"<<endl;
    }
    void cancel_seat()
    {
        int n;
        cout<<"Enter the the type of compartment you want to delete\n"; cin>>n;
        switch(n)
        {
            case 1:
            cout<<"Cancelling your ticket in 1st class"<<endl;
            booked_first_class=false;
            break;
            case 2:
            cout<<"Cancelling your ticket in 2nd class"<<endl;
            booked_second_class=false;
            break;
            case 3:
            cout<<"Cancelling your ticket in AC 2 tier class"<<endl;
            booked_ac_2tier=false;
            break;
        } 
    }
};
//Driver class to test the class 
int main()
{
    Reservation reserve1,reserve12;
    reserve1.settingSeats(); 
    //Setting data for the reserve12
	reserve12.settingSeats();
	//Outputting the data
    reserve1.DisplayData();
    //Outputting the data 
	reserve12.DisplayData();
    
    reserve1.evaluvate_seat(); 
	reserve1.statusDisplay(reserve1.evaluvate_seat());
    reserve12.cancel_seat(); 
	reserve12.statusDisplay(reserve12.evaluvate_seat());
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS