← Back to Pointers
Question 697
SeatingGrid Built with new int*[]
SeatingGrid Built with new int*[]
Write a classSeatingGridthat 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 readsrows cols k, thenklines ofr cbookings, 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
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.