Please provide screenshot of code. please include every detail and a code that can be copied and pasted. Thank you! In this program you will be reading sales information from a file and writing out a bar chart for each of the stores. The bar charts will be created by writing out a sequence of * characters. You will have to create input files for your program. You can use a text editor such as Notepad or Notepad++ to create this.  Reading in files When reading data from a file you need to make sure you are checking for end of file properly. The general method shown below: ifstream inputFile; inputFile.open("input.txt"); int num; if (inputFile) { // the file opened successfully while (inputFile >> num) { // process the num value cout << num << endl; } inputFile.close(); } else { cout << "The file could not be opened" << endl; } If you want to read in two values with every read you can simply replace inputFile >> num with something like inputFile >> num1 >> num2 as shown here: while (inputFile >> num1 >> num2) { // process the num1 and num2 values cout << num1 << " " << num2 << endl; } Text files are more complicated that they seem. On Windows lines of text end with \r followed by \n. Most text files have every line ending with either \r \n (for Windows). if (inputFile >> num1 >> num2) { // executes only if the read worked } or while (inputFile >> num1 >> num2) { // executes while the read works } There are other ways to test for end of file but you have to make sure your code will work for all of the cases discussed above. It is STRONGLY recommended that you use the process outlined above. Your program will read in a file name from cin. It will then open the input file. Your program must also open an output file called saleschart.txt. You will write the bar char headings and data to this file. Your program needs to have the following general flow: prompt for the input file name "Enter input file name" read in the file name open the input file for this file name display a message if the input file does not open and quit your program open the output file ("saleschart.txt") display a message if the output file does not open, close the input file, and quit your program while (readFile into store number and sales for store if store number or sales are invalid display an appropriate error message (see below) else output bar chart for this store to the output file end if end while close the input and output files The processing loop will read the input data and process it until it gets and end of file indication from the file read operation Assuming you have read in valid data AND this is the first sales data being processed your program should output some headings to the output file before processing the data. The headings are as follows: SALES BAR CHART (Each * equals 5,000 dollars) You need to come up with a way of keeping track if this is the first valid read or not. Assuming you have valid data the processing will consist displaying the output Once the loop has completed you need to close the input file. If the input file could not be opened your program should output an error message to cout. Example error message is: File "sales.txt" could not be opened The store number is of type unsigned int. Your program must verify that the store number is in the range 1 to 99 (inclusive). Display following message if the store number is invalid: If the store number is less than 1 or greater than 99 you need to output the following message to cout: The store number xx is not valid Where xx is the store number. If the sales data is read in as a long long int. If the sales value is less than 0 output the following message to cout: The sales value for store xx is negative Where xx is the store number. Don't forget to close both files, if they were opened. Write the bar chart information to the file. You will be outputting a string of * characters where each * represents $5,000 in sales for that store. For each 5,000 in sales you output one *. You do not round up the sales, so sales of $16,000 and sales of $16,999 would both output 3 * characters. You will output the sales bar chart to the output file. Assuming a store number of 9 and sales of $16,999. The display function will write the following to the output file: Store 9: *** Note that the store width is 2 characters, so the output is: Store yy: ******* The yy has a width of 2 even if the store number is 1 through 9. The format of the input file The data in the input file is in the order store number followed by the store sales. There will be zero or more of these input pairs in the file. Here is sample input text file: 1 10000 2 25000 3 37000 4 29000 5 8000 Sample runs Example run. Assume the following input being read in from cin: sales.txt

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter7: File Handling And Applications
Section: Chapter Questions
Problem 7RQ
icon
Related questions
Question

Use C++

Please provide screenshot of code.

please include every detail and a code that can be copied and pasted.

Thank you!

In this program you will be reading sales information from a file and writing out a bar chart for each of the stores. The bar charts will be created by writing out a sequence of * characters.

You will have to create input files for your program. You can use a text editor such as Notepad or Notepad++ to create this. 

Reading in files

When reading data from a file you need to make sure you are checking for end of file properly.

The general method shown below:

ifstream inputFile; inputFile.open("input.txt"); int num; if (inputFile) { // the file opened successfully while (inputFile >> num) { // process the num value cout << num << endl; } inputFile.close(); } else { cout << "The file could not be opened" << endl; }

If you want to read in two values with every read you can simply replace inputFile >> num with something like inputFile >> num1 >> num2 as shown here:

while (inputFile >> num1 >> num2) { // process the num1 and num2 values cout << num1 << " " << num2 << endl; }

Text files are more complicated that they seem. On Windows lines of text end with \r followed by \n.

Most text files have every line ending with either \r \n (for Windows).

if (inputFile >> num1 >> num2) { // executes only if the read worked }

or

while (inputFile >> num1 >> num2) { // executes while the read works }

There are other ways to test for end of file but you have to make sure your code will work for all of the cases discussed above. It is STRONGLY recommended that you use the process outlined above.

Your program will read in a file name from cin. It will then open the input file.

Your program must also open an output file called saleschart.txt. You will write the bar char headings and data to this file.

Your program needs to have the following general flow:

prompt for the input file name "Enter input file name" read in the file name open the input file for this file name display a message if the input file does not open and quit your program open the output file ("saleschart.txt") display a message if the output file does not open, close the input file, and quit your program while (readFile into store number and sales for store if store number or sales are invalid display an appropriate error message (see below) else output bar chart for this store to the output file end if end while close the input and output files

The processing loop will read the input data and process it until it gets and end of file indication from the file read operation

Assuming you have read in valid data AND this is the first sales data being processed your program should output some headings to the output file before processing the data. The headings are as follows:

SALES BAR CHART (Each * equals 5,000 dollars)

You need to come up with a way of keeping track if this is the first valid read or not.

Assuming you have valid data the processing will consist displaying the output

Once the loop has completed you need to close the input file.

If the input file could not be opened your program should output an error message to cout. Example error message is:

File "sales.txt" could not be opened

The store number is of type unsigned int. Your program must verify that the store number is in the range 1 to 99 (inclusive). Display following message if the store number is invalid:

If the store number is less than 1 or greater than 99 you need to output the following message to cout:

The store number xx is not valid

Where xx is the store number.

If the sales data is read in as a long long int. If the sales value is less than 0 output the following message to cout:

The sales value for store xx is negative

Where xx is the store number.

Don't forget to close both files, if they were opened.

Write the bar chart information to the file.

You will be outputting a string of * characters where each * represents $5,000 in sales for that store. For each 5,000 in sales you output one *. You do not round up the sales, so sales of $16,000 and sales of $16,999 would both output 3 * characters.

You will output the sales bar chart to the output file.

Assuming a store number of 9 and sales of $16,999. The display function will write the following to the output file:

Store 9: ***

Note that the store width is 2 characters, so the output is:

Store yy: *******

The yy has a width of 2 even if the store number is 1 through 9.

The format of the input file

The data in the input file is in the order store number followed by the store sales. There will be zero or more of these input pairs in the file.

Here is sample input text file:

1 10000 2 25000 3 37000 4 29000 5 8000

Sample runs

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:

1 10000 2 25000 3 37000 4 29000 5 8000

The output (to file saleschart.txt) for this input would be:

SALES BAR CHART (Each * equals 5,000 dollars) Store 1: ** Store 2: ***** Store 3: ******* Store 4: ***** Store 5: *

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning