15. a. Write a program to process a collection of daily high temperatures. Your
ID: 3641450 • Letter: 1
Question
15. a. Write a program to process a collection of daily high temperatures.Your program should count and print the number of hot days (high
temperature 85 or higher), the number of pleasant days (high tem-
perature 60-84), and the number of cold days (high temperature less
than 60). It should also display the category of each temperature.
Test your program on the following data:
55 62 68 74 59 45 41 58 60 67 65 78 82 88 91
92 90 93 87 80 78 79 72 68 61 59
b. Modify your program to display the average temperature (a real
number) at the end of the run.
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int arr[]={55,62, 68, 74, 59, 45, 41, 58, 60, 67, 65, 78, 82, 88, 91,92, 90, 93, 87, 80, 78, 79, 72, 68, 61, 59};
int i,hot_days=0,pleasant_days=0,cold_days=0;
for(i=0;i<26;i++)
{
if(arr[i]>=85)
hot_days++;
else if(arr[i]>=60 && arr[i]<85)
pleasant_days++;
else cold_days++;
}
cout<<hot_days<<" of hot days"<<endl;
cout<<pleasant_days<<" of pleasant days"<<endl;
cout<<cold_days<<" of cold days"<<endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.