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

How would Chap 7, PC #18 in Starting out with C++ 6th ed. look if I were to use

ID: 3621771 • Letter: H

Question

How would Chap 7, PC #18 in Starting out with C++ 6th ed. look if I were to use this data? Our book doesn't have random number generator into a 2d array but its something I am sure I need to understand for the final.

-------------------------------------------------
Output should look like:

The seed value for random number generator is: 101021

Column 1 2 3 4 5 6 7 8 9 10
----- ----- ----- ----- ----- ----- ----- ----- ----- -----
Row 1: 25.0 3.3 87.1 37.4 84.5 56.7 31.8 48.1 54.0 33.3
Row 2: 43.2 28.9 96.7 0.6 72.2 5.9 49.1 34.3 50.0 18.6
Row 3: 49.1 38.1 77.2 76.0 14.2 0.4 47.7 32.4 2.4 23.4
Row 4: 10.8 20.5 67.7 43.7 40.5 67.0 77.1 26.6 32.0 97.0
Row 5: 83.2 22.4 81.0 14.5 16.4 27.6 40.2 18.8 68.0 71.1
Row 6: 9.7 97.4 90.3 90.1 86.1 33.1 53.1 17.5 20.0 27.7
Row 7: 31.6 90.7 21.2 16.4 91.7 24.9 47.4 31.0 35.9 65.8
Row 8: 74.0 56.1 67.4 12.5 31.1 32.4 9.7 83.4 10.9 10.8

The Total for all the elements in this array is: 3517.6
The Average of all the elements in this array is: 44.0

The sum of each row is:
Row 1: 461.2
Row 2: 399.5
Row 3: 360.9
Row 4: 482.9
Row 5: 443.2
Row 6: 525.0
Row 7: 456.6
Row 8: 388.3

The sum of each column is:
Col 1: 326.6
Col 2: 357.4
Col 3: 588.6
Col 4: 291.2
Col 5: 436.7
Col 6: 248.0
Col 7: 356.1
Col 8: 292.1
Col 9: 273.2
Col 10: 347.7

The highest and lowest of each row is:
Row 1: 87.1 3.3
Row 2: 96.7 0.6
Row 3: 77.2 0.4
Row 4: 97.0 10.8
Row 5: 83.2 14.5
Row 6: 97.4 9.7
Row 7: 91.7 16.4
Row 8: 83.4 9.7

The highest and lowest of each column is:
Col 1: 83.2 9.7
Col 2: 97.4 3.3
Col 3: 96.7 21.2
Col 4: 90.1 0.6
Col 5: 91.7 14.2
Col 6: 67.0 0.4
Col 7: 77.1 9.7
Col 8: 83.4 17.5
Col 9: 68.0 2.4
Col 10: 97.0 10.8

The highest value in all the elements in this array is:
97.4 which is located in position [6][2]

The lowest value in all the elements in this array is:
0.4 which is located in position [3][6]

Column 1 2 3 4 5 6 7 8 9 10
----- ----- ----- ----- ----- ----- ----- ----- ----- -----
Row 1: 25.0 3.3 87.1 37.4 84.5 56.7 31.8 48.1 54.0 33.3
Row 2: 43.2 28.9 96.7 0.6 72.2 5.9 49.1 34.3 50.0 18.6
Row 3: 49.1 38.1 77.2 76.0 14.2 0.4 47.7 32.4 2.4 23.4
Row 4: 10.8 20.5 67.7 43.7 40.5 67.0 77.1 26.6 32.0 97.0
Row 5: 83.2 22.4 81.0 14.5 16.4 27.6 40.2 18.8 68.0 71.1
Row 6: 9.7 97.4 90.3 90.1 86.1 33.1 53.1 17.5 20.0 27.7
Row 7: 31.6 90.7 21.2 16.4 91.7 24.9 47.4 31.0 35.9 65.8
Row 8: 74.0 56.1 67.4 12.5 31.1 32.4 9.7 83.4 10.9 10.8


------------------------------------------------------------------------------


Lets say just use these prototypes as a guide:


void Fill2DArray( const double ary[] [MaxCols] );
(For this function generate a random number between 0 and 999 (inclusive), then divide the number by 10.0 and store the values in the array. [Your array will be filled with numbers from 0.0 to 99.9.])
void Print2DArray( const double ary[] [MaxCols] );
double GetTotal( ); (use get row total function to do some of the work)
double GetAverage( );
double GetRowTotal (const double ary[][MaxCols], int theRow );
double GetColumnTotal( fill in the former parameter list);
double GetHighestInRow( const double ary[MaxCols], int theRow );
double GetLowestInRow( fill in the former parameter list);
double GetHighestInCol( fill in the former parameter list);
double GetLowestInCol(fill in the former parameter list );
double GetHighest( const double ary[][MaxCols], int theRow );
double GetLowest( );


Explanation / Answer

please rate - thanks

please change your user name so I know who you are, and message me it

#include <iostream>
#include <cstdlib>
#include<iomanip>
#define NROW 8
#define MaxCols 10
using namespace std;
void Fill2DArray( double [] [MaxCols] );
void Print2DArray( const double [] [MaxCols] );
double getTotal(double[][MaxCols]);
double getRowTotal(double[][MaxCols],int);
double getColumnTotal(double[][MaxCols],int);
double getAverage(double);
double getLowestInRow(double[][MaxCols],int);
double getHighestestInRow(double[][MaxCols],int);
double getLowestInCol(double[][MaxCols],int);
double getHighestInCol(double[][MaxCols],int);
double GetHighest( const double[][MaxCols], int&,int& );
double GetLowest( const double[][MaxCols], int&,int&);
int main ()
{int i,j;
double val;
double avg;
double num[NROW][MaxCols];
Fill2DArray(num);
Print2DArray(num);
val=getTotal(num);
cout<<"The Total for all the elements in this array is: "<<val<<endl;
cout<<"The Average of all the elements in this array is: "<<getAverage(val)<<endl;
cout<<"The sum of each row is: ";
for(i=0;i<NROW;i++)
cout<<"Row "<<i+1<<": "<<setprecision(1)<<fixed<<getRowTotal(num,i)<<endl;     
cout<<"The sum of each column is: ";
for(i=0;i<MaxCols;i++)
cout<<"Col "<<i+1<<": "<<setprecision(1)<<fixed<<getColumnTotal(num,i)<<endl;     
cout<<"The highest and lowest of each row is: ";
for(i=0;i<NROW;i++)
cout<<"Row "<<i+1<<": "<<setprecision(1)<<fixed
       <<getHighestestInRow(num,i)<<" "<<getLowestInRow(num,i)<<endl;     
cout<<"The highest and lowest of each column is:: ";
for(i=0;i<MaxCols;i++)
cout<<"Row "<<i+1<<": "<<setprecision(1)<<fixed
       <<getHighestInCol(num,i)<<" "<<getLowestInCol(num,i)<<endl;
val=GetHighest(num,i,j);
cout<<"The highest value in all the elements in this array is:"<<
      val<<" which is located in position ["<<i+1<<"]["<<j+1<<"] ";
val=GetLowest(num,i,j);
cout<<"The lowest value in all the elements in this array is: "<<
      val<<" which is located in position ["<<i+1<<"]["<<j+1<<"] ";
       
system("pause");
}
double GetHighest( const double ary[][MaxCols], int& r,int& c )
{int i,j;
double val;
r=0;c=0;
for(i=0;i<NROW;i++)
   for(j=0;j<MaxCols;j++)
       {
       if(ary[i][j]>ary[r][c])
           {r=i;
           c=j;
           val=ary[i][j];
          }
        }  
return val;
                
}
double GetLowest( const double ary[][MaxCols], int& r,int& c)
{int i,j;
double val;
r=0;c=0;
for(i=0;i<NROW;i++)
   for(j=0;j<MaxCols;j++)
       {if(ary[i][j]<ary[r][c])
           {r=i;
           c=j;
           val=ary[i][j];
           }
         }  
return val;
    
}    
void Print2DArray( const double ary[] [MaxCols] )
{int i,j;
cout<<"The Matrix Column";
for(i=1;i<=MaxCols;i++)
cout<<setw(7)<<i;
cout<<"           ";
for(i=1;i<=MaxCols;i++)
    cout<<" -----";
cout<<endl;
for(i=0;i<NROW;i++)
   {cout<<"Row "<<i+1<<":   ";
   for(j=0;j<MaxCols;j++)
       cout<<setw(7)<<setprecision(1)<<fixed<<ary[i][j];
    cout<<endl;
    }
}
void Fill2DArray( double ary[] [MaxCols] )
{srand(101021);
int i,j;
for(i=0;i<NROW;i++)
    for(j=0;j<MaxCols;j++)
         ary[i][j]=rand()%1000/10.;
}

double getTotal(double r[][MaxCols])
{int i,j;
double val=0;
for(i=0;i<NROW;i++)
     for(j=0;j<MaxCols;j++)
   val+=r[i][j];
return val;
}
double getHighestestInRow(double num[][MaxCols],int n)
{int i;
double val=0;
val=num[n][0];
for(i=1;i<MaxCols;i++)
   if(num[n][i]>val)
      val=num[n][i];
return val;
}
double getHighestInCol(double num[][MaxCols],int n)
{int i;
double val=0;
val=num[0][n];
for(i=1;i<NROW;i++)
   if(num[i][n]>val)
      val=num[i][n];
return val;
}
double getAverage(double t)
{return (double)t/(NROW*MaxCols);
}
double getLowestInRow(double num[][MaxCols],int n)
{int i;
double val=0;
val=num[n][0];
for(i=1;i<MaxCols;i++)
   if(num[n][i]<val)
      val=num[n][i];
return val;
}
double getLowestInCol(double num[][MaxCols],int n)
{int i;
double val=0;
val=num[0][n];
for(i=1;i<NROW;i++)
   if(num[i][n]<val)
      val=num[i][n];
return val;
}
double getRowTotal(double num[][MaxCols],int n)
{int i;
double val=0;
for(i=0;i<MaxCols;i++)
   val+=num[n][i];
return val;
}
double getColumnTotal(double num[][MaxCols],int n)
{int i;
double val=0;
for(i=0;i<NROW;i++)
   val+=num[i][n];
return val;
}

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