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

Modify this c++ code which calculated the wind chill factor and cloud base altit

ID: 3607259 • 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 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.

I will have a .txt file already I was just wondering where would I need to add those strings to let it read the .txt file and output to a .txt file?

Orignal code:

#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)

{

   std::cout<<" ---------------------------------------------------------- ";

   std::cout<<" | This program determines wind chill using temperature. | ";

   std::cout<<" | in Farenheit and wind speed in mph. and computes      | ";

   std::cout<<" | the cloud base using the dew point in Farenheit.      | ";

   std::cout<<" ---------------------------------------------------------- ";

   

   std::cout<<"Enter the temperature in degrees Fahrenheit: ";

   std::cin>>*temperature;

   

   std::cout<<"Enter the wind speed in mph: ";

   std::cin>>*windSpeed;

   

   std::cout<<"Enter the dew point in degrees Fahrenheit: ";

   std::cin>>*duePoint;

   

}

//Method to print output

void output(double *temperature,double *windSpeed,double *duePoint,double windChill,double cloudBase)

{

   std::cout<<" Temperature Wind Speed Dew Point Wind Chill Cloud Base ";

   std::cout<<"----------------------------------------------------------------------------- ";

   if(*temperature<=50 && *windSpeed>=3)

   {

       std::cout<<*temperature<<" "<<*windSpeed<<" "<<*duePoint<<" "<<windChill<<" "<<cloudBase<<" ";

   }

   else

   {

       std::cout<<*temperature<<" "<<*windSpeed<<" "<<*duePoint<<" "<<"xxx"<<" "<<cloudBase<<" ";

       std::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;   

}

Test Input data-create a text file with the data below called "weatherData.txt" and test against the output shown above. The input data order is temperature, wind speed, dew point. 6 9.1 35 12 56 45 38 16 43 40 47 34 10 56 36 15

Explanation / Answer

Modified Code

//Method to get input

void input(double *temperature,double *windSpeed,double *duePoint)

{

   std::cout<<" ---------------------------------------------------------- ";

   std::cout<<" | This program determines wind chill using temperature. | ";

   std::cout<<" | in Farenheit and wind speed in mph. and computes      | ";

   std::cout<<" | the cloud base using the dew point in Farenheit.      | ";

   std::cout<<" ---------------------------------------------------------- ";

fstream infile;

infile.open("weatherData.txt", ios::in );

infile>>*temperature;

infile>>* windSpeed;

infile>>* duePoint;

infile.close();

}

//Method to print output

void output(double *temperature,double *windSpeed,double *duePoint,double windChill,double cloudBase)

{

   std::cout<<" Temperature Wind Speed Dew Point Wind Chill Cloud Base ";

   std::cout<<"----------------------------------------------------------------------------- ";

fstream outfile;

outfile.open("yourName.txt", ios::out );

   if(*temperature<=50 && *windSpeed>=3)

   {

       std::cout<<*temperature<<" "<<*windSpeed<<" "<<*duePoint<<" "<<windChill<<" "<<cloudBase<<" ";

outfile<<*temperature<<endl<<*windSpeed<<endl<<*duePoint<< endl <<windChill<< endl <<cloudBase<<endl;

   }

   else

   {

       std::cout<<*temperature<<" "<<*windSpeed<<" "<<*duePoint<<" "<<"xxx"<<" "<<cloudBase<<" ";

       std::cout<<" xxx Temperature must be 50 degrees or less, and windspeed must be 3 mph or more to compute wind chill. ";

       outfile<<*temperature<<endl<<*windSpeed<<endl<<*duePoint<< endl <<windChill<< endl <<cloudBase<<endl;

   }

outfile.close();

}

All the modified code is in bold. Only input() and output() functions will be modifed. All the calculations and main() remain same.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote