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