Question

In: Computer Science

You are required to write an interactive program that prompts the user for seven (7) real...

You are required to write an interactive program that prompts the user for seven (7) real numbers and performs the following tasks:

  1. Reads and stores the numbers into one-dimensional array called A.
  2. Calculates the sum of the numbers.
  3. Find the average of the numbers.
  4. Finds the smallest value of the numbers.
  5. Prints all the results with proper headings.

Program requirements:

-     The program must contain at least five functions using necessary parameters. These functions should read the data, perform the above tasks, and print the results.

-     The program must be fully documented.

-    You must submit a properly labeled output. .

-     Test your program for different values using real numbers.

Please submit with through comments & spacings/indentations from the source code.

Solutions

Expert Solution

#include <iostream>
using namespace std;
void read_array(float arr[])
{
for(int i=0;i<7;i++)
cin>>arr[i];
}
void print_array(float arr[])
{
for(int i=0;i<7;i++)
cout<<arr[i]<<" ";
}
float compute_sum(float arr[])
{
float sum=0;
for(int i=0;i<7;i++)
sum=sum+arr[i];
return sum;
}
float find_average(float arr[])
{
float sum=0;
for(int i=0;i<7;i++)
sum=sum+arr[i];
return sum/7;
}
float find_min(float arr[])
{
float min;
min=arr[0];
for(int i=1;i<7;i++)
if(arr[i]<min)
min=arr[i];

return min;
}

int main()
{
float arr[7],sum,average,small;
cout<<"Enter seven real numbers : "<<endl;
read_array(arr);
cout<<"THE CONTENTS OF ARRAY:"<<endl;
print_array(arr);

sum=compute_sum(arr);
cout<<"\nSum = "<<sum<<endl;
  
average=find_average(arr);
cout<<"Average = "<<average<<endl;

small=find_min(arr);
cout<<"Smallest = "<<small<<endl;
return 0;
}//end main

input Enter seven real numbers : 4.3 3.5 6.7 8.9 2.1 3.2 6.7 THE CONTENTS OF ARRAY: 4.3 3.5 6.7 8.9 2.1 3.2 6.7 Sum =35.4 Average =5.05714 Smallest = 2.1 . Program finished with exit code 0 Press ENTER to exit console.


Related Solutions

You are required to write an interactive program that prompts the user for ten (10) real...
You are required to write an interactive program that prompts the user for ten (10) real numbers and performs the following tasks: Reads and stores the numbers into one-dimensional array called A. The program must use a function to perform this task. Prints the content of the array. Write a function to perform this task. Calculates the sum of the numbers. Use a function to perform this task. Find the average of the numbers. Utilize a function to perform this...
You are required to write an interactive program that prompts the user for two integers X...
You are required to write an interactive program that prompts the user for two integers X and Y and performs the following tasks: Adds two numbers Subtracts Y from X Multiplies X and Y Divides X by Y Finds which numbers is larger X oy Y) Prints all the results (a , b, c, d, and e) Program requirements: -     The program should run as many times as the users wish -     The program should be fully documented. -   ...
You are required to write an interactive JS program that prompts the user for three numbers...
You are required to write an interactive JS program that prompts the user for three numbers and then finds the sum, average, smallest, and the largest value of the numbers and prints the results labeling properly.
You will write a program that prompts the user to enter a 7-digit phone numbers, and...
You will write a program that prompts the user to enter a 7-digit phone numbers, and finds the 3- and 4-letter words that map to the phone number, according to the restrictions outlined earlier. A sample run: unixlab% java MapNumbers Enter name of dictionary file: words10683 Enter a test word (3 letters): cat Test word maps to 228 Enter telephone number (7 digits, no 0's or 1's, negative to quit): 2282273 Options for first 3 digits: act cat bat Options...
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user...
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user for the number of interior and exterior murals scheduled to be painted during the next month by Marshall’s Murals. Next, the programs compute the expected revenue for each type of mural when interior murals cost $500 each and exterior murals cost $750 each. The application also displays the total expected revenue and a statement that indicates whether more interior murals are scheduled than exterior...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT