Question: Need help with this C++ program. The code provided works in everyway but I do not know how to make the seats randomly generated instead

Need help with this C++ program. The code provided works in everyway but I do not know how to make the seats randomly generated instead of being entered in by the keyboard. Thanks

Program requirements:

Create a program that will assign a random number to each seat in a classroom. The program should work for a classroom of any size, so your solution must use a 2-dimensional dynamic array. The main program should ask the user for the size of the classroom (number of rows along with number of seats per row) and the largest maximum number to be generated. Numbers generated will be in the range [1..MAX].

The program should continue asking for user input until valid data has been entered. For example, if the user entered 3 rows by 5 students per row and a maximum value of 10, it wouldnt be possible to generate unique numbers for each student. When the data is valid, allocate the space for your 2-D dynamic array.

The program needs to call four functions below the main:

  • One to generate the data and store it in the array. Be sure you dont repeat any numbers
  • Display the data in a tabular format
  • Display the smallest, largest, and mean value
  • Free up the memory that was allocated to the array

Code:

#include #include using namespace std; void getData(int **seats,int rows,int noOfSeats,int MAX); void display(int **seats,int rows,int noOfSeats); void displayMinMaxAvg(int **seats,int rows,int noOfSeats); bool isValidNumber(int **seats,int MAX,int rows,int noOfSeats,int number); int main() { int rows,noOfSeats; int MAX; cout<<"Enter number of rows :"; cin>>rows; cout<<"Enter number of seats :"; cin>>noOfSeats; while(true) { cout<<"Enter Maximum Number :"; cin>>MAX; if(MAX

int** seats = new int*[rows]; for (int i = 0; i < rows; ++i) seats[i] = new int[noOfSeats]; for(int i=0;i

void getData(int **seats,int rows,int noOfSeats,int MAX) { int number; for(int i=0;i>number; if(number<1 || number>MAX) { cout<<"Invalid! Must be a number between 1-"<< MAX <

bool b=isValidNumber(seats,MAX,rows,noOfSeats,number); if(b) { seats[i][j]=number; j++; } else { cout<<"Invalid!"<

bool isValidNumber(int **seats,int MAX,int rows,int noOfSeats,int number) { for(int i=0;i

void displayMinMaxAvg(int **seats,int rows,int noOfSeats) { int min,max; double sum=0,avg=0; min=seats[0][0]; max=seats[0][0]; for(int i=0;iseats[i][j]) min=seats[i][j]; if(max

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!