-
Notifications
You must be signed in to change notification settings - Fork 0
/
C-20.cpp
149 lines (141 loc) · 3.36 KB
/
C-20.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
#include <iostream>
using namespace std;
struct node
{
int seatc, seatr;
string status;
struct node *next, *prev;
} *head[10], *last[10];
class ticket
{
public:
ticket()
{
for (int j = 0; j < 10; j++)
{
head[j] = last[j] = NULL;
struct node *temp;
for (int i = 1; i <= 7; i++)
{
temp = create_node(i, j + 1);
if (head[j] == last[j] && head[j] == NULL)
{
head[j] = last[j] = temp;
head[j]->next = last[j]->next = NULL;
head[j]->prev = last[j]->prev = NULL;
}
else
{
temp->next = head[j];
head[j]->prev = temp;
head[j] = temp;
head[j]->prev = last[j];
last[j]->next = head[j];
}
}
}
}
node *create_node(int x, int y)
{
struct node *temp;
temp = new (struct node);
if (temp == NULL)
{
cout << "\nMemory not allocated";
return 0;
}
else
{
temp->seatc = x;
temp->seatr = y;
temp->status = "A";
temp->next = NULL;
temp->prev = NULL;
return temp;
}
}
void book()
{
int x, y;
cout << "\nEnter row and column";
cin >> x >> y;
struct node *temp;
temp = head[x - 1];
for (int i = 0; i < 7; i++)
{
if (temp->seatc == y)
{
if (temp->status == "A")
{
temp->status = "B";
}
else
{
cout << "\nSORRY !! Already booked!!";
}
}
temp = temp->next;
}
display();
}
void cancel()
{
int x, y;
cout << "\nEnter row and column to cancel booking : ";
cin >> x >> y;
struct node *temp;
temp = head[x - 1];
for (int i = 0; i < 7; i++)
{
if (temp->seatc == y)
{
if (temp->status == "B")
{
temp->status = "A";
}
else
{
cout << "\nSORRY !! Already unbooked!!";
}
}
temp = temp->next;
}
display();
}
void display()
{
struct node *temp;
for (int j = 0; j < 10; j++)
{
temp = head[j];
for (int i = 0; i < 7; i++)
{
cout << temp->seatr << "," << temp->seatc;
cout << "" << temp->status << "\t";
temp = temp->next;
}
cout << "\n";
}
}
};
int main()
{
ticket t;
int ch;
t.display();
do
{
cout << "\n1.Book Ticket \n2.Cancel Booking \n3.EXIT";
cin >> ch;
switch (ch)
{
case 1:
t.book();
break;
case 2:
t.cancel();
break;
}
} while (ch != 3);
return 0;
}