Answer:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream Inputfile;
Inputfile.open("People.txt"); // Open file
if (!Inputfile) // Test for open errors
{
cout << "Error opening file.\n";
return 0;
}
int Pop; // Population
// Display Population Bar Chart Header
cout << "PRAIRIEVILLE POPULATION GROWTH\n"
<< "(each * represents 1000 people)\n";
for (int Year = 1; Year <= 6; Year++)
{ // One iteration per year
switch (Year)
{
case 1 : cout << "1900 ";
break;
case 2 : cout << "1920 ";
break;
case 3 : cout << "1940 ";
break;
case 4 : cout << "1960 ";
break;
case 5 : cout << "1980 ";
break;
case 6 : cout << "2000 ";
break;
}
Inputfile >> Pop; // Read from file
// calculate one per 1000 people
//cout<<"**"<<Pop<<endl;
while(Pop > 0)
{ // Display one asterisk per iteration
// One iteration per 1000 people
cout << "*";
Pop -= 1000;
}
cout << endl;
}
Inputfile.close(); // To close file
return 0;
}
Explanation: