forked from CodeWithKartik/BookMyShow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeatingArrangement.cpp
47 lines (46 loc) · 1.35 KB
/
SeatingArrangement.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
#include "SeatingArrangement.h"
SeatingArrangement::SeatingArrangement(int nr, int nc) {
nrows = nr;
ncols = nc;
chairs = new bool*[nr];
for (register int i = 0; i < nr; i++) {
chairs[i] = new bool[nc];
for (register int j = 0; j < nc; j++)
chairs[i][j] = false;
}
}
SeatingArrangement::SeatingArrangement(const SeatingArrangement &cpy) {
nrows = cpy.GetRows();
ncols = cpy.GetCols();
chairs = new bool*[nrows];
for (register int i = 0; i < nrows; i++) {
chairs[i] = new bool[ncols];
for (register int j = 0; j < ncols; j++)
chairs[i][j] = cpy.GetChairs(i,j);
}
}
SeatingArrangement::~SeatingArrangement() {
for (register int i = 0; i < nrows; i++)
delete[] chairs[i];
delete[] chairs;
}
bool &SeatingArrangement::operator()(const int i, const int j) {
if ((i < nrows && i >= 0) && (j < ncols && j >= 0))
return chairs[i][j];
else {
static bool dummy = false;
return dummy;
}
}
void SeatingArrangement::BookChairNo(int i, int j) {
(*this)(i,j) = true;
}
std::ostream& operator<<(std::ostream& os, const SeatingArrangement sa) {
for (register int i = 0; i < sa.GetRows(); i++) {
for (register int j = 0; j < sa.GetCols(); j++) {
os<<sa.GetChairs(i,j);
}
os<<"\n";
}
return os;
}