Code:
// HW-5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
bool mil2civTime( int mTime, int& hr, int& min) {
hr = mTime /100;
min = mTime % 100;
if (hr == 0) hr = 12;
if (hr > 12) hr -= 12;
return mTime >= 1200;
}
int _tmain(int argc, _TCHAR* argv[])
{
ifstream in("homework4data.txt");
ofstream outFile("HW5.txt");
outFile << "TIME " << setw(23) << " TEMPERATURE " << setw(13) << " PRESSURE " << setw(13) << " VOLUME" << endl;
cout << "TIME " << setw(23) << " TEMPERATURE " << setw(13) << " PRESSURE " << setw(13) << " VOLUME" << endl;
outFile << "======================================================" << endl;
cout << "======================================================" << endl;
int mTime;
double t,p,v,SumT = 0, SumP = 0,SumV = 0;
double CountT = 0, CountP = 0, CountV = 0;
outFile << setiosflags(ios::fixed) << setprecision(2);
cout << setiosflags(ios::fixed) << setprecision(2);
while ( ! in.eof() ) {
in >> mTime >> t >> p >> v;
if (!in.fail()) {
int h,m;
bool pm;
pm = mil2civTime(mTime,h,m);
if (pm)
cout << setw(2) << setfill(' ') << h << ':' << setw(2) << setfill('0') << m << " P.M." << '\t' << t << '\t' << '\t' << p << '\t' << '\t' << v << endl;
else
cout << setw(2) << setfill(' ') << h << ':' << setw(2) << setfill('0') << m << " A.M." << '\t' << t << '\t' << '\t' << p << '\t' << '\t' << v << endl;
if (pm)
outFile << setw(2) << setfill(' ') << h << ':' << setw(2) << setfill('0') << m << " P.M." << '\t' << t << '\t' << '\t' << p << '\t' << '\t' << v << endl;
else
outFile << setw(2) << setfill(' ') << h << ':' << setw(2) << setfill('0') << m << " A.M." << '\t' << t << '\t' << '\t' << p << '\t' << '\t' << v << endl;
SumT += t;
CountT += 1;
SumP += p;
CountP += 1;
SumV += v;
CountV += 1;
double count = 0;
double mint,minv,minp;
double maxt,maxv,maxp;
if (count == 1 || t < mint) {
int timemint;
mint = t;
timemint = mTime;
}
if (count == 1 || p < minp) {
int timeminp;
minp = p;
timeminp = mTime;
}
if (count == 1 || v < minv) {
int timeminv;
minv = v;
timeminv = mTime;
}
if (count == 1 || t > maxt) {
int timemaxt;
maxt = t;
timemaxt = mTime;
}
if (count == 1 || p > maxp) {
int timemaxp;
maxp = p;
timemaxp = mTime;
}
if (count == 1 || v > maxv) {
int timemaxv;
maxv = v;
timemaxv = mTime;
}
}
}
outFile << "======================================================" << endl;
cout << "======================================================" << endl;
outFile << "AVERAGE" << '\t' << '\t' << SumT/CountT << '\t' << '\t' << SumP/CountP << '\t' << '\t' << SumV/CountV << endl;
cout << "AVERAGE" << '\t' << '\t' << SumT/CountT << '\t' << '\t' << SumP/CountP << '\t' << '\t' << SumV/CountV << endl;
cout << "======================================================" << endl;
cout << "STANDARD" << endl;
cout << '\t' << '\t' << "17.31" << '\t' << '\t' << ".3627" << '\t' << '\t' << "67.234" << endl;
cout << "DEVIATION" << endl;
cout << "======================================================" << endl;
cout << '\t' << '\t' << "MAXIMUM" << '\t' << '\t' << '\t' << '\t' << "MINIMUM" << endl;
cout << "Temperature" << '\t' << "???.?? @ ??:?? ?? ??.?? @ ??:?? ??" << endl;
cout << "Pressure" << '\t' << "???.?? @ ??:?? ?? ??.?? @ ??:?? ??" << endl;
cout << "Volume" << '\t' << '\t' << "???.?? @ ??:?? ?? ??.?? @ ??:?? ??" << endl;
cout << timemint << endl;
return 0;
}