Answer to Question #7268 in C++ for Haniff Halmi
Question #7268
Write a program that will read daily temperature reading for the month of January 2012. Your program should contain the following functions:
(a) main() function contains instructions of reading input needed and print all the related information.
(b) NORMAL() function calculates the number of normal days (temperature between 60F and 84F)
(c) AVERAGE() function calculates the average temperature in January 2012.
(d) DAYS() function calculates the number of days which has temperature more than the average.
(a) main() function contains instructions of reading input needed and print all the related information.
(b) NORMAL() function calculates the number of normal days (temperature between 60F and 84F)
(c) AVERAGE() function calculates the average temperature in January 2012.
(d) DAYS() function calculates the number of days which has temperature more than the average.
Expert's answer
#include <iostream>
using namespace std;
const int
n=31;
int NORMAL(int * deg){
int res = 0;
for( int i=0; i<n;
i++){
if(deg[i]>=64 && deg[i]<=80)
res++;
}
return
res;
}
double AVERAGE(int * deg){
double res = 0;
for( int i=0;
i<n; i++){
res +=deg[i];
}
return res/n;
}
int DAYS(int *
deg){
int res = 0;
double e = AVERAGE(deg);
for( int i=0; i<n;
i++){
if(deg[i] > e)
res++;
}
return res;
}
int
main(){
int * temp = new int [n];
cout<<"Input 31 value of
tempetarute in January 2012\n";
for( int i=0; i<n; i++
){
cout<<i+1<<":
";
cin>>temp[i];
}
cout<<"The number of normal days:
"<<NORMAL(temp)<<endl;
cout<<"The average temperature
value: "<<AVERAGE(temp)<<endl;
cout<<"The number of days
which has temperature more than the average:
"<<DAYS(temp)<<endl;
system("pause");
return 0;
}
using namespace std;
const int
n=31;
int NORMAL(int * deg){
int res = 0;
for( int i=0; i<n;
i++){
if(deg[i]>=64 && deg[i]<=80)
res++;
}
return
res;
}
double AVERAGE(int * deg){
double res = 0;
for( int i=0;
i<n; i++){
res +=deg[i];
}
return res/n;
}
int DAYS(int *
deg){
int res = 0;
double e = AVERAGE(deg);
for( int i=0; i<n;
i++){
if(deg[i] > e)
res++;
}
return res;
}
int
main(){
int * temp = new int [n];
cout<<"Input 31 value of
tempetarute in January 2012\n";
for( int i=0; i<n; i++
){
cout<<i+1<<":
";
cin>>temp[i];
}
cout<<"The number of normal days:
"<<NORMAL(temp)<<endl;
cout<<"The average temperature
value: "<<AVERAGE(temp)<<endl;
cout<<"The number of days
which has temperature more than the average:
"<<DAYS(temp)<<endl;
system("pause");
return 0;
}
Need a fast expert's response?
Submit orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment