Question
CSE 110 Weather Program PROJECT #1 File handling, Loops, and meeting requirements Start a new project or Modify Lab this code, which calculated the wind
CSE 110 Weather Program PROJECT #1 File handling, Loops, and meeting requirements
Start a new project or Modify Lab this code, which calculated the wind chill factor and cloud base altitude using temperature, wind speed, and the dew point, to read the input values from a file called weatherData.txt. The program will read a set of values, compute the results, and write the results to a file called yourName.txt and display them on the output console. 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. The loop should be in main. Create the input file (data on next page) weatherData.txt The input and output streams must be declared in main and passed as needed. The program must read the data from the data file weatherData.txt. There should be a loop in main that reads, computes, and outputs the values until the end. It should also capture the fact that invalid data was read to output the error message. 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 error message is only output if data producing an invalid wind chill was read Main will close both files before returning zero, and shall not have any output statements. Output Formatting for the display and output file are to be exactly as shown below. 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 below the data. The input file data order is temperature, wind speed, dew point.
"
// My Name CSE 110 - Lab #5 // Weather Program #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 <= 50 && windSpeed >= 3) //Compute only if temperature is <= 50 and windSpeed 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 << endl << endl; cout << " -----------------------------------------------------------" << endl; //Input cout << " | |" << endl; cout << " | This program determines wind chill using temperature |" << endl; cout << " | in Farenheit and wind speed in mph, and computes |" << endl; cout << " | the cloud base using the dew point in Farenheit. |" << endl; cout << " | |" << endl; cout << " -----------------------------------------------------------" << endl << endl;
cout << " Enter the temperature in degrees Fahrenheit: "; cin >> temperature;
cout << " Enter the wind speed in mph: "; cin >> windSpeed;
cout << " Enter the dew point in degrees Fahrenheit: "; cin >> dewPoint;
}
void output(double temperature, double windSpeed, double dewPoint, double windChill, double cloudBase) //Output
{ cout << " Temperature Wind Speed Dew Point Wind Chill Cloud Base ";
cout << " ----------------------------------------------------------------------------- ";
if (temperature <= 50 && windSpeed >= 3)
{ cout << setw(9) << temperature << " dF" << setw(13) << windSpeed << " mph" << setw(12) << dewPoint;
cout << " dF" << setw(13) << windChill << " dF" << setw(15) << cloudBase << " ft" << endl;
}
else
{ cout << setw(9) << temperature << "dF" << setw(13) << windSpeed << "mph" << setw(12) << dewPoint << "dF" << setw(13) << "***" << setw(16) << cloudBase << "ft" << endl < cout << " *** Temperature must be 50 degrees or less, and windspeed must be 3 mph or more to compute wind chill. "; } } 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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started