You are working for a lumber company, and they would like aprogram that calculat
ID: 3566177 • Letter: Y
Question
You are working for a lumber company, and they would like aprogram that calculates the cost of lumber for an order. Thecompany sells pine, fir, ceder, maple, and oak lumber. Lumber ispriced by board feet. One board foot equals one square foot, oneinch thick. The price per board foot is given in the followingtable:
Pine 0.89
Fir 1.09
Cedar 2.26
Maple 4.50
Oak 3.10
The lumber is sold in different dimensions (specified in inchesof width and height, and feet of length) that need to be convertedto board feet. For example, a 2*4*8 is 2 inches wide, 4 incheshigh, and 8 feet long, and is equivalent to 5.333 board feet. Anentry from the user will be in the form of a letter and fourinteger numbers. The integers are: number of pieces, width, height,and length. The letter will be one of P, F, C, M, O (correspondingto the five the kinds of wood) or T meaning Total. When the letteris T, there are no integers following it on the line. The programshould print out the price for each entry, and print the totalafter T is entered. Here is an example run:
Enter item: P 10 2 4 8
10 2*4*8 Pine, cost: $47.47
Enter item: M 1 1 12 8
1*12*8 Maple, cost: $36.00
Enter item: T
Total cost: $83.47
Develop the program using functional decomposition, and use proper style and documentation in your code. Your program shouldmake appropriate use of value returning functions in solving thisproblem. Be sure that the user prompts are clear, and that theoutput is labeled appropriately.
You need to make a correction as following;
1. The input data should be from the keyboard and the output should be printed to the monitor.
2. The program gets many lines of inputs as required by the problem. So you need to use a looping statement with sentinel value, 'T' or 't' to stop the looping. The letters may be uppercases or lowercases of P, F, C, M, O, and T.
3. You may use switch statement or if-else statement.
4. You need to use at least 4 functions as following;
1) GetData: to get the input data to pass to the main body with parameters.
2) CalculateBoardFeet: to calculate the board feet with the input data passed from the mainbody to pass the board feet back to main body.
3) CalculateCost: to calculate the prices of the lumber based on the board feet and the unit prices per board feet passed from the main body and to pass the cost back to the main body.
4) PrintOutPut: to print the outputs as shown at the problem to the monitor.
5. You may use either "void" functions or "value-return" functions.
6. You may use either "value parameters" or "reference parameter".
7. You need to place the main body in front of all the functions. So you need to use the function prototypes of them.
Explanation / Answer
#include<iostream> //Allows program to perform input and output
using std::cout; // Programuses cout
using std::cin; // Program usescout
double rate(char, int, double); // Prototype of the function
int main() // function mainbegins program execution
{
char type;
int quantity, width, height, length;
double total_cost = 0.0;
do
{
cout << " Enter the type of lumber :";
cin >> type;
if (tolower(type) == 't' )
break;
// cout << " Enter thenumber of pieces : ";
cin >> quantity;
// cout << " Enter thewidth : ";
cin >> width;
// cout << " Enter theheight : ";
cin >> height;
// cout << " Enter thelength : ";
cin >> length;
cout << " "<< quantity << " "<< width << " * "
<< height << " * " <<height;
double board_feet = ( width * height * length ) / 12.0;
total_cost += rate(type, quantity,board_feet);
} while (true);
cout << " Total cost is $" <<total_cost;
return 0; // indicate programexecuted successfully
} // end offunction, main
// returns the cost
double rate(chartype, int quantity, double board_feet)
{
double cost;
switch(type)
{
case 'p' :cost = 0.89 * board_feet;
break;
case 'f' :cost = 1.09 * board_feet;
break;
case 'c' :cost = 2.26 * board_feet;
break;
case 'm' :cost = 4.5 * board_feet;
break;
case 'o' :cost = 3.1 * board_feet;
break;
} // endswitch
cost = cost * quantity;
cout << " cost : $" <<cost;
return cost;
} // endfunction rate
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.