Computers and Technology

Write a program that produces a bar chart showing the population growth of Prairieville, a small town in the Midwest, at 20-year intervals during the past 100 years. The program should read in the population figures for 1900, 1920, 1940, 1960, 1980, and 2000 from a file named People. txt. It is understood that the first value represents the population in 1900 (for example, 2843), the second the population in 1920 and so on. For each year it should display the year, followed by one space followed by a bar consisting of one asterisk for each 1,000 people. (The program should round UP so that a population of 1 would generate one asterisk -- as would 1000, while a population of 1,001 would generate two, etc.)

Prompts And Output Labels. The program is not interactive so there are no prompts. The first line of the output should be
PRAIRIEVILLE POPULATION GROWTH
and the second line of the output should be
(each * represents 1000 people)
after which the main output follows.

Input Validation. The program should validate each population count read. If the population is ever negative, the program should print the message "BAD DATA" on a line by itself and not process any more data.

Here is what I have so far..

code:

#include
#include
using namespace std;

int main()
{
ifstream Inputfile;
Inputfile. open("people. dat"); // Open file
if (!Inputfile) // Test for open errors
cout << "Error opening file.\n";

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

Pop /= 1000; // calculate one per 1000 people

for (int Arisk = 1; Arisk <= Pop; Arisk++)
{ // Display one asterisk per iteration
// One iteration per 1000 people
cout << "*";
}

cout << endl;
}
Inputfile. close(); // To close file
return 0;
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 03:00, seddy86
Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". any value that is the same as the immediately preceding value is considered a consecutive duplicate. in this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. note that the last 3 is not a consecutive duplicate because it was preceded by a 7. write some code that uses a loop to read such a sequence of non-negative integers , terminated by a negative number. when the code finishes executing, the number of consecutive duplicates encountered is printed. in this case, 3 would be printed. assume the availability of a variable, stdin, that references a scanner object associated with standard input. that is, stdin = new scanner(system. in); is given.
Answers: 1
image
Computers and Technology, 22.06.2019 15:30, mikey3882
When creating a budget, log fixed expenses before income. after income. after savings. at the top.
Answers: 1
image
Computers and Technology, 22.06.2019 21:10, itsmichaelhere1
Dameas communication challenge is due to which factor
Answers: 2
image
Computers and Technology, 23.06.2019 09:00, 19youngr
Which company provides a crowdsourcing platform for corporate research and development? a: mtruk b: wiki answers c: mediawiki d: innocentive
Answers: 2
Do you know the correct answer?
Write a program that produces a bar chart showing the population growth of Prairieville, a small tow...

Questions in other subjects:

Konu
Health, 08.02.2021 05:40
Konu
Arts, 08.02.2021 05:40
Konu
Mathematics, 08.02.2021 05:40