Question
Lesson 7 has two parts. There are also 10 bonus points. To earn the bonus points you have to complete the Participation activities and Challenge
Lesson 7 has two parts.
There are also 10 bonus points. To earn the bonus points you have to complete the Participation activities and Challenge activities for zyBooks unit 4. These have to be completed by the due date for lab lesson 7.
Part 1 is worth 50 points (40 points running the tests and 10 for your program formatting, comments, and variable names). You will be developing and testing with an IDE and them uploading the solution to zyBooks/zyLabs. Your program will be reading in from a file and writing out to a file. You need to test your program in the IDE to make sure it is working. Once you have completed your testing you will need to upload the source file for the submit mode tests. Failure to meet the requirements could result in loss of points beyond the 10 for the code formatting, variable names, and so on.
You can only run the submit mode tests 30 times (or less). If you find any errors while in submit mode you will have to go back to your IDE and update your program, test to make sure you have fixed the problems, and upload a new version to zyBooks/zyLabs.
You will have to create input files for your program. You can use a text editor such as Notepad or Notepad++ to create this. There may also be an editor in your IDE that you can use. You can use the TextEdit program on macOS but you will need to change the format to Make Plain Text. You will not be uploading these text files to zyBooks/zyLabs. The submit tests will be using their own files.
In part 1 you will read in five (5) long long int values that represent today's sales for five stores and then create a bar chart from these.
The five input values will be read in from a file. You need to read in the file name from cin. You should not have a prompt for the file name. Once you have read in the file name you need to open up the file and read in the five input values (the sales for the five stores).
You will be outputting a string of X (upper case X) characters where each X represents $1,000 in sales for that store. For each 1,000 in sales you output one X. You do not round up the sales, so sales of $6,000 and sales of $6,999 would both output 6 X characters.
You will output the sales bar chart to a file named saleschart.txt. You need to use a for loop to create the bar chart.
You need to verify that the input values are all numbers that are not negative. If one or more of the values are negative you need to output an error message to cout and end the program.
The error message is:
One or more of the sales values are negative
If you get an end of file before you get five input values output to cout the error message:
Your input file must contain the sales values for five stores
Assume the file we are reading in from is called sales.txt. If the file does not exist or cannot be opened output the following message to cout:
File "sales.txt" could not be opened
Note that the file name is enclosed in " characters in the output error message.
Here is an example run. Assume the following input being read in from cin:
sales.txt
Assume that the content of the file sales.txt are as follows:
10000 25000 37000 29000 8000
The output (to file saleschart.txt) for this input would be:
SALES BAR CHART (Each X equals 1,000 dollars) Store 1: XXXXXXXXXX Store 2: XXXXXXXXXXXXXXXXXXXXXXXXX Store 3: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Store 4: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Store 5: XXXXXXXX
You are reading from an input file and you are writing to an output file. Make sure you close both files after you are finished using them. You must do this in your program, you cannot just let the operating system close the files for you.
In this lab. and some future labs, you will be creating an output file. There will be output to cout as well.
For tests where there is output written to an output file the contents of the output file will determine if you passed that test or not. For cases where you have written out to cout the tests will check the output sent to cout.
In part 1 tests 2, 3 and 4 check the output sent to cout. The rest of the tests check the output sent to file saleschart.txt.
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