Question

In: Computer Science

In C++, write a program that creates a two-dimensional array initialized with some integers. Have the...

In C++, write a program that creates a two-dimensional array initialized with some integers. Have the following six functions: Total (total of all values in array), Average (average of values in array), Total of specific row (this needs 2 arguments, the array, like the others, and an integer for the subscript of any row. Total of specific Column (same as row), Max value in Row ( same as previous two, but return the highest value), Minimum Value ( same as previous).

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main()
{   

int i,j,s=0,sum=0;
int x, y;

cout<<"Enter the rows count for your 2- D array \n";
cin>>x;
cout<<endl;

cout<<"Enter the columns count for your 2- D array \n";
cin>>y;
cout<<endl;

int mul=0;
mul = x*y;

int a[x][y];
int total=0;

cout<<"Enter "<<mul<<" elements of "<<x<<"*"<<y<<" Matrix \n";
for(i=0;i<x;i++){
for(j=0;j<y;j++){
cin>>a[i][j];
total=total+a[i][j];
}
}
cout<<endl;

cout<<"Matrix Entered By you is \n";
for(i=0;i<x;i++)
{for(j=0;j<y;j++)
cout<<a[i][j]<<" ";

cout<<endl;
}

cout<<"The total of "<<mul<<" elements is "<<total<<"\n";

float avg;
avg = total/mul;
cout<<"The average of "<<mul<<" elements is "<<avg<<"\n";

int b,c;

cout<<"Enter a row subscript to add the values \n";
cin>>b;
cout<<endl;


for(j=0;j<y;j++){
s=s+a[b][j];

}
cout<<"sum of"<<b<<" Row is"<<s;
cout<<endl;
  
  
cout<<"Enter a column subscript to add the values \n";
cin>>c;
cout<<endl;

int r=0;
for(i=0;i<x;i++)
{
r=r+a[i][c];

}
cout<<"sum of"<<c<<" Column is"<<r;
cout<<endl;
int d;

cout<<"Enter a row subscript where we need to find max value \n";
cin>>d;
cout<<endl;

int max=0;
for(j=0;j<y;j++){
//s=s+a[b][j];
if(max<a[d][j]){
max=a[d][j];
}
}
cout<<"Max of "<<d<<" Row is"<<max;
cout<<endl;

int e;

cout<<"Enter a row subscript where we need to find min value \n";
cin>>e;
cout<<endl;

int min=0;
for(j=0;j<y;j++){
//s=s+a[b][j];
if(min>a[e][j]){
min=a[e][j];
}
}
cout<<"Min of "<<e<<" Row is"<<min;
cout<<endl;


}


Related Solutions

Write a program that creates a two-dimensional array initialized with test data. The program should have...
Write a program that creates a two-dimensional array initialized with test data. The program should have the following functions: Hi There I really appreciate your help with this project. ▪ 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 ....
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept 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 values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: -getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. -getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array. -getRowTotal. This method should accept a two-dimensional array as...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: fillRandom. Accepts a reference to a two-dimensional array and fills it with random integers from 0 to 99 formatPrint. This method should accept a two-dimensional array and print it out row by row getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in...
1. a. In C++, Write a program that creates an array of 20 integers and initializes...
1. a. In C++, Write a program that creates an array of 20 integers and initializes it with the even values starting from 200. i.e. 200, 202, 204…. b. Write the elements of the array to the file even.txt, each element on a separate line. Try to use a single for loop for initializing the array and writing to file. You will need a separate counter for initializing the array. 2. a. Write another program that opens the file even.txt...
use c++ 1 a)Write a console program that creates an array of size 100 integers. Then...
use c++ 1 a)Write a console program that creates an array of size 100 integers. Then use Fibonacci function Fib(n) to fill up the array with Fib(n) for n = 3 to n = 103: So this means the array looks like: { Fib(3), Fib(4), Fib(5), ...., Fib[102) }. For this part of the assignment, you should first write a recursive Fib(n) function. .For testing, print out the 100 integers. b) For the second part of this assignment, you must...
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
Q in c++ Write a program that will find the inverse of any two dimensional array...
Q in c++ Write a program that will find the inverse of any two dimensional array without the usage of the built-in function.? plz answer in while or do while loop
Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
Write a Java program that creates a three-dimensional array. Populate each element with a string that...
Write a Java program that creates a three-dimensional array. Populate each element with a string that states each coordinate position in the array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT