1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <cstdlib>
using namespace std;
void open_files(ifstream& in_stream, ofstream& out_stream);
double wind_chill(double temp, double windSpeed);
double cloud_base(double temp, double dewPoint);
void output_header(ofstream& out_stream);
void output_data(ofstream& out_stream, double temp, double windSpeed, double dewPoint, double wc, double cb);
void output_warning(ofstream& out_stream, double temp, double windSpeed);
int main()
{
ifstream in_stream;
ofstream out_stream;
double temp, windSpeed, dewPoint, wc, cb;
bool warn;
open_files(in_stream, out_stream);
output_header(out_stream);
while (in_stream)
{
in_stream >> temp >> windSpeed >> dewPoint;
wc = wind_chill(temp, windSpeed);
cb = cloud_base(temp, dewPoint);
output_data(out_stream, temp, windSpeed, dewPoint, wc, cb);
}
if (warn = true)
{
output_warning(out_stream, temp, windSpeed);
}
in_stream.close();
out_stream.close();
return 0;
}
void output_data(ofstream& out_stream, double temp, double windSpeed, double dewPoint, double wc, double cb)
{
cout << fixed << setprecision(1);
out_stream << fixed << setprecision(1);
if ((temp > 0.0 && temp < 50.0) && windSpeed > 3.0)
{
cout << setw(7) << temp << " dF "<< setw(10) << windSpeed << " mph " << setw(12) << dewPoint << " dF " << setw(13) << wc << " dF " << setw(13) <<cb << " ft " << endl;
out_stream << setw(7) << temp << " dF "<< setw(10) << windSpeed << " mph " << setw(12) << dewPoint << " dF " << setw(13) << wc << " dF " << setw(13) <<cb << " ft " << endl;
}
else if (temp > 50.0 || (windSpeed <=3 && windSpeed > 0))
{
bool warn = true;
wc = wind_chill(temp, windSpeed);
cb = cloud_base(temp, dewPoint);
cout << setw(7) << temp << " dF "<< setw(10) << windSpeed << " mph " << setw(12) << dewPoint << " dF " << setw(13) << "***" << setw(17) <<cb << " ft " << endl;
out_stream << setw(7) << temp << " dF "<< setw(10) << windSpeed << " mph " << setw(12) << dewPoint << " dF " << setw(13) << "***" << setw(17) <<cb << " ft " << endl;
}
}
void output_warning(ofstream& out_stream, double temp, double windSpeed)
{
cout <<"\n*** There is no wind chill factor at this temperature or wind speed. ***" << endl;
cout << "\n *** Temperature must be 50 degrees or less, and wind speed" << endl;
cout << " must be > 3 mph to compute wind chill." << endl;
out_stream <<"\n*** There is no wind chill factor at this temperature or wind speed. ***" << endl;
out_stream << "\n *** Temperature must be 50 degrees or less, and wind speed" << endl;
out_stream << " must be > 3 mph to compute wind chill." << endl;
}
|