You\'re working for a lumber company, and your employer would like a program tha
ID: 3633786 • Letter: Y
Question
You're working for a lumber company, and your employer would like a program that calculate 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 dimension ( specified in inches of width and height, and feet of length) that need to be converted to board feet. For example, a 2 * 4 * 8 piece is 2 inches wide, 4 inches high, and 8 feet long, and is 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 kinds of wood) or T, meaning total. when the letter is 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. Here is an example run:
Enter item: P 10 2 4 8
10 2x4x8 pine, cost: $47.47
Enter item: M 1 1 12 8
1 1x12x8 maple, cost: $36.00
Enter item: T
Total cost: $83.47
Develop the program using functional decomposition,and proper style and documentation in your code. your program should make appropriate use of value- returning function in solving this problem. Be sure that the user prompts are clear, and that the outputs is labeled appropriately.
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
using namespace std;
void getinfo(char, double&, string &);
double input();
double finish(double,double,string);
int main()
{double total=0,feet,cost;
cout.setf(ios::fixed,ios::floatfield);
cout.precision(2);
char type;
string wood;
cout<<"Enter item: ";
cin>>type;
while(type!='T')
{feet=input();
getinfo(type,cost,wood);
total+=finish(cost,feet,wood);
cout<<"Enter item: ";
cin>>type;
}
cout<<"Total cost: $"<<total<<endl;
system("pause");
return 0;
}
double finish(double cost,double feet,string wood)
{
cost*=feet;
cout<<wood<<", cost:$"<<cost<<endl;
return cost;
}
double input()
{int l,w,d,num;
double feet;
cin>>num>>l>>w>>d;
feet=((double)(l*w)/12)*d*num;
cout<<num<<""<<l<<"x"<<w<<"x"<<d<<" ";
return feet;
}
void getinfo(char type,double& cost, string &wood)
{ if(type=='P')
{cost=.89;
wood="Pine";
}
else if(type=='F')
{cost=1.09;
wood="Fir";
}
else if(type=='C')
{cost=2.26;
wood="Cedar";
}
else if(type=='M')
{cost=4.5;
wood="Maple";
}
else if(type=='O')
{cost=3.1;
wood="Oak";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.