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 <

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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's 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, we 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
Transcribed Image Text:Alice is trying to monitor how much time she spends studying per week. She's 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, we 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
```plaintext
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:

Function Call:
```cpp
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:
```cpp
double arr[] = {0};
int arr_size = 1;
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: 0.000
Sum: 0.000
Avg: 0.000
```
```
Transcribed Image Text:```plaintext 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: Function Call: ```cpp 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: ```cpp double arr[] = {0}; int arr_size = 1; 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: 0.000 Sum: 0.000 Avg: 0.000 ``` ```
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education