Answer to Question #214007 in C++ for Hemambar

Question #214007

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-13T13:36:10-0400
#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;
}

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