-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseat_functions.cpp
300 lines (262 loc) · 5.55 KB
/
seat_functions.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include <iostream>
#include "files.h"
#include"seat_classes.h"
#include <string.h>
// Reading room deatils from I/P file
void details :: room_details()
{
infile.open(input_file);
infile>>t_rooms;
for(int i=0; i<t_rooms; i++)
{
infile>>room_no[i]>>rows[i]>>cols[i];
}
}
// Reading branch deatils from I/P file
void details :: rollno_details()
{
infile>>t_branches;
for(int i=0; i<t_branches; i++)
{
infile>>branches[i]>>start_roll[i]>>end_roll[i];
}
}
// Definition of static variables.
int seat_planner :: nxt_branch;
int seat_planner :: nxt_room;
// Exam Details
void seat_planner::exam_details()
{
cout<<"\n1. Enter the Name of the Test: ";
cin>>test_name; //getline(cin, test_name);
cout<<"\n2. Enter Date of the Test (eg 13-03-1990): ";
cin>>exam_date;
cout<<"\n3. Timing (eg 12:00pm 2:00pm): ";
cin>>start_time>>end_time;
}
// To display exam deatils
void seat_planner::exam_display()
{
//outfile.open("seatplan.out");//, ios::app);
outfile<<"\n\n\t\t\t"<<test_name<<" Test\n\n\tDate: "
<<exam_date<<"\n\tTimings: "<<start_time<<" to "<<end_time;
}
void seat_planner :: get_details()
{
room_details();
rollno_details();
infile.close();
}
void seat_planner :: set_room() // Setting room deatils
{
if(nxt_room<t_rooms)
{
row = rows[nxt_room]; // Rows of room
col = cols[nxt_room]; // Columns of room
room = room_no[nxt_room]; // Room name
nxt_room++; // Next room
}
}
void seat_planner :: set_branch() // set_branch of seat_planner
{
if(nxt_branch==0) // Sets start and end roll nos of two branches.
{
start_roll1 = start_roll[nxt_branch];
end_roll1 = end_roll[nxt_branch];
nxt_branch++;
start_roll2 = start_roll[nxt_branch];
end_roll2 = end_roll[nxt_branch];
nxt_branch++;
}
else if(nxt_branch<t_branches)
{
start = start_roll[nxt_branch]; // Start roll no
end = end_roll[nxt_branch]; // End roll no
nxt_branch++; // Increment branch
}
else
{ // When branches are finished
start = 0;
end = 0;
}
}
void seat_planner :: set_rollno()
{
if(start_roll1>end_roll1)
{ // To set start and end roll no. of first branch
set_branch();
start_roll1 = start;
end_roll1 = end;
}
if(start_roll2>end_roll2)
{ // To set start and end roll no. of second branch.
set_branch();
start_roll2 = start;
end_roll2 = end;
}
}
void seat_planner :: seat_plan() // Allocate seats
{
set_branch(); // Calling set_branch()
for(int rm = 0; rm<t_rooms; rm++)
{
set_room(); // Call to set_room() member function
for(x=0; x<col; x++) // For number of columns in a room
{
for(y=0; y<row; y++) // For number of rows in a room
{
set_rollno(); // Call to set_rollno() function
if(y%2==0)
{
seat[rm][x][y] = start_roll1; // seat allocation
start_roll1++;
}
else
{
seat[rm][x][y] = start_roll2;
start_roll2++;
}
}
}
}
if(start_roll1 < end_roll1)
{
fill_space(start_roll1, end_roll1);
}
if(start_roll2 < end_roll2)
{
fill_space(start_roll2, end_roll2);
}
}
void seat_planner :: output() // To display seat plan
{
outfile.open("seatplan.out");//, ios::app);
for(int a=0;a<t_rooms;a++)
{
sum=0;
count_rollno();
exam_display();
outfile<<"\n\n\t\t Room No: "<<room_no[a]<<"\n\n";
for(x=0; x<rows[a]; x++)
{
for(y=0; y<cols[a]; y++)
{
outfile<<branch(seat[a][y][x])<<"-"<<seat[a][y][x]
<<"\t";
}
outfile<<"\n";
}
outfile<<"\n";
for(int i=0; i<t_branches; i++)
{
if(count[i] != 0)
{
outfile<<branches[i]<<":\t"<<count[i]<<endl;
}
}
outfile<<"Total:\t"<<sum;
}
outfile.close();
}
void seat_planner :: valid()
{
int students=0, seats=0;
char choice;
for(x=0; x<t_branches; x++)
{
students += (end_roll[x]-start_roll[x])+1;
}
for(x=0; x<t_rooms; x++)
{
seats += (rows[x] * cols[x]);
}
if(students > seats)
{
system("clear");
cout<<"\nThis strategy is not applicable because of less seats."
<<endl<<"Total Seats: "<<seats<<endl
<<"Total students: "<<students<<endl
<<"More Seats Required: "<<(students-seats)<<endl
<<"Please add more rooms in input file."<<endl;
}
else if(seats > students || seats == students)
{
system("clear");
cout<<"\nStrategy applicable. Press 'Y' to continue."<<endl;
cin>>choice;
switch(choice)
{
case 'Y':
exam_details();
//report_choice();
seat_plan(); // Call to seat_plan() function
cout<<"\n Check seatplan.out file for seat plan."<<endl;
break;
default:
cout<<"\nWrong Choice"<<endl;
break;
}
}
}
string seat_planner :: branch(int rno)
{
string brnch;
for(int i=0; i<t_branches; i++)
{
if(rno>=start_roll[i] && rno<=end_roll[i])
{
brnch = branches[i];
count[i] = count[i] + 1;
sum += 1;
break;
}
}
return brnch;
}
void seat_planner::count_rollno()
{
for(x=0;x<t_branches;x++)
{
count[x]=0;
}
}
void seat_planner :: report_choice()
{
do
{
system("clear");
cout<<"\n1. Enter 1 to generate the report Room-wise"
<<"\n2. Enter 2 to generate the Report Branch-wise\n"
<<"3. Exit\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\n you entered 1";
break;
case 2:
cout<<"\nyou entered 2";
break;
default:
cout<<"Wrong Choice!!!!! Enter your choice again";
}
} while(choice!=1 && choice!=2);
}
//used to fill the remaining seats.
void seat_planner :: fill_space(int start_roll, int end_roll)
{
for(int r=0;r<t_rooms;r++)
{
for(x=0;x<cols[r];x++)
{
for(y=0;y<rows[r];y++)
{
if( seat[r][x][y] == 0 && start_roll <= end_roll)
{
seat[r][x][y]=start_roll;
start_roll++;
}
}
}
}
}