Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a small C++ program the randomly populate a 2D array of 6 Times 6 with dou

ID: 3572498 • Letter: W

Question

Write a small C++ program the randomly populate a 2D array of 6 Times 6 with double numbers between 0.00 - 1000.00 once the array is populated the program will display a menu that implement the following functionalities: Displays the populated array Each row individually with the smallest, largest, and the average in a table format. The smallest with its address, largest with its address, and the average of the whole array. Example Smallest value = 29.328 at address = [0][3] Largest value = 961.991 at address a [0][5] Array average is: ******* The following function generates a random float number between 0.00 - 1000.00 #include #include #include using namespace std; float greater() {float f; sr and(time(NULL)); f = 1000 + (float)rand()/SAND_MAX; return f;} The only code in the main is declaration and function cells Lab is due by 12.09.10 late submission will be penalized

Explanation / Answer

#include<iostream> // header files
#include<ctime>
#include<limits>
using namespace std;
float generator(){ // generators random float numbers
float f;
srand(time(NULL));
f=1000*(float)rand()/RAND_MAX;
return f;
}
void display(float a[6][6]){ // finction to display matrix
cout<<" a[0] a[1] a[2] a[3] a[4] a[5] "<<endl;
for (int i=0;i<6;i++){
cout<<"a["<<i<<"] ";
for(int j=0;j<6;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
}
void displayavgeach(float a[6][6]){ // function find smallest largest and avg of each row
float s,l;
cout<<" a[0] a[1] a[2] a[3] a[4] a[5] smallest largest average"<<endl;
for (int i=0;i<6;i++){
cout<<"a["<<i<<"] ";
for(int j=0;j<6;j++)
cout<<a[i][j]<<" ";
s=l=a[i][0];
float avg,sum=0.0;
for(int j=1;j<6;j++){
if(s>a[i][j])
s=a[i][j];
if(l<a[i][j])
l=a[i][j];
sum=sum+a[i][j];
}
avg=sum/6;
cout<<s<<" "<<l<<" "<<avg<<endl;
}
}
void displayavg(float a[6][6]){ // function fing smallest largest and average for entire matrix
float s,l;
float avg,sum=0.0;
cout<<"smallest largest average"<<endl;
s=l=a[0][0];
for (int i=0;i<6;i++){
for(int j=0;j<6;j++){
if(s>a[i][j])
s=a[i][j];
if(l<a[i][j])
l=a[i][j];
sum=sum+a[i][j];
}
}
avg=sum/6;
cout<<s<<" "<<l<<" "<<avg<<endl;
}
int main(){
float a[6][6];
for (int i=0;i<6;i++)
for(int j=0;j<6;j++)
a[i][j]=generator();
cout<<"1. Display the array"<<endl;
cout<<"2. Display the array with largest smallest and avg of each row"<<endl;
cout<<"3. Display the array's largest smallest and average"<<endl;
int ch;
cin>>ch;
switch(ch){
case 1: display(a);
break;
case 2: displayavgeach(a);
break;
case 3: displayavg(a);
break;
default: system("pause");
}
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote