Question

In: Computer Science

In C++ using a single dimensional array Create a program that uses a for loop to...

In C++ using a single dimensional array

Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array, a for loop will be used to pull out the high and low temps and total them. After all temps have been totaled, the average high and low will be calculated. The totals and averages will be placed into the array. The output will display the following;

The total high temps is "total high"

The total low temps is "total low"

The average high temps is "average high"

The average low temps is "average low"

Solutions

Expert Solution

Code is Given Below:

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

#include <iostream>

using namespace std;

int main()
{
//declaring array to hold day, low Temperature and high Temperature
float temperature[21];
int day=1;
//asking user to enter data of 7 days
for(int i=0;i<21;i+=3){
temperature[i]=day;
cout<<"Enter High Temperature of Day "<<day<<": ";
cin>>temperature[i+1];
cout<<"Enter Low Temperature of Day "<<day<<": ";
cin>>temperature[i+2];
day++;

}
//finding highToatal and lowToatl
double highTotal,lowTotal;
highTotal=0;
lowTotal=0;
for(int i=0;i<21;i+=3){
highTotal=highTotal+temperature[i+1];
lowTotal=lowTotal+temperature[i+2];

}
//finding average
double averageHigh;
double averageLow;
averageHigh=highTotal/7;
averageLow=lowTotal/7;
//displaying result
cout<<"The total high temps is "<<highTotal<<endl;
cout<<"The total low temps is "<<lowTotal<<endl;
cout<<"The average high temps is "<<averageHigh<<endl;
cout<<"The average low temps is "<<averageLow<<endl;
return 0;
}

Output:

===========

Code Snapshot:

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


Related Solutions

Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
C/ C++ Preferably 1. Write a simple program where you create an array of single byte...
C/ C++ Preferably 1. Write a simple program where you create an array of single byte characters. Make the array 100 bytes long. In C this would be an array of char. Use pointers and casting to put INTEGER (4 byte) and CHARACTER (1 byte) data into the array and pull it out. YES, an integer can be put into and retrieved from a character array. It's all binary under the hood. In some languages this is very easy (C/C++)...
Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0.
This program is for C.Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0. Combine the elements of A + B to create two- dimensional array C = A + B. Display array A, B and C to the screen for comparison. (Note a[0] + b[0] = c[0], a[1] + b[1] = c[1], etc.)
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write Matrix Addition 2 D (dimensional) Array program in c++.
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like...
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. 2. Write a python program using Pandas to convert a Panda module Series to Python list and print it's type. (Hint: use ds.tolist() to convert the pandas series ds to a list) 3. Create a pandas dataframe called **my_df** with index as integer numbers between 0 to 10, first column (titled "rnd_int") as 10 integer random numbers between...
C++ Language Implement a two-dimensional image using a nested loop. 1) Create an integer constant DIM...
C++ Language Implement a two-dimensional image using a nested loop. 1) Create an integer constant DIM and set it equal to 5. 2) Use a nested loop to print the output in terms of DIM. Example output: ***** *---* *---* *---* *****
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT