Sunday, October 16, 2016

Train Reservation System

Train Reservation System

code
1: #include<iostream>
2: //#include<conio.h>
3: using namespace std;
4: class Train { int number; //train number
5: int seats_1;//total seats in first class
6: int seats_2;// total seats in second class
7: int seats_3;//total seats in third class
8: public:
9: Train(int i,int j, int k, int l)
10: { number = i; seats_1 = j;
11: seats_2=k ; seats_3 = l;
12: }
13: int getnum(void)
14: { return number;}
15: int getseats_1(void)
16: { return seats_1;}
17: int getseats_2(void)
18: { return seats_2;}
19: int getseats_3(void)
20: { return seats_3;}
21: };
22: class Reservation :public Train
23: { int bkd_1;// seats reserved in 1st class
24: int bkd_2;//seats reserved in 2nd class
25: int bkd_3;// seats reserved in 3rd class
26: public:
27: int i,j,k,l;
28: Reservation (int i,int j,int k,int l):Train(i,j,k,l)
29: { bkd_1=bkd_2=bkd_3=0;}
30: void book(char type,int num);
31: void cancel(char type,int num);
32: void disp_status(void);
33: };
34: void Reservation::book(char type,int num)
35: { switch(type)
36: { case'1': bkd_1+=num; //add num to bkd_1
37: break;
38: case'2': bkd_2+=num;//add num to bkd_2
39: break;
40: case'3': bkd_3+=num;//add num to bkd_3
41: break;
42: default: cout<<"wrong class\n";
43: }
44: }
45: void Reservation :: cancel(char type, int num)
46: { switch(type)
47: { case'1':bkd_1-=num;
48: break;
49: case'2':bkd_2-=num;
50: break;
51: default:cout<<"wrong class\n";
52: }
53: }
54: void Reservation::disp_status(void)
55: { cout<<"\t\t Train number:"<<getnum()<<"\n";
56: cout<<"Class\tTotal seats\tReseved\tUn reserved\n";
57: int val;
58: val=getseats_1();
59: cout<<"1\t"<<val<<"\t"<<bkd_1<<"\t"<<val-bkd_1<<"\n";
60: val=getseats_2();
61: cout<<"2\t"<<val<<"\t"<<bkd_2<<"\t"<<val-bkd_2<<"\n";
62: val=getseats_3();
63: cout<<"3\t"<<val<<"\t"<<bkd_3<<"\t"<<val-bkd_3<<"\n";
64: }
65: int main(){
66: //clrscr();
67: int num;
68: cout<<"Enter Train Number:\n";
69: cin>>num;
70: cout<<"\n Enter total Number Of seats in 1st class\n";
71: int s1;
72: cin>>s1;
73: cout<<"\n Enter total number of seats in 2nd class\n";
74: int s2;
75: cin>>s2;
76: cout<<"\n Enter total number of seats in 3rd class\n";
77: int s3;
78: cin>>s3;
79: Reservation Tr(num,s1,s2,s3);
80: char cl_type;
81: int choice,seats;
82: do
83: { cout<<"\n Main Menu\n";
84: cout<<"1.Reservation\n";
85: cout<<"2.Cancellation\n";
86: cout<<"3.Display Status\n";
87: cout<<"4.Exit\n";
88: cout<<"Enter your choice:";
89: cin>>choice;
90: cout<<"\n";
91: switch(choice)
92: { case 1: cout<<"which class?(1/2/3):";
93: cin>>cl_type;
94: cout<<"\n How many seats?";
95: cin>>seats;
96: cout<<"\n";
97: Tr.book(cl_type,seats);
98: break;
99: case 2:cout<<"Which class?(1/2/3):";
100: cin>>cl_type;
101: cout<<"\n How many seats?";
102: cin>>seats;
103: cout<<"\n";
104: Tr.cancel(cl_type,seats);
105: break;
106: case 3:Tr.disp_status();
107: break;
108: case 4:break;
109: default : cout<<"Wrong choice!!\n";
110: }; //end of switch
111: } while(choice>=1&&choice<=3);
112: getchar();
113: return 0;
114: }


Use Case Diagram :


Class Diagram :



 CRC :
  • Passenger
  • Admin / Ticket Clerk
  • Payment
  • Ticket
  • Database
  • Train

Sequence Diagram



Diagram Activity

No comments:

Post a Comment