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
|
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
const int SIZE = 100; // Maximum size of array
void inputFromFile(int[], int[], int[], int[], int[]);
double CalculateMean(int[], int[], int[], int[], int[]); // Mean of each category
double CalculateMax(int[], int[], int[], int[], int[]); // Maximum of each category
double CalculateSum(int[], int[], int[], int[], int[]); // Sum of each category
int main(void)
{
int Deaths[SIZE];
int Doctors[SIZE];
int Hospitals[SIZE];
int Income[SIZE];
int Population[SIZE];
inputFromFile(Deaths, Doctors, Hospitals, Income, Population);
ifstream health("health.txt"); // Open health.txt
string firstline;
// Read health.txt
double Death, Docs, Hosp, Inc, Pop;
if (health.is_open())
{
getline(health, firstline);
cout << "The mean, maximum & sum of Deaths: " << << endl;
cout << "The mean, maximum & sum of Doctors: " << << endl;
cout << "The mean, maximum & sum of Hospitals: " << << endl;
cout << "The mean, maximum & sum of Income: " << << endl;
cout << "The mean, maximum & sum of Population: " << << endl;
while (!health.eof())
{
// Organize health.txt Data
health >> Death >> Docs >> Hosp >> Inc >> Pop;
}
}
return 0;
double CalculateMean(const double x[], int[], int[], int[], int[], int[])
{
double sum(0);
for (int i=0; k<SIZE; i++)
{
sum =+ x[i];
}
return sum/n;
}
double CalculateMax (const double x[], int[], int[], int[], int[], int[])
{
double Max = x[0];
for (int i=1; i<SIZE; i++)
{
if (x[i] > Max)
Max = x[i];
}
return Max;
}
}
| |