Question: This lab lesson you are writing a program for the hypothetical Acme Wholesale Copper Wire Company . The Acme company sells spools of copper wiring

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. The number of spools ordered and in stock are of type int and the shipping charge is of type double.

Here is the general logic for the read function:

Prompt for the number of spools being ordered

Read in the value for the number of spools being ordered

If the spools ordered is less than 1 display a message (see below for details) and return false

Prompt for the number of spools in stock

Read in the value for number of spools in stock

If the spools in stock is less than 0 display a message and return false

Ask if there is special shipping and handling

If yes (y)

Prompt for shipping and handling.amount

Read in the shipping and handling amount

If the shipping and handling charge is less than 0 display a message and return false

If the shipping and handling question returned something other than y

Set shipping and handling to the default value ($11.88)

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 number ordered is greater than the number currently 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.

Call the read function. If the read function returns a value of true pass the ordered spools, spools in stock, and shipping and handling charge to the display function. 

Note that the read function does NOT call the display function. The display function does not call the read function. These functions are called by the main 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

10 -1 

The contents of cout after the run:

Spools to be ordered Spools in stock Spools in stock must be 0 or more

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!