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

Lumber Order - C++ Note: Cannot use classes or arrays, only functions! You are t

ID: 673097 • Letter: L

Question

Lumber Order - C++

Note: Cannot use classes or arrays, only functions!

You are to write a program to compute the cost of a lumber order for a local lumber company. The company sells pine, fir, cedar, maple, and oak lumber and the 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 1.05 Fir 1.29 Cedar 2.25 Maple 4.10 Oak 2.40

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 es, a 2 x 4 x8 piece is 2 inches wide, 4 inches high, and 8 feet long, and is equivalent to 5.333 board feet (possibly not the correct calculation).

The input will be for several customers, each with a lumber order. The lumber order will have several types of wood and different sizes in each order.

Input file: 'LumberOrder.txt' (file can be found here: http://pastebin.com/A8FvaPms)
Output file: 'LumberReport.txt' (must send to output file)

The input format for an order will be first: a label 'Customer #:' followed by the customer's ID number. The next lines contain the lumber order, starting with a letter (P, F, C, M, O) corresponding to the five kinds of wood, or a T meaning total. When the letter is a T, there will be no other numbers following the T. The program should print out each entry (itemized the order) and print out the toal cost of the order.

Example input:
Customer #; 1020
P 10 2 4 8      // Pine 10 pieces 2 inches by 4 inches by 8 feet
M 3 1 6 10    // Maple 3 pieces 1 inch by 4 inches by 10 feet
T       // Flag for the program to print the toatl cost of this order.

Customer #: 2040
C ......           // New wood order for next customer.
T

Example Output:
                 Customer Order Report
   Customer# 1020
Pieces     Size     Wood     Cost
10            2x4x8 Pine       $47.47
3              1x6x10 Maple   $11.25
                       Total:     $1340.28

Customer # 2040           // Next Customer report

Explanation / Answer

Program:

// lumberprice.cpp : main project file.

#include "stdafx.h"

#include<iostream>

#include<fstream>

#include<cmath>

#include<iomanip>

#define costOfP 1.05

#define costOfF 1.29

#define costOfC 2.25

#define costOfM 4.10

#define costOfOak 2.40

using namespace std;

using namespace System;

int main()

{

int customerId,noOfPieces,wide,high,temp;

double length,Cost,temp1;

char typeOfLumber;

ofstream outData;

ifstream inData;

inData.open("LumberOrder.txt");

outData.open("LumberReport.txt");

inData>>"Customer#">>customerId>>typeOfLumber>>noOfPieces>>wide>>high>>length;

if(typeOfLumber=='P')

temp=wide*high;

temp1=(double)(temp)/12.0;

Cost=typeOfLumber*temp1*length*costOfP;

if(typeOfLumber=='F')

temp=wide*high;

temp1=(double)(temp)/12.0;

Cost=noOfPieces*temp1*length*costOfF;

if(typeOfLumber=='C')

temp=wide*high;

temp1=(double)(temp)/12.0;

Cost=noOfPieces*temp1*length*costOfC;

if(typeOfLumber=='M')

int temp=wide*high;

double temp1=(double)(temp)/12.0;

Cost=noOfPieces*temp1*length*costOfM;

if(typeOfLumber=='O')

temp=wide*high;

temp1=(double)(temp)/12.0;

Cost=noOfPieces*temp1*lenght*costOfOak;

outData<<"CustomerOrder Report";

outData<<"Customer#"<<customerId;

outData<<"Pieces"<<"Size"<<"Wood"<<"Cost";

outData<<noOfPieces+" "<<wide+"*"+high+"*"+length<<" "<<typeOfLumber<<Cost+"$"<<endl;

inData.close();

outData.close();

return 0;

}

Create InputFile " LumberORder.txt" with text:

Customer#,1020
P 10 2 3 8
M 3 1 6 10
T

Customer#,2040
C 10 2 3 8
M 3 1 6 10
T

create outputfile with name "LumberReport.txt"

the output is saved in the LumberReport.txt