This lab is based on \"Using Files - Population Bar Chart\" at the end of Chapte
ID: 3752519 • Letter: T
Question
This lab is based on "Using Files - Population Bar Chart" at the end of Chapter 5. This is on page 303 Programming Challenge 23 (7ed); or page 322 Programming Challenge 25 (8ed); or on page 322 Programming Challenge 27 (9ed). In this lab, you must read the data from a file. The input data file: people.txt is attached above. It can also be found under Publisher Source, Chapter 5 (called people.dat) or, you can just make the data file with a text editor. This small file contains the numbers: 2000 4000 5000 9000 14000 18000. Use the file people.txt. I changed the extension from .dat to .txt because Windows is set up to easily display and edit files with the .txt extension. Do not submit the people.txt file with your lab. I will use the above people.txt file for testing. If you want to provide your own different data file, submit it along with your source code. Name your data file: DDHH_L5_lastname_people.txt to keep is separate from others. I will then use your data file for testing. You program can assume: 1) population numbers start for the year 1900; 2) population counts are provided in 20 year increments; 3) there are 6 population counts provided. To start out with working code which does most of what you need to read data from a file, see: "Program Samples", Simple FileIO. This provides a complete, working FileIO example.
Explanation / Answer
#include <iostream>
#include <iostream>
#include <fstream> #include <string> using namespace std; int main() { ifstream input; input.open("People.txt"); int year, people; for (year = 1910; year<=2010; year+=20) { cout << year << " "; input >> people; for (int x = 1; x <= people; x += 1000) { cout << "*"; } cout << endl; } input.close(); return 0; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.