CJCoding With Joseph
15free / daySign inCreate account

SeatingGrid Built with new int*[]

Write 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 booked
`

The 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 2
``

the 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 — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
3 4 5\n0 0\n0 3\n1 2\n2 1\n2 2\n
This input is automatically fed to your program's stdin
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.