The program should do the following:
1. store the information into a 5 by 3 array
2. compute the average of each 5 rows
3. determine the smallest value of the 15 values
4. report the results ; print the original matrix and average of each row, and the smallest value in this function
Each part should be handled by a seperate function.
You need to use two dimensional arrays and functions in this program.
Can anybody help me with this problem? Thanks alot
Write a C++ program that prompts the user to enter five sets of three double numbers each.?
Find the code snipet that can perform the tasks you are looking for:-
/*************************************...
#include%26lt;iostream.h%26gt;
class TwoDArray
{
private:
double doubleArray[5][3];
public:
void getNumbers();
void getAverage();
void getSmalest();
TowDArray() { };
};
void TwoDArray::getNumbers()
{
for(int row=0; row%26lt;5; row++)
{
for(int col=0; col%26lt;3; col++)
{
cout %26lt;%26lt; "doubleArray[" %26lt;%26lt; row %26lt;%26lt; "][" %26lt;%26lt; col %26lt;%26lt; "]: ";
cin %26gt;%26gt; doubleArray[row][col];
}
}
return;
}
void TwoDArray::getAverage()
{
double average[5];
for(int row=0; row%26lt;5; row++)
{
average[row] = 0.00;
for(int col=0; col%26lt;3; col++)
{
// Summing up the three (3) double in a row.
average[row] += doubleArray[row][col];
cout %26lt;%26lt; doubleArray[row][col] %26lt;%26lt; "\t";
}
// Calculating the average.
average[row] /= 3;
cout %26lt;%26lt; "Average: " %26lt;%26lt; average[row] %26lt;%26lt; endl;
}
}
void TwoDArray::getSmalest()
{
double smallest = 0.00;
for(int row=0; row%26lt;5; row++)
{
for(int col=0; col%26lt;3; col++)
{
cout %26lt;%26lt; doubleArray[row][col] %26lt;%26lt; "\t";
if(smallest %26gt; doubleArray[row][col] )
smallest = doubleArray[row][col];
}
cout %26lt;%26lt; endl;
}
cout %26lt;%26lt; "Smallest value: " %26lt;%26lt; smallest %26lt;%26lt; endl;
}
int main()
{
TwoDArray twoDArray;
twoDArray.getNumbers();
towDArray.getAverage();
twoDArray.getSmalest();
}
/*************************************...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment