you are required to write an interactive object oriented pro

you are required to write an interactive object oriented program which performs the following tasks: Reads 16 integers into two-dimensional array. Prints the content of the array. Finds the sum of each row. Finds the average of each row. Finds the sum of each column. Finds the average of each column. Finds sum of the main diagonal (right main diagonal). Prints the results using an appropriate format (see the requirements).
you are required to write an interactive object oriented program which performs the following tasks: Reads 16 integers into two-dimensional array. Prints the content of the array. Finds the sum of each row. Finds the average of each row. Finds the sum of each column. Finds the average of each column. Finds sum of the main diagonal (right main diagonal). Prints the results using an appropriate format (see the requirements).
you are required to write an interactive object oriented program which performs the following tasks: Reads 16 integers into two-dimensional array. Prints the content of the array. Finds the sum of each row. Finds the average of each row. Finds the sum of each column. Finds the average of each column. Finds sum of the main diagonal (right main diagonal). Prints the results using an appropriate format (see the requirements).

Solution

Example: If elements of matrix are:
1 2 3
4 5 6
7 8 9
Output:
Sum of row 1 = 6
Sum of row 2 = 15
...
...
Sum of column 3 = 18

For rows , average =sum/no. of rows

for column, average = sum/no. of column

program:

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

const int numRows = 10;

const int numCols = 10;

int val[numRows][numCols];

int i, j;

double sum = 0, avgR, avgC;

void randNum() // Creates 10x10 array of random nums 0-9

{

    srand(2622); // random seed

    for (i = 0; i < numRows; i++) // Creates random rows

    {

        cout << endl << endl;

        for (j = 0; j < numCols; j++) // Creates random columns

        {

            val[i][j] = rand() % 10;

            cout << setw(6) << val[i][j];

        }

    }

    cout << endl << endl;

}

void randAvg() // finds average of each row and column

{

    for (i = 0; i < numCols; i++)

    {

        sum += val[i][j];

    }

    avgR = sum / numRows;

    cout << \"     \" << avgR << endl;

}

int main() // calls each function

{

    randNum();

    randAvg();

For Finding & Printing Sum Of Diagonal Elements Of Matrix(right main diagonal):

/* Declaration Of Header Files */
# include <iostream.h>
# include <conio.h>

/* Start Of Main Program */
void main()
{
   
       /* Declaration Of Variables */
       int i, j, r = 0, c = 0;
       int a [ 10 ][ 10 ];
       clrscr();

       /* Asking For The Input From User */
       cout << \" Enter Number Of Rows & Columns Of 2D Array [ Matrix ] : \";
       cin >> r >> c ;
      
       // Accepting Values Of 2D Array [ Matrix ]
       cout << \" Enter \" << r * c << \" Values for 2D Array :  \";
       for ( i = 0; i < r; i++ )
       {
                for ( j = 0; j < c; j++ )
                {
                         cin >> a [ i ][ j ];
                }
       }

       // Printing Values Of 2D Array [ Matrix ]
       cout << \" Values Of 2D Array [ Matrix ] Are : \";
       for ( i = 0; i < r; i++ )
       {
                cout << \" \ \";
                for ( j = 0; j < c; j++ )
                {
                         cout << a [ i ][ j ];
                }
       }
/* Source Code For Computing Sum Of Diagonal Elements If & Only If Rows & Columns Are Equal */
sum=0;
if(r==c)
{
   for(i=0; i<r; i++)
   {
      for(j=0; j<c; j++)
      {
         if(i+j==0 || i+j==2 || i+j==4)
         {
            sum=sum+a[i][j];
         }
      }
   }
   /* Printing The Output Onto The Screen/Console */
   cout<<\"\ Sum Of Diagonal Elements Of Array Is : \"<<sum;
}
else
{
   cout<<\" \ Addition Is Not Possible\";
}
getch();
}
/* End Of Main Program */


Output :

Enter Order For Array A : 3 3

Enter 9 Values For Array :
1 2 3 4 5 6 7 8 9

Array A Is :
1 2 3
4 5 6
7 8 9

Sum Of Diagonal Elements Of Array Is : 15

 you are required to write an interactive object oriented program which performs the following tasks: Reads 16 integers into two-dimensional array. Prints the c
 you are required to write an interactive object oriented program which performs the following tasks: Reads 16 integers into two-dimensional array. Prints the c
 you are required to write an interactive object oriented program which performs the following tasks: Reads 16 integers into two-dimensional array. Prints the c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site