Question: C++ Weather Program File handling and Loops Modify Lab #5 which calculated the wind chill factor and cloud base altitude from inputs of temperature, wind
C++ Weather Program File handling and Loops
Modify Lab #5 which calculated the wind chill factor and cloud base altitude from inputs of temperature, wind speed, and the dew point, to read the values from a file called weatherData.txt. Read the values, compute the results, and write the results to a file called yourName.txt and also display them on the output console. The data sentinel is -99.
The program must have at least four (4) functions: one for opening the files with file failure conditions, one to compute the wind chill, one to compute the cloud base, and at least one for the output. Consider other functions as you see fit.
- Main will close the files before returning zero.
- The input and output streams can be declared globally.
- The program must read the data from the data file weatherData.txt.
- The program must produce the required output to the console window and to a file.
- The output must be as shown in the screen capture below (notice the extra note shown).
The equation for approximating the wind chill factor in North America is: wc = 35.74 + 0.6215 Ta - 35.75V +0.16 + 0.4275 Ta V +0.16
Where Ta is the air temperature in Fahrenheit V is the wind speed in mph (consider pow(windSpeed, 0.16)) Also, wind chill temperature is defined only at or below 10? C (50 ? F), and wind speeds above 4.8 kilometers per hour (3.0 mph). The program must check this.
The cloud base in feet above ground level is determined by the spread which is the difference between the temperature and the dew point, and is calculated: cloudBase = temperature spread / 4.4 * 1000
Note: When the input does not produce a valid wind chill value, the program will need to retain this information to output the required text.
Output Formatting for the display and output file are to be exactly as shown below.


LAB 5 Program Data
#include
using namespace std;
void input(double&temperature, double&windSpeed, double&dewPoint);
void output(double temperature, double windSpeed, double dewPoint, double windChill, double cloudBase);
double computeWindChill(double temperature, double windSpeed);
double computeCloudBase(double temperature, double dewPoint);
int main()
{
double temperature, windSpeed, dewPoint = 0, windChill = 0, cloudBase; //Declare all variables
input(temperature, windSpeed, dewPoint); //Get input
if(temperature = 3) //Compute only if temperature is = 3
{
windChill= computeWindChill(temperature, windSpeed); //Call computeWindChill method
}
cloudBase= computeCloudBase(temperature, dewPoint); //Call computeCloudBase method
output(temperature, windSpeed, dewPoint, windChill, cloudBase);
return 0; }
void input(double&temperature, double&windSpeed, double&dewPoint) {
cout.setf(ios::fixed); // use fixed point
cout.setf(ios::showpoint); // display the decimal
cout.precision(1); // display one decimal places
cout
cout > temperature;
cout > windSpeed;
cout > dewPoint;
}
void output(double temperature, double windSpeed, double dewPoint, double windChill, double cloudBase) //Output
{ cout
cout
if (temperature = 3)
{ cout
cout
}
else
{ cout
cout
}
}
double computeWindChill(double temperature, double windSpeed) //Method to compute wind chill and return wind chill
{
double windChill;
windChill = 35.74 + 0.6215 *(temperature) - 35.75*(pow(windSpeed,0.16))+ 0.4275*(temperature)*(pow((windSpeed),0.16));
return windChill;
}
double computeCloudBase(double temperature, double dewPoint) //Method to compute cloud base
{ double cloudBase;
cloudBase = (temperature - dewPoint)/4.4 * 1000;
return cloudBase;
}
Temperature Wind Speed Dew Point Wind Chill Cloud Base 6.0 mph 6.0 mph 8.0 mph 7.0 mph 5.0 mph 3.0 mph 6.0 mph 6. mph 1.0 mph 4.0 mph 7.0 mph 0.0 dF 2.0 dF 5.0 dF 12.0 dF 45.0 dF 16.0 dF 40.0 dF 34.0 dF 35.0 dF 36.0 dF 9.0 dF -4.7 d 14.3 dF 18.8 d 29.1 dF 6.0 dF 22.0 dF 27. dF 35.0 dF 56. dF 38.0 dF 43.0 dF 47.0 dF 48.0 dF 56.0 dF 15.0 dF 1363.6 ft 4545.5 ft 5000.0 ft 5227.3 ft 2500.0 ft 5000.0 ft 681.8 ft 2954.5 ft 2954.5 ft 4545.5 ft 1363.6 ft 36.1 dF 39.3 dF 44.1 dF 5.0 dF xxx There is no wind chill factor at this temperature or wind speed * xx)( Temperature must be 50 degrees or less, and wind speed must be 3 mph or more to compute wind chill Process returned 0 (0x0 execution time 0.047 s Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
