Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following program prompts the user to enter the temperatures in three cities

ID: 3648415 • Letter: T

Question

The following program prompts the user to enter the temperatures in three cities. (see output below). Only one function is used to get all three values. The average temperature of all three cities is displayed on me screen. Create a new project and name it: HW 1b Create a new file and name it: main.cpp The following 3 functions are called in main(): getTemps() The function prompts the user to enter three temperatures. The numbers are read and assigned to variables. The function is a void-returning function. calcAvg() The function calculates the average temperature of the three cities. The value is returned to main(). displayAvg() The function displays the information on the screen. (see output). Create a new project and name it: HW 1c Create a new file and name it: main.cpp Use the code in HW 1b, and then make the following change. Use an array to store the 3 temperatures. Pass the array to the getTemps function. After values have been stored in the array, pass the array to displayAvg().

Explanation / Answer

please rate - thanks

without array

#include<iostream>
#include <iomanip>
using namespace std;
void getTemps(double&,double&,double&);
double calcAvg(double,double,double);
void displayAvg(double);
int main()
{double t1,t2,t3,avg;
getTemps(t1,t2,t3);
avg=calcAvg(t1,t2,t3);
displayAvg(avg);
system("pause");
return 0;
}
void getTemps(double& t1,double& t2,double& t3)
{cout<<"Enter temperaturs of 3 cities. ";
cout<<"#1: ";
cin>>t1;
cout<<"#2: ";
cin>>t2;
cout<<"#3: ";
cin>>t3;
}
double calcAvg(double t1,double t2,double t3)
{return (t1+t2+t3)/3.;
       }
void displayAvg(double avg)
{cout<<"The average temperature is "<<setprecision(1)<<fixed<<avg<<" degrees. ";
}

---------------------------------------

with array

#include<iostream>
#include <iomanip>
using namespace std;
void getTemps(double[]);
double calcAvg(double[]);
void displayAvg(double);
int main()
{double t[3],avg;
getTemps(t);
avg=calcAvg(t);
displayAvg(avg);
system("pause");
return 0;
}
void getTemps(double t[])
{cout<<"Enter temperaturs of 3 cities. ";
int i;
for(i=0;i<3;i++)
    {cout<<"#"<<i+1<<": ";
     cin>>t[i];
    }
}
double calcAvg(double t[] )
{double sum=0;
int i;
for(i=0;i<3;i++)
    sum+=t[i];
return sum/3.;
       }
void displayAvg(double avg)
{cout<<"The average temperature is "<<setprecision(1)<<fixed<<avg<<" degrees. ";
}