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
|
int main()
{
ifstream inputFile;
ofstream outputFile;
float popAverage, interAverage, userAverage, total, penetration, growthPercent,
pentAverage, growAverage, sumPop, sumInt, sumUser, sumPent, sumGrowth;
int population, internet, usersCurrent, area;
//Open file.
inputFile.open("pgm4.txt");
outputFile.open("pgm4rpt.txt");
if (!inputFile)
{
//Display error messeage.
cout << "Error opening your file.\n";
}
cout << "World Internet Usage Report \n";
cout << " M T, CS2010, Tuesday Thursday @6pm \n ";
cout << "\n";
cout << "Area Population Internet(2000) Users Current Penetration (% Pop) Growth% ";
cout << "___________________________________________________________________________________";
// read in
while (!inputFile.eof())
{
inputFile >> area >> population >> internet >> usersCurrent;
cout << area << " " << population << " " << internet << " " << usersCurrent << " " << penetration << " " << growthPercent << endl;
area++;
if (area == 1)
{
penetration = usersCurrent / population;
growthPercent = (usersCurrent - internet) / internet;
}
else if (area == 2)
{
penetration = usersCurrent / population;
growthPercent = (usersCurrent - internet) / internet;
}
else if (area == 3)
{
penetration = usersCurrent / population;
growthPercent = (usersCurrent - internet) / internet;
}
else if (area == 4)
{
penetration = usersCurrent / population;
growthPercent = (usersCurrent - internet) / internet;
}
else if (area == 5)
{
penetration = usersCurrent / population;
growthPercent = (usersCurrent - internet) / internet;
}
else if (area == 6)
{
penetration = usersCurrent / population;
growthPercent = (usersCurrent - internet) / internet;
}
else if (area == 7)
{
penetration = usersCurrent / population;
growthPercent = (usersCurrent - internet) / internet;
}
sumPop += population;
sumInt += internet;
sumUser += usersCurrent;
sumPent += penetration;
sumGrowth += growthPercent;
}
//Calculate average number of each category.
popAverage = sumPop / area;
interAverage = sumInt / internet;
userAverage = sumUser / usersCurrent;
pentAverage = sumPent / penetration;
growAverage = sumGrowth / growthPercent;
cout << "____________________________________________________________________________" << endl;
cout << "Total/Avg %: " << popAverage << " " << interAverage << " " << userAverage << " " << pentAverage << " " << growAverage << " " << endl;
//Output to file
outputFile << ("pgm4rpt.txt");
//Close the file.
inputFile.close();
outputFile.close();
cout << endl;
cout << endl;
system("pause");
return 0;
|