CPE 101
Laboratory 4 (Selection)

You must turn in your source electronically on unix1 using the handin command – instructions are provided below.

Objectives

·         To practice writing code that uses selection.

·         To practice problem solving.

·         To develop a complete C program, compile it, and turn it in electronically.

Resources

·         Your instructor, peers, texts, and your own innate capabilities and resourcefulness!

Orientation…

You've been hired by a local lumberyard to help computerize its operations.  Your first assignment is to write a program that computes the total amount of an item ordered in standard units, given its type, dimensions, and the number of pieces ordered.  The yard sells two kinds of items: boards and plywood panels.  First, the program should read a letter - either 'B' for board or 'P' for plywood - to determine the type.  Next it should read four integer numbers. 

For lumber, the first two numbers are the width and the depth in inches; the third number is the length in feet; and the fourth number is the number of pieces ordered.  To compute the quantity ordered, you have to calculate the total volume ordered.  The unit for board volume is board foot, which is equivalent to 1 square foot of lumber, 1 inch thick, or 144 cubic inches.  For example, given 14 pieces of 2-inch by 4-inch lumber, each 8 feet long, the quantity ordered is 74.67 board feet.  To determine the board feet, we use this formula:

(2 in. x 4 in. x (8 ft. x 12 in./ft) x 14 pieces)/144 cubic in. per board foot

For plywood, the first two numbers are the thickness of the sheet, expressed as a fraction; the third number is the length of the sheet in feet, and the last number is the number of sheets ordered.  The lumberyard only stocks plywood in sheets in 4-foot widths, so there's no need to enter the width.  At this lumberyard, the unit for plywood volume is a full sheet.  A full sheet is 4 feet (48 inches) wide, 8 feet (96 inches) long, and 1 inch thick, or 4608 cubic inches.  Given 18 sheets of 3/4-inch-thick plywood, 8 feet long (and 4 feet wide), the quantity ordered is 13.5 full sheets.  We use this formula:

(18 sheets x 3/4 in. x (8 ft x 12 in./ft) x 48 in.)/4608 cubic in. per sheet

Finally, you must display a message based on the amount of lumber ordered telling the customer what they've earned in the lumberyard's Buyer's Rewards Program.  Display the following messages given the amount of lumber ordered.

For boards:

For panels:

Part 1: Develop the lumberyard program.

Follow the steps in the process for how to build a program.   Importantly you must create a test plan that causes all possible outputs to be produced.

The instructor has created the required header file for this activity: lumber_utils.h.   This file provides the function prototypes you are to follow. 

Create an implementation for each of the functions specified in the header file.  Put the implementations in a separate file named lumber_utils.c.  Note that none of the functions do any input or output to the user.  Do not include a main function in this file.

Create unit tests in a separate file named lumber_test.c.  This file contains only a main function and unit tests (calls to checkit).  Create calls to checkit to invoke each of the functions you implemented and pass as input parameters the values from your test plan.  

Create an executable by linking both the implementation and the unit tests object files together. 

Run the unit tests and correct any errors until they are all passing.

Now create a client program in a separate file named lumber_client.c.  The client should contain only a main function.  The main function should interact with the user to obtain input values and display the corresponding results.  See sample output below.

You do not need to check for incorrect user input.  Assume the user will correctly enter a 'B' or 'P' when queried for the lumber type.

Be sure to display the correct prompts given the type of lumber selected.  See below! 

Run your program using all the test cases in your test plan and verify that it produces the expected results.

Part 2: Sample output

Two different example runs appear below (user input shown underlined):

Sample Run 1:

Would you like to order boards or panels (B or P)? B

Width (in inches): 2

Depth (in inches): 4

Length (in feet): 8

Quantity: 14

 

Quantity ordered is 74.67 board feet.

You've earned a free 'Save Old Growth Forests' sticker.

 

 Sample Run 2:


Would you like to order boards or panels (B or P)? P

Numerator of thickness: 3

Denominator of thickness: 4

Length (in feet): 8

Quantity: 18

 

Quantity ordered is 13.5 full sheets.

You've earned a free carpenter's tool belt.

Part 3:  Get Feedback (suggested)

Show your completed test plans and passing unit tests to your instructor. 
Show your execution output to the instructor.
Show your completed source code to the instructor.


Part 4: Handing in Your Source Electronically

  1. Verify that your completed source files lumber_utils.c, lumber_test.c, lumber_client.c compile and execute on unix1.
  2. Put both student names in the header comment of each file.
  3. Use the handin command below,

  4. handin graderjd Lab04 lumber*.c