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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
cout << "This is Vishant's pint program." << endl;
char reset = 'n';
double pints[24];
double averagePints = 0;
double highPints = 0;
double lowPints = 0;
int hours = 7;
void getPints(double pints[], int hours);
double getAverage(double pints[], int hours);
double getHigh(double pints[], int hours);
double getLow(double pints[], int hours);
void displayInfo(int hours, double averagePints, double highPints, double lowPints);
while (reset == 'n')
{
getPints(pints, hours);
averagePints = getAverage(pints, hours);
highPints = getHigh(pints, hours);
lowPints = getLow(pints, hours);
displayInfo(hours, averagePints, highPints, lowPints);
cout << "End program?" << endl;
cin >> reset;
}
return 0;
}
void getPints(double pints[], int hours)
{
int a;
ifstream bloodInFile;
bloodInFile.open("bloodDrive.txt");
bloodInFile >> a;
int count = 0;
while (!bloodInFile.eof())
{
pints[count] = a;
count++;
bloodInFile >> a;
}
bloodInFile.close();
}
double getAverage(double pints[], int hours)
{
double totalPints = 0;
for (int i = 0; i < hours; i++)
{
totalPints = totalPints + pints[i];
}
double completePints = totalPints / hours;
return completePints;
}
double getHigh(double pints[], int hours)
{
double highest = pints[0];
for (int i = 1; i < hours; i++)
{
if (pints[i] > highest)
{
highest = pints[i];
}
}
return highest;
}
double getLow(double pints[], int hours)
{
double lowest = pints[0];
for (int i = 1; i < hours; i++)
{
if (pints[i] < lowest)
{
lowest = pints[i];
}
}
return lowest;
}
void displayInfo(int hours, double averagePints, double highPints, double lowPints)
{
ofstream bloodOutFile;
bloodOutFile.open("bloodResults.txt");
bloodOutFile << "Blood drive period.";
bloodOutFile << hours << endl;
bloodOutFile << "Average Pints";
bloodOutFile << averagePints << endl;
bloodOutFile << "Highest Pints";
bloodOutFile << highPints << endl;
bloodOutFile << "Lowest Pints";
bloodOutFile << lowPints;
bloodOutFile.close();
}
|