Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 X characters.

You are required to have your main function and two additional functions.

main function

Your main function will be 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.

You main will then have a processing loop that will call the read function.

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

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

SALES BAR CHART (Each X equals 1,000 dollars) 

Note: Your program must not output the headings to the output file if all of the data in the input file is invalid, or if there is not data in the input file.

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 of calling the display function.

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. Assume the file we are reading in from is called sales.txt, and the file does not exist. The error message written to cout is:

File "sales.txt" could not be opened 

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

read function

The read function will return a value of true if data has been read, and will return a value of false if you have reached end of file.

The input file (of type ifstream) must be passed to the function by reference. A long long int value also needs to be passed by reference to the read function. This is where the sales data will be stored. A third parameter of type unsigned int needs to be passed by reference as well. This will be the store number. The store number is an unsigned int in the range of 1 to 99.

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 the contents of a sample input text file:

1 10000 2 25000 3 37000 4 29000 5 8000 

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 less than 0 you need to output the following message to cout:

The sales value for store xx is negative 

Where xx is the store number.

If either (or both) of these values are invalid your read function should loop and read in the next store number and sales value and validate them.

Every time you read from the input file you need to read in both the store number and the store sales value. After you have read in the two values you need to check to see if they are valid.

display function.

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 the output file.

The output file is passed to you by reference. The store number and store sales are also passed to you but they are passed by value.

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

Store 9: XXXXXX 

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

Store yy: XXXXXXX 

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

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:

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 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 could 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, 5, 6, and 7 check the output sent to cout. The rest of the tests check the output sent to file saleschart.txt.

Error message "Could not find main function"

Now that we are using functions some of the tests are unit tests. In the unit tests the zyBooks environment will call one or more of your functions directly.

To do this it has to find your main function.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

Students also viewed these Databases questions