The Problem:
You’re working for a lumber company, and your employer would like a program that calculates the cost of lumber for an order. The company sells pine, fir, cedar, maple, and oak lumber. Lumber is priced by board feet. One board foot equals one square foot, one inch thick. The price per board foot is given in the following table:
Pine 0.89
Fir 1.09
Cedar 2.26
Maple 4.50
Oak 3.10
The lumber is sold in different dimensions (specified in inches of width and height, and feet of length) that need to be converted to board feet. For example, a 2 x 4 x 8 piece is 2 inches wide, 4 inches high and 8 feet long, and equivalent to 5.333 board feet. An entry from the user will be in the form of a letter and four integer numbers. The integers are the number of pieces, width, height, and length. The letter will be one of P, F, C, M, O (corresponding to the five kind of wood) or T, meaning total. When the letter T, there are no integers following it on the line. The program should print out the price for each entry, and print the total after T is entered.
Develop the program using functional decomposition, and use proper style and documentation in your code. Your program should make appropriate use of value-returning functions in solving this problem. Be sure that the user prompts are clear, and that the output is labeled appropriately.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include<iostream>
#include<string>
using namespace std;
double calcCost(int amntPieces, int width, int length,
int height, char woodType);
int main()
{
int amntPieces, width, length, height;
double total = 0.0, cost;
char woodType;
do
{
cout<<"Enter item:";
cin>>woodType;
if(woodType=='T')
{
cout<<"Total cost: $"<<total<<endl;
break;
}
cin>>amntPieces;
cin>>width;
cin>>length;
cin>>height;
cost=calcCost (amntPieces, width,length,height,woodType);
cout<<", Cost: $"<<cost<<endl;
total+=cost;
}while(woodType!='T');
system("pause");
}
double calcCost(int amntPieces, int width, int length, int height, char woodType)
{
double cost;
string name;
cost= (length * width *height)/12.0;
cost= amntPieces * cost;
if (woodType=='P')
{
cost=cost*0.89;
name="Pine";
}
else if (woodType=='F')
{
cost=cost*1.09;
name="Fir";
}
else if(woodType=='C')
{
cost=cost*2.26;
name="Cedar";
}
else if (woodType=='M')
{
cost=cost*4.50;
name="Maple";
}
else if (woodType=='O')
{
cost=cost*3.10;
name="Oak";
}
cout<<amntPieces<<" "
<<width<<"x"<<length<<"x"<<height<<name;
return cost;
}
|