Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A lumber company needs a program to calculate the cost of lumber for an order. The company sells pine, fir, cedar, maple and oak lumber.

A lumber company needs a program to calculate the cost of lumber for an order. The company sells pine, fir, cedar, maple and oak lumber. All lumber is priced per board foot. One board foot is equal to one square foot one inch thick. The price per board foot is:

Pine $0.89

Fir 1.09

Cedar 2.26

Maple 4.40

Oak 3.10

The lumber is sold in different dimensions (specified in inches of width and thickness, and feet of length) which need to be converted to board feet. For example a piece of wood 2 X 4 X 8 is 2 inches thick, 4 inches wide and 8 feet long. That is equivalent to 5.333 board feet. The user will enter the type of lumber (P, F, C, M or O) and an integer and three doubles indicating the number of pieces, thickness, width and length, or T indicating the order should be totaled. A typical run might be:

Enter item: i

I is not a valid type!

Reenter. o

Enter number of pieces and thickness width and length 100 2.5 3 20

100 2.50 X 3.00 X 20.00 Oak, cost: $3875.00

Enter item: p

Enter number of pieces and thickness width and length 150 3 3.5 22 150

3.00 X 3.50 X 22.00 Pine, cost: $2569.88

Enter item: t

Total cost: $6444.88

More purchases? n

Ive given you the program with the function prototypes and the code for main. You need to write the function definitions.

#include

#include

#include

using namespace std;

const double INCHESINLINEARFOOT = 12.0;

const double INCHESINONESQUAREFOOT = 144.0;

const double PINECOST = 0.89;

const double FIRCOST = 1.09;

const double CEDARCOST = 2.26;

const double MAPLECOST = 4.40;

const double OAKCOST = 3.10;

bool validateType(char t);

// Return true if t represents a valid wood type or false otherwise

double calcBoardFeet(double th, double wid, double len);

// calculate board feet where th = thickness in inches,

// wid = width in inches and len = length in feet

double calcCost(char type, int numP, double bf);

// calculate cost based on type, number of pieces and board feet

string getTypeName(char type);

// return name of wood type based on char representing type, eg P = Pine

void getData(char & woodType, int & numPieces, double &thickness, double & width, double & length);

// Get data on sale

int main()

{

char woodType, reply;

int numPieces;

double thickness, width, length;

double cost, totalCost, boardFeet;

string woodTypeName;

cout << fixed << setprecision(2);

do

{

totalCost = 0;

do

{

getData(woodType, numPieces, thickness, width, length);

if (woodType != 'T')

{

boardFeet = calcBoardFeet(thickness, width, length);

cost = calcCost(woodType, numPieces, boardFeet);

woodTypeName = getTypeName(woodType) + ", cost: $";

cout << setw(3) << numPieces << setw(6) << thickness << " X " << setw(6) << width << " X " << setw(6) << length << " " << setw(14)

<< woodTypeName << cost << endl;

totalCost+= cost;

}

}while (toupper(woodType) != 'T');

cout << "Total cost: $" << totalCost << endl;

cout << "More purchases?" << endl;

cin >> reply;

}while (toupper(reply) == 'Y');

}

//Function definitions here:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions