#include<iostream.h>
#include<conio.h>
class Train
{
int number; //Train number
int seat_1; // Total seat in 1st class
int seat_2; // Total seat in 2nd class
int seat_3; // Total seat in 3rd class
public :
Train(int i, int j, int k, int m)
{
int number = i;
int seat_1 = j;
int seat_2 = k;
int seat_3 = m;
}
// access functions
int getnum(void)
{
return number;
}
int getseat_1(void)
{
return seat_1;
}
int getseat_2(void)
{
return seat_2;
}
int getseat_3(void)
{
return seat_3;
}
};
class Reservation : public Train
{
int bkd_1; //Seat researved in 1st class
int bkd_2; //Seat researved in 2nd class
int bkd_3; //Seat researved in 3rd class
public:
Reservation(int i, int j, int k, int m) : Train (i, j, k, m)
{
bkd_1=bkd_2=bkd_3=0;
}
void book(int type, int num);
void cancel(int type, int num);
void disp_status(void);
};
void Reservation :: book(int type, int num)
{
switch(type)
{
case '1' : bkd_1 +=num; //add num to bkd_1
break;
case '2' : bkd_2 +=num; //add num to bkd_2
break;
case '3' : bkd_3 +=num; //add num to bkd_3
break;
default: cout<<"Wrong class\n";
}
}
void Reservation :: cancel(int type, int num)
{
switch(type)
{
case '1' : bkd_1 -=num;
break;
case '2' : bkd_2 -=num;
break;
case '3' : bkd_3 -=num;
break;
default: cout<<"Wrong class\n";
}
}
void Reservation :: disp_status(void)
{
cout<<"\t\tTrain Number:"<<getnum()<<"\n";
cout<<"Class\tTotal seats\tReserved\tUnreserved\n";
int val;
val=getseat_1();
cout<<"1\t"<<val<<"\t"<<bkd_1<<"\t"<<val-bkd_1<<"\n";
val=getseat_2();
cout<<"2\t"<<val<<"\t"<<bkd_2<<"\t"<<val-bkd_2<<"\n";
val=getseat_3();
cout<<"3\t"<<val<<"\t"<<bkd_3<<"\t"<<val-bkd_3<<"\n";
}
int main()
{
clrscr();
int num;
cout<<"Enter Train number:\n";
cin>>num;
cout<<"\nEnter total number of seats in 1st class\n";
int s1;
cin>>s1;
cout<<"\nEnter total number of seats in 2nd class\n";
int s2;
cin>>s2;
cout<<"\nEnter total number of seats in 3rd class\n";
int s3;
cin>>s3;
Reservation Tr(num,s1, s2, s3);
char cl_type;
int choice, seats;
do
{
cout<<"\nMain Menu\n";
cout<<"1. Reservation \n";
cout<<"2. Cancellation \n";
cout<<"3. Display status \n";
cout<<"4. Exit\n";
cout<<"Enter your choice :";
cin>>choice;
cout<<"\n";
switch(choice)
{
case 1 : cout<<"Which class? (1/2/3):";
cin>>cl_type;
cout<<"\nHow many seats?";
cin>>seats;
cout<<"\n";
Tr.book(cl_type, seats);
break;
case 2 : cout<<"Which class? (1/2/3):";
cin>>cl_type;
cout<<"\nHow many seats?";
cin>>seats;
cout<<"\n";
Tr.cancel(cl_type, seats);
break;
case 3 : Tr.disp_status();
break;
case 4 : break;
default : cout<<"Wrong choice!!\n";
}; // end of switch
}while(choice>=1 && choice <=3);
getch();
return 0;
}// end of main()
|
|

A railway reservation counter needs to computerize its reservation process. Using the following information write C++ Program to do so. |
|
| |
|
|
|
|