Sample run 1: Function Call double arr[] = {1.24, 5.68, 3.456} int arr_size= 3; 11 cout << "Min: " << fixed << setprecision (3)<< min(arr, arr_size) << endl; cout << "Sum: << fixed <

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 24PE
icon
Related questions
Question

Write in C++

Alice is trying to monitor how much time she spends studying per week. She going through her logs, and wants to figure out which week she studied the least, her total time spent studying, and her average time spent studying per week. To help Alice work towards this goal, write three functions: min()total(), and average(). All three functions take two parameters: an array of doubles and the number of elements in the array. Then, they make the following computations:

  • min() - returns the minimum value in the array
  • sum() - returns the sum of all the values in the array
  • average() - returns the average of all the values in the array

You may assume that the array will be non-empty.

Function specifications:

Function 1: Finding the minimum hours studied

  • Name: min()
  • Parameters (Your function should accept these parameters IN THIS ORDER):
    • arr double: The input array containing Alice's study hours per week
    • arr_size int: The number of elements stored in the array
  • Return Value: double: The minimum value in the array

Function 2: Computing the total hours studied

  • Name: sum()
  • Parameters (Your function should accept these parameters IN THIS ORDER):
    • arr double: The input array containing Alice's study hours per week
    • arr_size int: The number of elements stored in the array
  • Return Value: double: The sum of all the values in the array

Function 3: Computing the median study hours

  • Name: average()
  • Parameters (Your function should accept these parameters IN THIS ORDER):
    • arr double: The input array containing Alice's study hours per week
    • arr_size int: The number of elements stored in the array
  • Return Value: double: The average of all the values in the array

Sample run 1:

Alice is trying to monitor how much time she spends studying per week. She going through her logs, and wants to figure out which week
she studied the least, her total time spent studying, and her average time spent studying per week. To help Alice work towards this goal,
write three functions: min(), total(), and average (). All three functions take two parameters: an array of doubles and the number of
elements in the array. Then, they make the following computations:
min() - returns the minimum value in the array
sum() - returns the sum of all the values in the array
average() - returns the average of all the values in the array
You may assume that the array will be non-empty.
Function specifications:
Function 1: Finding the minimum hours studied
• Name: min()
• Parameters (Your function should accept these parameters IN THIS ORDER):
o arr double : The input array containing Alice's study hours per week
o arr_size int: The number of elements stored in the array
• Return Value: double : The minimum value in the array
Function 2: Computing the total hours studied
• Name: sum()
• Parameters (Your function should accept these parameters IN THIS ORDER):
o arr double : The input array containing Alice's study hours per week
o arr_size int: The number of elements stored in the array
• Return Value: double: The sum of all the values in the array
Function 3: Computing the median study hours
• Name: average()
• Parameters (Your function should accept these parameters IN THIS ORDER):
●
●
Transcribed Image Text:Alice is trying to monitor how much time she spends studying per week. She going through her logs, and wants to figure out which week she studied the least, her total time spent studying, and her average time spent studying per week. To help Alice work towards this goal, write three functions: min(), total(), and average (). All three functions take two parameters: an array of doubles and the number of elements in the array. Then, they make the following computations: min() - returns the minimum value in the array sum() - returns the sum of all the values in the array average() - returns the average of all the values in the array You may assume that the array will be non-empty. Function specifications: Function 1: Finding the minimum hours studied • Name: min() • Parameters (Your function should accept these parameters IN THIS ORDER): o arr double : The input array containing Alice's study hours per week o arr_size int: The number of elements stored in the array • Return Value: double : The minimum value in the array Function 2: Computing the total hours studied • Name: sum() • Parameters (Your function should accept these parameters IN THIS ORDER): o arr double : The input array containing Alice's study hours per week o arr_size int: The number of elements stored in the array • Return Value: double: The sum of all the values in the array Function 3: Computing the median study hours • Name: average() • Parameters (Your function should accept these parameters IN THIS ORDER): ● ●
• Parameters (Your function should accept these parameters IN THIS ORDER):
o arr double : The input array containing Alice's study hours per week
o arr_size int: The number of elements stored in the array
• Return Value: double : The average of all the values in the array
Sample run 1:
Function Call
double arr[] = {1.24, 5.68, 3.456}
int arr_size = 3;
cout << "Min: " << fixed << setprecision (3)<< min(arr, arr_size) << endl;
cout << "Sum:
<< fixed << setprecision (3) << sum(arr, arr_size) << endl;
cout << "Avg:
<< fixed <<
setprecision (3) << average (arr, arr_size) << endl;
Output
Min: 1.240
Sum: 10.376
Avg: 3.459
Sample run 2:
Function Call
double arr[]
int arr_size = 1;
cout << "Min: "
cout << "Sum:
cout << "Avg:
{0};
Output
<< fixed <<
<< fixed <<
<< fixed <<
setprecision (3)<< min(arr, arr_size) << endl;
setprecision (3) << sum(arr, arr_size) << endl;
setprecision (3) << average (arr, arr_size) << endl;
Transcribed Image Text:• Parameters (Your function should accept these parameters IN THIS ORDER): o arr double : The input array containing Alice's study hours per week o arr_size int: The number of elements stored in the array • Return Value: double : The average of all the values in the array Sample run 1: Function Call double arr[] = {1.24, 5.68, 3.456} int arr_size = 3; cout << "Min: " << fixed << setprecision (3)<< min(arr, arr_size) << endl; cout << "Sum: << fixed << setprecision (3) << sum(arr, arr_size) << endl; cout << "Avg: << fixed << setprecision (3) << average (arr, arr_size) << endl; Output Min: 1.240 Sum: 10.376 Avg: 3.459 Sample run 2: Function Call double arr[] int arr_size = 1; cout << "Min: " cout << "Sum: cout << "Avg: {0}; Output << fixed << << fixed << << fixed << setprecision (3)<< min(arr, arr_size) << endl; setprecision (3) << sum(arr, arr_size) << endl; setprecision (3) << average (arr, arr_size) << endl;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning