Input Data File Program Homework Help Using C++
Custom Input Data File in C++
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.
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 Zappa’s ACCeID is: a1234567.
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 Soo’s ACCeID is: m7032901. The data file will contain:Mindobiz 7000 9000 3000 2000 9000 9000 1000
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.
A Program that Reads Data from the File
Next, write a program to read the data from this file and display a population bar chart. The program should:
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)
You program can assume:
1) Population numbers start at the year 1900 (or 1910); (some textbook editions start at 1900, some start at 1910; it doesn't really matter)
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.
C++ Code Solution
using namespace std;
// Entry point of the program
// Open the file
// Stop program if it can't be opened.
cout<< "Error: Failed to open input file DL1_L5_Maria.txt" <
// Read the title
// Convert all letters of town name to upper case
for (unsigned i = 0; i
townName[i] = toupper(townName[i]);
// Display a bar chart for each year from 1900 onwards with increments of 20 years
cout<< " (each * represents 1000 people)" <
for (int year = 1900; inFile>> population; year += 20)
cout<< year << " ";
for (inti = 0; i< population; i += 1000)