1: #include<iostream.h>
2: #include<conio.h>
3: #include<stdio.h>
4:
5: struct rail
6: {
7:
8: int seatNo;
9: int isEmpty;
10:
11: }seat[67];
12:
13: void reserve(int n);
14: int arrRowState[15];
15:
16: void main()
17: {
18: for(int i = 0 ; i <67 ; i++)
19: {
20: seat[i].seatNo=(i+1);
21: seat[i].isEmpty=1;
22: }
23: for(i=0 ; i<13 ; i++)
24: arrRowState[i]=5;
25:
26: arrRowState[13]=2;
27: arrRowState[14]=67;
28:
29: char res='y';
30: do
31: {
32: int n;
33: clrscr();
34: cout<<"Enter d no of seats u want to reserve : ";
35: cin>>n;
36: reserve(n);
37: cout<<"
38:
39:
40: Do u want to reserve more seats?";
41: res=getchar();
42: }while(res!='n');
43: }
44:
45: void reserve(int n)
46: {
47: if(n>arrRowState[14])
48: {
49: cout<<"Too large group to accomodate";
50: getch();
51: return;
52: }
53:
54: int flag=0;
55: int seatbook;
56: for(int i = 0 ; flag==0&&i<=13 ; i++)
57: {
58: if(arrRowState[i] >= n)
59: {
60: flag=1;
61: // cout<<"Following Seats Alloted";
62: seatbook=(((i)*5)+(6-arrRowState[i]));
63: for(int j = 0 ; j < n ; j++)
64: {
65: cout<<"
66: "<<seatbook+j<<"
67: ";
68: seat[(seatbook+j)].isEmpty=0;
69: }
70: arrRowState[i]=arrRowState[i]-n;
71: arrRowState[14]=arrRowState[14]-n;
72: }
73: }
74: if(flag==0)
75: {
76: while(n!=0)
77: {
78: int max,rowNo=0;
79: max=arrRowState[0];
80: for( int j = 0 ; j<14 ; j++)
81: {
82: if(arrRowState[j] > max)
83: {
84: max=arrRowState[j];
85: rowNo=j;
86: }
87:
88: }
89: if(n>max)
90: {
91: n=n-max;
92: seatbook=(((rowNo)*5)+(6-arrRowState[rowNo]));
93: arrRowState[rowNo]=arrRowState[rowNo]-max;
94: for( int j = 0 ; j<max ; j++)
95: {
96: cout<<"
97: "<<(seatbook+j)<<"
98: ";
99: seat[(seatbook+j)].isEmpty=0;
100: }
101: }
102: else
103: {
104: reserve(n);
105: n=0;
106: }
107:
108: }
109:
110: }
111:
112: getch();
113: }
Post a Comment