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
|
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
using namespace std;
void Fileopen(ifstream& InputFile, ofstream& OutputFile);
void initializeVariables(ifstream& InputFile, ofstream& OutputFile);
void SumPopulation(float&, float&, ifstream&, ofstream&, int&, int&);
void averageCounty(int&, int&, float&, float&, ifstream&, ofstream&);
void output(int&, int&, float&, float&, ifstream&, ofstream&, float&, float&);
int main() {
ifstream InputFile;
ofstream OutputFile;
Fileopen(InputFile, OutputFile);
InputFile.close();
OutputFile.close();
return 0;
}
void Fileopen(ifstream& InputFile, ofstream& OutputFile)
{
InputFile.open("data.txt");
OutputFile.open("avgdata.txt");
initializeVariables(InputFile, OutputFile);
OutputFile << showpoint << fixed << setprecision(2);
}
void initializeVariables(ifstream& InputFile, ofstream& OutputFile) {
string state;
float population;
string county;
string line;
string when = "FL";
string what = "MS";
int MS = 0;
int FL = 0;
float PopulationSumMS = 0;
float PopulationSumFL = 0;
while (!InputFile.eof()) {
InputFile >> state >> county >> population;
if (state == what) {
MS++;
PopulationSumMS = PopulationSumMS + population;
InputFile.ignore('\n');
}
if (state == when) {
FL++;
PopulationSumFL = PopulationSumFL + population;
InputFile.ignore('\n');
}
}
SumPopulation(PopulationSumMS, PopulationSumFL, InputFile, OutputFile, MS, FL);
averageCounty(MS, FL, PopulationSumMS, PopulationSumFL, InputFile, OutputFile);
}
void SumPopulation(float& PopulationSumMS, float& PopulationSumFL, ifstream& InputFile, ofstream& OutputFile, int& MS, int& FL) {
}
void averageCounty(int& MS, int& FL, float& PopulationSumMS, float& PopulationSumFL, ifstream& InputFile, ofstream& OutputFile) {
float AverageMS = PopulationSumMS / MS;
float AverageFL = PopulationSumFL / FL;
output(MS, FL, PopulationSumMS, PopulationSumFL, InputFile, OutputFile, AverageMS, AverageFL);
}
void output(int& MS, int&FL, float& PopulationSumMS, float& PopulationSumFL, ifstream& InputFile, ofstream& OutputFile, float& AverageMS, float& AverageFL) {
OutputFile << "MS: " << AverageMS << endl;
OutputFile << "FL: " << AverageFL << endl;
InputFile.close();
OutputFile.close();
}
|