fork download
  1. //Xinnuo Wang CS1A chapter 5 , P.297, #18
  2. //
  3. /*******************************************************************************
  4. *
  5. * Display a bar chart
  6. *-------------------------------------------------------------------------------
  7. * This program display the population growth of Prairieville at 20-year intervals
  8. * during the past 100 years.The data can be found in the People.txt file.
  9. *
  10. *-------------------------------------------------------------------------------
  11. * INPUT
  12. * Outfile : The place to store data
  13. * i : The counter
  14. *
  15. *******************************************************************************/
  16. #include <iostream>
  17. #include <fstream>
  18. using namespace std;
  19.  
  20. int main()
  21. {
  22. ofstream outfile;
  23. //
  24. // Open the file
  25. outfile.open("People.txt");
  26. outfile<<"PRAIRIEVILLE POPULATION GROWTH"<< endl;
  27. outfile<< "(each * represents 1,000 people)"<< endl;
  28. // Initialize
  29. int star;//The place to store data
  30. int i ; // The counter
  31. //
  32. //1900
  33. star = 2;
  34. outfile<< "1900";
  35. for (i = 0;i< star; i++)
  36. outfile<< "*";
  37. outfile << endl;
  38. //1920
  39. star = 4;
  40. outfile<< "1920";
  41. for (i = 0;i< star; i++)
  42. outfile<< "*";
  43. outfile << endl;
  44. //1940
  45. star = 5;
  46. outfile<< "1940";
  47. for (i = 0;i< star; i++)
  48. outfile<< "*";
  49. outfile << endl;
  50. //1960
  51. star = 8;
  52. outfile<< "1960";
  53. for (i = 0;i< star; i++)
  54. outfile<< "*";
  55. outfile << endl;
  56. //1980
  57. star = 14;
  58. outfile<< "1980";
  59. for (i = 0;i< star; i++)
  60. outfile<< "*";
  61. outfile << endl;
  62. //2000
  63. star = 18;
  64. outfile<< "2000";
  65. for (i = 0;i< star; i++)
  66. outfile<< "*";
  67. outfile << endl;
  68. //
  69. // Close file
  70. outfile.close();
  71. return 0;
  72. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty