Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You\'re working for a lumber company, and your employer would like a program tha

ID: 3633215 • Letter: Y

Question

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 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 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. 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.

Explanation / Answer

#include <iostream>

//#include

//#include

using namespace std;

#define PINE_$ 0.89;

#define FIR_$ 1.09;

#define CEDAR_$ 2.26;

#define MAPLE_$ 4.50;

#define OAK_$ 3.10;

//function

float findBoardFeet (int width, int height, int length );

int main ()

{

      cout << "COST OF LUMBER" << endl << endl;

      int wth, hght, lgth, pieces;

      char wood;

      float boardfeet = 0.0;

      float cost, totalcost = 0.0;

      do

      {

            cout << "Enter Item: ";

            cin >> wood;

            wood = toupper(wood);

            if(wood != 'T')

               cin >> pieces >> wth >> hght >> lgth;

            if((wood != 'P') && (wood != 'F') && (wood != 'C') && (wood != 'M') && (wood != 'O') && (wood != 'T'))

            {

                  cout << "Invalid wood type, try again" << endl;

            }

            else

            {

                  if(wood == 'T')

                        cout << "Total Cost: $" << totalcost << endl;

                  else

                  {

                        boardfeet = findBoardFeet(wth, hght, lgth);

                        switch(wood)

                        {

                        case 'P':

                              cost = boardfeet * pieces * PINE_$;

                              cout << "Pine Cost:   $" << cost << endl;

                              break;

                        case 'F':

                              cost = boardfeet * pieces * FIR_$;

                              cout << "Fir Cost:   $" << cost << endl;

                              break;

                        case 'C':

                              cost = boardfeet * pieces * CEDAR_$;

                              cout << "Cedar Cost:   $" << cost << endl;

                              break;

                        case 'M':

                              cost = boardfeet * pieces * MAPLE_$;

                              cout << "Maple Cost:   $" << cost << endl;

                              break;

                        case 'O':

                              cost = boardfeet * pieces * OAK_$;

                              cout << "Oak Cost:   $" << cost << endl;

                              break;

                        default:

                              break;

                        }

                        totalcost = totalcost + cost;

                  }

            }

      }

      while(1);

      return 0;

}

//function to return value

float findBoardFeet (int width, int height, int length )

{

      float BoardFeet = 0.0;

      BoardFeet = (width * height * length) / 12.0;

      return BoardFeet;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote