0

I have a C++ question regarding inheritance:

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.

This is the code which I have written

https://onlinegdb.com/CTAdFBM_C
#include <iostream>
using namespace std;
class Train
{
    protected :
    int seats_first_class,seats_second_class,seats_ac_2tier;
    public :
    //Train(int a,int b,int c) : seats_first_class(a),seats_second_class(b),seats_ac_2tier(c){}
    //Train() : seats_first_class(0),seats_second_class(0),seats_ac_2tier(0){}
    void Read()
    {
        cout<<"Enter the seats in 1st class..."; cin>>seats_first_class; cout<<endl;
        cout<<"Enter the seats in 2nd class..."; cin>>seats_second_class; cout<<endl;
        cout<<"Enter the seats in AC 2 tier..."; cin>>seats_ac_2tier; cout<<endl;
    }
    void Disp()
    {
        cout<<"The number of seats in booked by you in 1st class are "<<seats_first_class<<endl;
        cout<<"The number of seats in booked by you in 2nd class are "<<seats_second_class<<endl;
        cout<<"The number of seats in booked by you in AC 2 tier class are "<<seats_ac_2tier<<endl;
    }
};
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 status_disp(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;
        } 
    }
};
int main()
{
    Reservation r1,r2;//Train t1,t2;
    r1.Read(); r2.Read();
    r1.Disp(); r2.Disp();
    
    r1.evaluvate_seat(); r1.status_disp(Resevation :: evaluvate_seat());
    r2.cancel_seat(); r2.status_disp(Resevation :: evaluvate_seat());
    return 0;
}

These are the errors i am facing:

main.cpp:76:38: error: ‘Resevation’ has not been declared
  r1.evaluvate_seat(); r1.status_disp(Resevation :: evaluvate_seat());
                                      ^~~~~~~~~~
main.cpp:77:35: error: ‘Resevation’ has not been declared
  r2.cancel_seat(); r2.status_disp(Resevation :: evaluvate_seat());

Edit : I tried to rectify some mistakes but still am not successful in making the code error free. Anyone's help is really appreciable

Andreas Wenzel
  • 22,760
  • 4
  • 24
  • 39
pHeroXoc
  • 31
  • 5
  • 7
    Please edit your question to include your program and the errors as text. Read through how to make a [mcve] for tips. – Retired Ninja Jun 20 '21 at 17:36
  • 1
    The last error in the picture means you promised to return a value from a function but broke your promise. This is undefined behavior and could cause your entire program to malfunction. – drescherjm Jun 20 '21 at 18:00
  • `if(a=true)` is a bug as well. You set `a` to true instead of comparing it to true. Comparison is `==` so you should have written `if (a == true)` instead. – drescherjm Jun 20 '21 at 18:04
  • I tried to edit some part and also added the errors in text form. Can anyone please help me. @drescherjm – pHeroXoc Jun 21 '21 at 06:56
  • 3
    **I am voting to reopen the question because** OP seems to have provided a [mre] and all relevant code and errors now seem properly inserted inside the question as text. – Andreas Wenzel Jun 21 '21 at 14:18
  • 1
    I agree with the reopening. The current error seems to be caused by a typo. Take a close look: `‘Resevation’ has not been declared`, but your class is called `Rese*r*vation` – Lukas-T Jun 21 '21 at 14:22
  • I corrected that error but again some errors are coming This is the edited part of code ``` r1.evaluvate_seat(); r1.status_disp(Reservation :: r1.evaluvate_seat()); r2.cancel_seat(); r2.status_disp(Reservation :: r2.evaluvate_seat()); ``` these are the errors that are appearing main.cpp:76:41: error: ‘r1’ is not a member of ‘Reservation’ r1.evaluvate_seat(); r1.status_disp(Reservation :: r1.evaluvate_seat()); main.cpp:77:38: error: ‘r2’ is not a member of ‘Reservation’ r2.cancel_seat(); r2.status_disp(Reservation :: r2.evaluvate_seat()); – pHeroXoc Jun 22 '21 at 16:45

0 Answers0