Modify this c++ code which calculated the wind chill factor and cloud base altit
ID: 3605764 • Letter: M
Question
Modify this c++ code 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.
• (Try not to use global variables)
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 equations for the wind chill factor and computing cloud base are in the previous instructions.
The equation for approximating the wind chill factor in North America is:
wc = 35.74 + 0.6215 * Ta - 35.75 * V0.16 + 0.4275 * Ta * V0.16
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.
Orignal code:
// This program will be used for a meteorologist that calculates the wind chill factor and cloud base altitude for the inputs temperature in Fahrenheit, wind speed in mph, and the dew point in Fahrenheit.
// Use a loop to enter a finite number of inputs for a given program run.
//
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//Setting Variables and asking User to input data
void takeInput(float *temp, float *wp, float *dp){
printf(" Enter the temprature in degrees Fahrenheit: ");
scanf("%f",temp);
printf("%.1f ",*temp);
printf(" Enter the wind speed in mph: ");
scanf("%f",wp);
printf("%.1f ",*wp);
printf(" Enter the dew point in degrees Fahrenheit: ");
scanf("%f",dp);
printf("%.1f ",*dp);
}
//setting vars. and calulating the wind chill
float calculateWC(float &temp,float &wp){
return 35.74 + 0.6215*temp - 35.75*pow(wp,0.16) + 0.4275*temp*pow(wp,0.16);
}
float calculateCB(float &temp,float &dp){
return (temp-dp)*1000/4.4;
}
void showOutput(float temp,float wp,float dp,float wc,float cb){
std::cout << std::fixed;
std::cout << std::setprecision(1);
cout<<endl;
cout<<setw(15);
cout<<"Temprature";
cout<<setw(15);
cout<<"Wind Speed";
cout<<setw(15);
cout<<"Dew Point";
cout<<setw(15);
cout<<"Wind Chill";
cout<<setw(15);
cout<<"Cloud Base";
cout<<endl<<" ";
for(int i=0;i<75;i++){
cout<<"-";
}
cout<<endl;
cout<<setw(11);
cout<<temp<<" df";
cout<<setw(11);
cout<<wp<<" mph";
cout<<setw(11);
cout<<dp<<" df";
cout<<setw(11);
if(wc>=50||wp<=3)
cout<<"***";
else
cout<<wc<<" df";
cout<<setw(11);
cout<<cb<<" ft";
cout<<endl<<" ";
if(wc>=50||wp<=3){
cout<<" *** Temprature must be 50 degrees or less, and windspeed must be above 3 mph to calculate the wind chill";
}
}
int main() {
printf(" --------------------------------------------------------- | This program determines wind chill using temprature | | in Farhenheit and wind speed in mph. and computes | | the cloud base using the dew point in Fahrenheit | --------------------------------------------------------- ");
printf(" ");
float temp,wp,dp,wc,cb;
takeInput(&temp,&wp,&dp);
wc = calculateWC(temp,wp);
cb = calculateCB(temp,dp);
showOutput(temp,wp,dp,wc,cb);
return 0;
}
Explanation / Answer
#include<iostream>
#include <math.h>
void input(double *temperature,double *windSpeed,double *duePoint);
void output(double *temperature,double *windSpeed,double *duePoint,double windChill,double cloudBase);
double computeWindChill(double *temperature,double *windSpeed);
double computeCloudBase(double *temperature,double *duePoint);
int main()
{
//Declare all variables
double *temperature= new double;
double *windSpeed= new double;
double *duePoint = new double;
double windChill = 0;
double cloudBase = 0;
//Get input
input(temperature,windSpeed,duePoint);
//Compute only if temperature is <=50 and windSpeed is >=3
if(*temperature<=50 && *windSpeed>=3) {
//Call computeWindChill method
windChill= computeWindChill(temperature,windSpeed);
}
//Call computeCloudBase method
cloudBase= computeCloudBase(temperature,duePoint);
//Print output
output(temperature,windSpeed,duePoint,windChill,cloudBase);
return 0;
}
//Method to get input
void input(double *temperature,double *windSpeed,double *duePoint)
{
cout<<" ---------------------------------------------------------- ";
cout<<" | This program determines wind chill using temperature. | ";
cout<<" | in Farenheit and wind speed in mph. and computes | ";
cout<<" | the cloud base using the dew point in Farenheit. | ";
cout<<" ---------------------------------------------------------- ";
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>>*duePoint;
}
//Method to print output
void output(double *temperature,double *windSpeed,double *duePoint,double windChill,double cloudBase)
{
cout<<" Temperature Wind Speed Dew Point Wind Chill Cloud Base ";
cout<<"----------------------------------------------------------------------------- ";
if(*temperature<=50 && *windSpeed>=3)
{
cout<<*temperature<<" "<<*windSpeed<<" "<<*duePoint<<" "<<windChill<<" "<<cloudBase<<" ";
}
else
{
cout<<*temperature<<" "<<*windSpeed<<" "<<*duePoint<<" "<<"xxx"<<" "<<cloudBase<<" ";
cout<<" xxx Temperature must be 50 degrees or less, and windspeed must be 3 mph or more to compute wind chill. ";
}
}
//Method to compute wind chill and return wind chill
double computeWindChill(double *temperature,double *windSpeed)
{
double windChill;
windChill = 35.74 + 0.6215 *(*temperature) - 35.75*(pow(*windSpeed,0.16))+ 0.4275*(*temperature)*(pow((*windSpeed),0.16));
//35.74 + 0.6215*(*temperature) - 35.75*(*windSpeed) +0.16 + 0.4275 *(*temperature)*(*windSpeed) +0.16;
return windChill;
}
//Method to compute cloud base
double computeCloudBase(double *temperature,double *duePoint)
{
double cloudBase;
cloudBase = (*temperature - *duePoint)/4.4 * 1000;
return cloudBase;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.