SeatingGrid Built with new int*[]
mediumQuestion 697Write a class SeatingGrid that owns a two-dimensional seating chart as an array of row pointers, each pointing at its own array of ints.
Private members:
- int** seats;
- int rows;
- int cols;
Public interface used by the hidden driver:
SeatingGrid(int r, int c); // allocate the grid with new int*[r] / new int[c] and set every seat to 0
~SeatingGrid(); // release every row AND the array of row pointers
void book(int r, int c); // mark that seat as 1
int rowCount(int r) const; // how many seats in row r are booked
int totalBooked() const; // how many seats in the whole grid are bookedThe driver reads rows cols k, then k lines of r c bookings, then prints the total followed by one line per row.
For the input:
3 4 5
0 0
0 3
1 2
2 1
2 2the exact output is what is shown in Expected Output.
Free the memory you allocate — this question checks for memory leaks.
Do NOT write a main function.
Expected output
total=5 row 0: 2 row 1: 1 row 2: 2
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.