Question

In: Computer Science

Write a program that prompts the user to enter three sets of five double numbers each....

Write a program that prompts the user to enter three sets of five double numbers each. (You may assume the user responds correctly and doesn’t enter non-numeric data.)

The program should accomplish all of the following:

a. Store the information in a 3×5 array.

b. Compute the average of each set of five values.

c. Compute the average of all the values.

d. Determine the largest value of the 15 values.

e. Report the results.

Each major task should be handled by a separate function using the traditional C approach to handling arrays.

Accomplish task “b” by using a function that computes and returns the average of a one-dimensional array; use a loop to call this function three times.

The other tasks should take the entire array as an argument, and the functions performing tasks “c” and “d” should return the answer to the calling program.

Must be done in C for DEV C++

Solutions

Expert Solution

Thanks for the question.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer. Thanks!


===========================================================================

#include<iostream>
#include<iomanip>
using namespace std;

//computes and returns the average of a one-dimensional array;
double averageRow(double arr[], int size){
   double total = 0;
   for(int i=0; i<size; i++) total +=arr[i];
   return total/size;
}

//c. Compute the average of all the values.
double averageAll(double arr[][5], int rows,int cols){
   double total = 0;
   for(int row=0;row<rows;row++){
       for(int col=0;col<cols;col++){
           total += arr[row][col];
       }
   }
   return total/(rows*cols);
}

//d. Determine the largest value of the 15 values.
double largest(double arr[][5], int rows,int cols){
   double max = arr[0][0];
   for(int row=0;row<rows;row++){
       for(int col=0;col<cols;col++){
           if(max<arr[row][col])
           max = arr[row][col];
       }
   }
   return max;
}

int main(){
  
   //a. Store the information in a 3×5 array.
   double matrix[3][5];
  
   for(int row=0; row<3; row++){
       cout<<"Set #"<<row+1<<endl;
       for(int col=0; col<5; col++){
           cout<<"Enter number #"<<col+1<<": ";
           cin >> matrix[row][col];
       }
   }
  
   //b. Compute the average of each set of five values.
   for(int row=0; row<3; row++){
       cout<<"\nAverage of set#"<<row+1<<": "
           <<averageRow(matrix[row],5)<<endl;
   }
   //c. Compute the average of all the values.
   cout<<"\nAverage of all values: "<<averageAll(matrix,3,5)<<endl;
  
   // d. Determine the largest value of the 15 values.
   cout<<"\nLargest value of the 15 values is: "<<largest(matrix,3,5)<<endl;


   return 0;
}


Related Solutions

Write a C program that prompts the user to enter three sets of five double numbers...
Write a C program that prompts the user to enter three sets of five double numbers each. (You may assume the user responds correctly and doesn’t enter non-numeric data.) The program should accomplish all of the following: a. Store the information in a 3×5 array. b. Compute the average of each set of five values. c. Compute the average of all the values. d. Determine the largest value of the 15 values. e. Report the results. Each major task should...
Part 1 Write a program that prompts the user to enter three sets of five double...
Part 1 Write a program that prompts the user to enter three sets of five double numbers each. These numbers represent the five grades that each of three students has received. After prompting for the grades, the program: stores the data in a previously defined 3◊5 double array computes the average of each set of 5 grades after acquiring the grades for that one student determines the maximum and minimum values of each set of 5 grades acquiring the grades...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and print the average of the numbers. 2. Write a Java program that uses a for loop to print the odd numbers from 1 to 20. Print one number per line in the command line window. 3. Write a program which asks the user to input the size of potatoe fries she would like to purchase, and based on the size, it will tell her...
Write a test program that prompts the user to enter a sequence of numbers ending with...
Write a test program that prompts the user to enter a sequence of numbers ending with 0, and invokes this method to return the largest number in the input. Use inheritance and polymorphism approach. in java please
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Write a program that prompts the user to enter a series of strings, but with each...
Write a program that prompts the user to enter a series of strings, but with each string containing a small integer. Use a while loop and stop the loop when the user enters a zero. When the loop has finished, the program should display: the number of user inputs (not counting the final zero input). the total of the integers in the strings entered. the average of the integers accurate to one decimal place. Any help is greatly appreciated, this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT