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 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 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;i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started