Question: Please read all the instruction below. And please use c++, thank you. Lab lesson 9 has two parts. There are also 10 bonus points. To

Please read all the instruction below. And please use c++, thank you.

Lab lesson 9 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 9.

Both parts will be making use of functions, and pass by reference.

Part 1 is worth 35 points (25 points for passing the tests and 10 for your code). Failure to meet the requirements could result in loss of points beyond the 10 for the code formatting, variable names, and so on.

This lab lesson you are writing a program for the hypothetical Acme Wholesale Copper Wire Company. The Acme company sells spools of copper wiring for $100 each. Write a program that displays the status of an order.

This program will be reading in from cin and writing to cout.

In this program you will need at least three functions, including main as one of the three.

You must use function prototypes for all of the functions (except main).

Read function

You need to have a function that reads in the following data:

The number of spools ordered

The number of spools currently in stock

Any special shipping and handling charges (see description below).

Your program needs to prompt for these values. The prompts are below under Sample with special shipping and handling.

Do not accept a number less than 1 for the number of spools ordered.

Do not accept a number less than 0 for the number of spools in stock.

Do not accept a shipping and handling charge of less than 0.

For each of these cases you will have to have a loop that issues an error message, prompts for the input value again, and checks the data for validity.

The normal shipping and handling is $11.88 per spool. You will have to ask if there is special shipping and handling. If there is you will need to read in the special shipping and handling charge.

Here are a couple of sample runs. One with the default shipping and handling and one with special shipping and handling.

Sample with default shipping:

Assume the following input from cin:

10 100 n 

Here are the prompts to read in the spools to be ordered, spools in stock and shipping and handling:

Spools to be ordered Spools in stock Special shipping and handling (y or n) 

Sample with special shipping and handling:

Assume the following input from cin:

10 100 y 9.99 

Here is the output or the prompts to cout:

Spools to be ordered Spools in stock Special shipping and handling (y or n) Shipping and handling amount 

Note that the Shipping and handling amount prompt is only written out if the input from cin was y from the Special shipping and handling (y or n) prompt.

If the input from the Shipping and handling amount is any value other than y (lower case y) you can assume the default shipping and handling amount. There is not validity checking for this value other than y and any other value (meaning no special shipping and handling).

The read function needs to return three values:

spools to be ordered

spools in stock

shipping and handling (either the default value or one specified by the user).

Since a function can only return one value we cannot return the values via the return statement. Instead you need to pass three variables to the read function and pass them by reference. That way the read function can update the actual variables passed to the read function. You not NOT use any global variables.

error messages

Here are the error messages that the read function may generate:

Spools order must be 1 or more Spools in stock must be 0 or more The spool shipping and handling charge must be 0.0 or more 

The above processing is all done in the read function.

The values you read into (for the spools ordered, spools in stock and the shipping and handling charge) all need to be passed to the read function by reference. This is needed because the read function will be updating all three variables and it needs access to the variables.

The returned shipping charge will either be the default charge of $11.88 per spool or the special shipping and handling charge (if requested).

Display function

You will also need a display function that takes the spools ordered, spools in stock and the shipping and handling charges. These values will not be changed by the function, so these can all be passed by value.

The display function needs to display:

the number of spools (ordered) that are ready to ship from the current stock

the number of spools on back-order (if the numbered ordered is greater than what is in stock)

the subtotal of the spools ready to ship (the number ready to ship times $100)

the total shipping and handling charges for the spools ready to ship

the total of the order ready to ship

The display function will output these values to cout.

Assume the number of spools ordered is 9 and there are 5 spools in stock. Assume the shipping cost is $10. The output would be as follows. All of the amounts should have two digits to the right of the decimal point and a leading $ character. The total width of the number (not including the $ character) is 10 characters.

Spools to be ordered Spools in stock Special shipping and handling (y or n) Shipping and handling amount Spools ready to ship: 5 Spools on back-order: 4 Subtotal ready to ship: $ 500.00 Shipping and handling: $ 50.00 Total shipping charges: $ 550.00 

The main function

The main function is fairly simple. You need to call the read function and then pass the updated values to the display function.

Here are some sample runs:

Sample run # 1 (valid input with special handling):

Assume the following is read in from cin

9 5 y 10.0 

The contents of cout:

Spools to be ordered Spools in stock Special shipping and handling (y or n) Shipping and handling amount Spools ready to ship: 5 Spools on back-order: 4 Subtotal ready to ship: $ 500.00 Shipping and handling: $ 50.00 Total shipping charges: $ 550.00 

Sample run # 2 (valid input, no special handling)

The following is read in from cin

35 35 n 

The following would be written to cout:

Spools to be ordered Spools in stock Special shipping and handling (y or n) Spools ready to ship: 35 Spools on back-order: 0 Subtotal ready to ship: $ 3500.00 Shipping and handling: $ 415.80 Total shipping charges: $ 3915.80 

Sample run # 3 (invalid input)

Assume the following is read in from cin

0 200 -1 12 y -0.01 5.99 

The contents of cout after the run:

Spools to be ordered Spools order must be 1 or more Spools to be ordered Spools in stock Spools in stock must be 0 or more Spools in stock Special shipping and handling (y or n) Shipping and handling amount The spool shipping and handling charge must be 0.0 or more Shipping and handling amount Spools ready to ship: 12 Spools on back-order: 188 Subtotal ready to ship: $ 1200.00 Shipping and handling: $ 71.88 Total shipping charges: $ 1271.88 

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.

Right now zyBooks has a problem with this when your int main() statement has a comment on it.

For example:

If your main looks as follows:

int main() // main function 

You will get an error message:

Could not find main function 

You need to change your code to:

// main function int main() 

If you do not make this change you will continue to fail the unit tests.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!