Question
C++ exercise In this exercise, you must read data from a file. First, create a custom input data file. The file contains the name of
C++ exercise
In this exercise, you must read data from a file.
First, create a custom input data file. The file contains the name of a town and seven population values. The name of the town will be your first name. The seven population values will be derived from the digits in your ACCeID. It will be a text file and can be made with any text editor, such as notepad. You can use your C++ programming editor. Do not use any punctuation or special characters. To create your input data file:
1) Get your ACCeID. This starts with one lowercase letter, followed by 7 digits. The first letter is usually the first letter of your first name. Example: Abernathy Zappas ACCeID is: a1234567.
2) Enter your first name represented by the letter. Then multiply each digit by 1000 and separate with some whitespace. Whitespace can be one or more spaces, tabs or newlines. Create the following data (example): Abernathy 1000 2000 3000 4000 5000 6000 7000
If a digit is a 0, use 9 instead. The problem with 0 is that no data is displayed in the chart. For example: Mindobiz Soos ACCeID is: m7032901. The data file will contain: Mindobiz 7000 9000 3000 2000 9000 9000 1000
3) Save this to a file; use the file naming convention, but use a .txt extension, not .cpp. For example: DLS_L5_Lastname.txt. For the examples above, the filenames would be: DL1_L5_Zappa.txt or DL1_L5_Soo.txt, assuming a section number of 1. Use your section number.
Next, write a program to read the data from this file and display a population bar chart. The program should:
1) Read the file DLS_L5_Lastname.txt made above. If the file is not found, handle the situation appropriately with a good error message, including the name of the file not found, then stop. Do not attempt to display a chart if no data is available. If the file opens OK, read the name of the town. At the top, display a title so the user knows what this chart represents. Use toupper on each letter of the name so the name is fully uppercase. For example, display: ABERNATHY POPULATION GROWTH (each * represents 1000 people)
2) Use all the data in the file to display a bar chart showing population growth.
3) Make the program more flexible: read population values from the file until end-of-file (instead of 7 times). It should work if there are more or less than 7 population values. Handle population values until end of file. Example output: (bar chart) MINDOBIZ POPULATION GROWTH (each * represents 1000 people) 1900 ******* 1920 ********* 1940 *** 1960 ** 1980 ********* 2000 ********* 2020 *
You program can assume: 1) population numbers start at the year 1900 (or 1910); 2) population counts are provided in 20 year increments; 3) seven population counts provided. For working code that reads data from a file, see: "Program Samples", Simple FileIO. This provides a complete, working FileIO example.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started