Question: C++ Programming Complete the incomplete code for the following findSeats function that returns an integer result. Its purpose is to check whether its first argument,
C++ Programming
Complete the incomplete code for the following findSeats function that returns an integer result. Its purpose is to check whether its first argument, a 2-dimensional integer array of numbers representing seats taken at a theater, contains enough consecutive empty seats (the second argument) on a desired row (the third argument). If the desired number of consecutive empty seats are available, it returns the position in the row of the first available seat in the group. If there are not enough empty seats available, it returns -1. Assume an empty seat is represented by 0 and an occupied seat is represented by 1 in the seats array. The algorithm for the program is to find an empty seat in the desired row, then see if it is the first of n consecutive empty seats. Assume global integer constants ROWS and COLS exist that are the dimensions of the seats array.
int findSeats(int seats[][ ], int empty, int row) { for (int outer = 0; outer < ; outer++) { if (seats[ ][ ] == ) { int consecutive = 0; for (int inner = ; inner < ; inner++) { if (seats[ row ][ inner ] == 0) { ++; } else { break; } } if (consecutive >= ) { return ; } } } return -1; } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
