Create a Base class Train containing protected data members as Train_no, Train_Name. Derive a class Route (Route_id, Source, Destination) from Train class. Also derive a class Reservation(Number_Of_Seats, Train_Class, Fare, Travel_Date) from Route. Write a C++ program to perform following necessary functions : i. Enter details of ‘n’ reservations ii. Display details of all reservations iii. Display reservation details of a specified Train class

//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;

#include<conio.h>
#include<iostream.h>
class train
{
   protected:
   int tno;
   char name[10]; // tno=train no , name=train name
   public:
   void acc()
   {
    //accept information realted to train
   cout<<"\nEnter train no: ";
   cin>>tno;
   cout<<"\nEnter train name: ";
   cin>>name;
   }
};
class route: public train //inheriate class route 
{
   public:
   int rid;
   char s[10],d[10]; // rid= train id , s=source , d=destination
   void ac()
   {
      cout<<"\nEnter train id: ";
      cin>>rid;
      cout<<"\nEnter train source: ";
      cin>>s;
      cout<<"\nEnter destination: ";
      cin>>d;
   }
};
class reser: public route  //inheriate class reser
{
public:
   int  nos,fare,dd,mm,yyyy; //nos=no of seats , dd=date mm=month yyyy=year
   char clas[10];
   void a()
   {
      cout<<"\nEnter no of seats: ";
      cin>>nos;
      cout<<"\nEnter train class: ";
      cin>>clas;
      cout<<"\nEnter date(dd mm yyyy): ";
      cin>>dd>>mm>>yyyy;
   }
   void dis()
   {
       // displaying all information
      cout<<"\ntrain no\t\t:\t"<<tno;
      cout<<"\ntrain name\t\t:\t"<<name;
      cout<<"\ntrain id\t\t:\t"<<rid;
      cout<<"\ntrain source\t\t:\t"<<s;
      cout<<"\ntrain destination\t: \t"<<d;
      cout<<"\nno of seats\t\t:\t"<<nos;
      cout<<"\ntrain class\t\t:\t"<<clas;
      cout<<"\ntrain date\t\t:\t"<<dd<<"/"<<mm<<"/"<<yyyy<<"\n";
   }
};
int main()
{
   int i,s;
   reser r[20]; //create instance of reser
   cout<<"Enter how many details you want to enter: ";
   cin>>s;
   for(i=0;i<s;i++)
   {
    r[i].acc(); 
    r[i].ac();
    r[i].a();
   }
   for(i=0;i<s;i++)
   {
    r[i].dis();
   }
   getch();
   return(0);
}

0 Comments