Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago