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

Starting Out With C++ From Control Structures through Objects, Chapter 7, Progra

ID: 3622250 • Letter: S

Question

Starting Out With C++ From Control Structures through Objects, Chapter 7, Programming Challenge 18, 2d Array Operations sixth edition

Here is the problem:

Write a program that creates a two-dimensional array initialized with test data. Use any data type you wish. The program should have the following functions:

getTotal This function should accept a two-dimensional array as its argument and return the total of all the values in the array.

getAverage This function should accept a two-dimensional array as its argument and return the average of all the values in the array.

getRowTotal This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the total of the values in the specified row.

getColumnTotal This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The function should return the total of the values in the specified column.

getHighestInRow This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the highest value in the specified row.

getLowestInRow This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the lowest value in the specified row.

The following was given to me as a study guide but I do not understand it. It compiles but I need explanation. Please rework this so that there are explanations for the steps and the letters used as variables are changed to meaningful names. I want to understand this which is why I am asking for all of the explanation.

Additional requests while reworking the solution:

Solution must compile with no errors.

Please include only meaningful names for variables NOT letters. (Example: the following solution contains the letters i, j and a. I do not understand what they stand for.) I’m trying to teach myself so this is my only source for instruction.

Please include explanations for steps.

Thanks for your time. 

#include<iostream>
#include <conio.h>
using namespace std;
#define row 5
#define col 5

int getTotal(int[][col]);
double getAverage(int[][col]);
int getRowTotal(int[][col],int);
int getColumnTotal(int[][col],int);
int getHighestRow(int[][col],int);
int getLowestRow(int[][col],int);

int main()
{int n=2;
int mat[row][col]={1,2,3,4,5,
                                      6,7,8,9,10,
                                      11,12,13,14,15,
                                      16,17,18,19,20,

                                      21,22,23,24,25};

cout<<"The total of all the values of the array is: "<<getTotal(mat)<<endl;
cout<<"the average of all the values in the array is: "<<getAverage(mat)<<endl;
cout<<"The total of row "<<n<<" is: "<<getRowTotal(mat,n)<<endl;
cout<<"The total of column "<<n<<" is: " <<getColumnTotal(mat,n) <<endl;
cout<<"The highest element of row "<<n<<" is: "<<getHighestRow(mat,n)<<endl;
cout<<"The lowest element of row "<<n<<" is: "<<getLowestRow(mat,n)<<endl;
_getch();
return 0;

int getTotal(int a[][col])
   {int i,j,sum=0;
    for(i=0;i<row;i++)
       for(j=0;j<col;j++)
          sum+=a[i][j];
return sum;
}
double getAverage(int a[][col])
    {int sum=getTotal(a);
        return(double)sum/(row*col);
    }
int getRowTotal(int a[row][col],int n)
   {int i,sum=0;
   for(i=0;i<col;i++)
       sum+=a[n][i];
   return sum;
   }
int getColumnTotal(int a[][col],int n)
   {int i,sum=0;
   for(i=0;i<row;i++)
       sum+=a[i][n];
   return sum;
   }
int getHighestRow(int a[][col],int n)
   {int i,high;
     high=a[n][0];
     for(i=1;i<col;i++)
        if(a[n][i]>high)
             high=a[n][i];
    return high;
}
int getLowestRow(int a[][col],int n)
{int i,low;
     low=a[n][0];
     for(i=1;i<col;i++)
        if(a[n][i]<low)
             low=a[n][i];
    return low;
}

 

Explanation / Answer

Dear, Here is the code with formatted included comments to almost each line of code //Header file section #include #include using namespace std; //Global declaration #define row 4 #define col 5 //function prototypes int getTotal(int[][col]); double getAverage(int[][col]); int getRowTotal(int[][col],int); int getColumnTotal(int[][col],int); int getHighestRow(int[][col],int); int getLowestRow(int[][col],int); int main() { //Variable declaration int n=2; //declaring an matrix int array[row][col]={1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15, 16,17,18,19,20}; //outpputing data cout
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