fork download
  1. //Diego Martinez CSC5 Chapter 5, P.297,#18
  2. /*******************************************************************************
  3. * PRODUCE PRAIREVILLE POPULATION GROWTH
  4. * ______________________________________________________________________________
  5. * This program displays the population growth of Prairieville over a 100-year
  6. * period, from 1900 to 2000. It presents the data in the form of a simple bar
  7. * chart, where each year is listed alongside a visual representation of its
  8. * population.
  9. *
  10. * Computation is based on the Formula:
  11. * A value of 2 : 2,000 people = **
  12. * A value of 15 : 15,000 people = ***************
  13. *______________________________________________________________________________
  14. * INPUT
  15. * The population data for each year: 2, 4, 5, 9, 12, 15
  16. * The years corresponding to the population data:1900,1920,1940,1960,1980,2000
  17. *
  18. * OUTPUT
  19. * title: PRAIRIEVILLE POPULATION GROWTH
  20. * legend explaining the scale : (each * represents 1,000 people)
  21. * list of years, each followed by a row of asterisks (*)
  22. *******************************************************************************/
  23. #include <iostream>
  24. using namespace std;
  25.  
  26. int main() {
  27. int population[] = {2, 4, 5, 9, 12, 15}; //stores the population values for each year
  28. int years[] = {1900, 1920, 1940, 1960, 1980, 2000}; //stores the years corresponding to each population value.
  29.  
  30. cout << "PRAIRIEVILLE POPULATION GROWTH\n";
  31. cout << "(each * represents 1,000 people)\n";
  32.  
  33. for (int i = 0; i < 6; i++) {
  34. cout << years[i] << " ";
  35.  
  36. for (int j = 0; j < population[i]; j++) {
  37. cout << "*";
  38. }
  39.  
  40. cout << endl;
  41. }
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
PRAIRIEVILLE POPULATION GROWTH
(each * represents 1,000 people)
1900 **
1920 ****
1940 *****
1960 *********
1980 ************
2000 ***************