-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcinema.cpp
223 lines (184 loc) · 4.98 KB
/
cinema.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <iostream>
#include <string>
using namespace std;
// Node class to represent each seat in the theater
class Node {
public:
Node* next;
Node* prev;
int seat;
string id;
int status; // 0: Available, 1: Booked
};
// Cinemax class to manage the theater booking system
class Cinemax {
public:
Node* head, *tail, *temp;
Cinemax() {
head = NULL;
}
// Initialize the circular linked list representing the theater seats
void createList();
// Display the current status of all seats in the theater
void display();
// Book a seat with the specified seat number and user ID
void book();
// Cancel the booking for a seat with the specified seat number and user ID
void cancel();
// Display the available seats in the theater
void available();
};
void Cinemax::createList() {
int i = 1;
temp = new Node;
temp->seat = 1;
temp->status = 0;
temp->id = "null";
tail = head = temp;
for (int i = 2; i <= 70; i++) {
Node* p = new Node;
p->seat = i;
p->status = 0;
p->id = "null";
tail->next = p;
p->prev = tail;
tail = p;
tail->next = head;
head->prev = tail;
}
}
void Cinemax::display() {
int r = 1;
temp = head;
int count = 0;
cout << "\n---------------------------------------------\n";
cout << " Cinemax Theater \n";
cout << "---------------------------------------------\n";
while (temp->next != head) {
cout << "S" << (temp->seat < 10 ? "0" : "") << temp->seat << " : ";
if (temp->status == 0)
cout << "|___| ";
else
cout << "|_B_| ";
count++;
if (count % 7 == 0) {
cout << endl;
r++;
}
temp = temp->next;
}
cout << "S" << temp->seat << " :";
if (temp->status == 0)
cout << "|___| ";
else
cout << "|_B_| ";
}
void Cinemax::book() {
int x;
string y;
label:
cout << "\n\nEnter seat number to be booked\n";
cin >> x;
cout << "Enter your ID number\n";
cin >> y;
if (x < 1 || x > 70) {
cout << "Enter correct seat number to book (1-70)\n";
goto label;
}
temp = head;
while (temp->seat != x) {
temp = temp->next;
}
if (temp->status == 1)
cout << "Seat already booked!\n";
else {
temp->status = 1;
temp->id = y;
cout << "Seat " << x << " booked!\n";
}
}
void Cinemax::cancel() {
int x;
string y;
label1:
cout << "Enter seat number to cancel booking\n";
cin >> x;
cout << "Enter your ID\n";
cin >> y;
if (x < 1 || x > 70) {
cout << "Enter correct seat number to cancel (1-70)\n";
goto label1;
}
temp = head;
while (temp->seat != x) {
temp = temp->next;
}
if (temp->status == 0) {
cout << "Seat not booked yet!!\n";
}
else {
if (temp->id == y) {
temp->status = 0;
cout << "Seat Cancelled!\n";
}
else
cout << "Wrong User ID!!! Seat cannot be cancelled!!!\n";
}
}
void Cinemax::available() {
temp = head;
int count = 0;
cout << "\n---------------------------------------------\n";
cout << " Available Seats in Cinemax \n";
cout << "---------------------------------------------\n";
while (temp->next != head) {
cout << "S" << (temp->seat < 10 ? "0" : "") << temp->seat << " : ";
if (temp->status == 0)
cout << "|___| ";
else if (temp->status == 1)
cout << " ";
count++;
if (count % 7 == 0) {
cout << endl;
}
temp = temp->next;
}
if (temp->status == 0) {
cout << "S" << temp->seat << " :";
if (temp->status == 0)
cout << "|___| ";
}
}
int main() {
Cinemax obj;
obj.createList();
int ch;
char c = 'y';
while (c == 'y') {
obj.display();
cout << "\n---------------------------------------------\n";
cout << " CINEMAX MOVIE THEATRE \n";
cout << "---------------------------------------------\n";
cout << "Enter Choice\n1. Current Seat Status\n2. Book Seat \n3. Available Seat\n4. Cancel Seat\n";
cin >> ch;
switch (ch) {
case 1:
obj.display();
break;
case 2:
obj.book();
break;
case 3:
obj.available();
break;
case 4:
obj.cancel();
break;
default:
cout << "Wrong choice input\n";
}
cout << "\nDo you want to perform any other operation? (y/n)\n";
cin >> c;
}
return 0;
}