Write a C++ program that estimates the average weather temperatures for the State of California for four (4) days in the month of May 2021. The temperature data (°C) provided in each day for each time interval (6:00 AM to 12:00 PM) is shown in this table, and Figure 1 displays the example output that the software will produce: Day/Hour-Hour 6-7 7-8 8-9 9-10 10-11 11-12 Day 1 17.2 18.1 21.5 24.3 25.5 26.0 Day 2 15.3 17.4 19.5 20.2 22.1 23.5 Day 3 16.1 18.5 19.0 19.8 21.2 22.4 Day 4 18.0 18.9 19.4 22.6 23.8 24.7 The program shall allow user to enter the data for six (6) time intervals. The program shall then display the hourly weather temperatures in tabular format (column: time interval, row: day) with the average temperatures on the interval 6:00 AM to 12:00 PM in each respective day. Following is the description of the program: a) The program uses a 1-dimensional array to store the day and a 2-dimensional array to store the hourly temperatures for the six (6) intervals of each day of the month May 2021 using pointer notations. b) One void function named enterData() is defined to enter the information for 6 intervals in four (4) iterations. c) One function named calcAvgTemps() is defined to calculate and returns a double value of the average temperature for each day. The function takes two (2) arguments. The function shall be called in a loop in your main() function. d) One function named displayData() is defined to display all values stored in the 2-dimensional array after (c) has been calculated. This function shall be called through main(). You are given the partial codes below. Complete the code to achieve the output in Figure 1. #include #include #include using namespace std; const int ROW = 4; const int COL = 7; //prototype void enterData(); double calcAvgTemp(); void displayData(); string day[] = {"Day 1", "Day 2", "Day 3", "Day 4"}; int main() { double hourly_temps[ROW][COL]; double avg, sum; //function call to enter data for (int k = 0; k < ROW; k++) { sum = 0.0; //function call here to calculate average } cout << endl; //function call to display return 0; } void enterData() // { cout << setw(38) << "Hour-Hour" << setw(6) << "6-7" << setw(6) << "7-8" << setw(6) << "8-9" << setw(7) << "9-10" << setw(8) << "10-11" << setw(8) << "11-12" << endl << endl; //loop through user entry } void displayData() // { cout << "Hour-Hour" << setw(6) << "6-7" << setw(8) << "7-8" << setw(8) << "8-9" << setw(9) << "9-10" << setw(9) << "10-11" << setw(8) << "11-12" << setw(6) << "Avg" << endl; //loop through display data } double calcAvgTemp() // { double average, sum = 0.0; //loop through accumulate total //calculate average
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
Write a C++
The temperature data (°C) provided in each day for each time interval (6:00 AM to 12:00 PM) is shown in this table, and Figure 1 displays the example output that the software will produce:
Day/Hour-Hour |
6-7 |
7-8 |
8-9 |
9-10 |
10-11 |
11-12 |
Day 1 |
17.2 |
18.1 |
21.5 |
24.3 |
25.5 |
26.0 |
Day 2 |
15.3 |
17.4 |
19.5 |
20.2 |
22.1 |
23.5 |
Day 3 |
16.1 |
18.5 |
19.0 |
19.8 |
21.2 |
22.4 |
Day 4 |
18.0 |
18.9 |
19.4 |
22.6 |
23.8 |
24.7 |
The program shall allow user to enter the data for six (6) time intervals. The program shall then display the hourly weather temperatures in tabular format (column: time interval, row: day) with the average temperatures on the interval 6:00 AM to 12:00 PM in each respective day. Following is the description of the program:
a) The program uses a 1-dimensional array to store the day and a 2-dimensional array to store the hourly temperatures for the six (6) intervals of each day of the month May 2021 using pointer notations.
b) One void function named enterData() is defined to enter the information for 6 intervals in four (4) iterations.
c) One function named calcAvgTemps() is defined to calculate and returns a double value of the average temperature for each day. The function takes two (2) arguments. The function shall be called in a loop in your main() function.
d) One function named displayData() is defined to display all values stored in the 2-dimensional array after (c) has been calculated. This function shall be called through main().
You are given the partial codes below. Complete the code to achieve the output in Figure 1.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps