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

Using C++. I also have to use either input or output with a .txt file. I am goin

ID: 3702778 • Letter: U

Question

Using C++. I also have to use either input or output with a .txt file. I am going to attach the .txt with this. Thank you.

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 for width and height, and feet for length) that need to be converted to board feet. For ex, 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.  

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

Input file:   ‘LumberOrder.txt’

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 total cost of the order. You must use Functions. One to read the data, one to compute board feet, one to compute cost, one to print a line of output (maybe more output functions.)

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 inche by 6 inches by 10 feet

                        …

                        T                                             Flag for the program to print the total cost of
                                                                                this order.

                        Customer #: 2040

                        C ……..                                   new wood order for next customer.

                        T

                        …

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

                               …

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

double calBoardFeet(int h,int w,int l){
return ((h*w*l*12)/144);
}

double calCost(string type,int quantity, double boardFeet) {
double c;
if (type=="P"){
c =(1.05*quantity*boardFeet);
}
if (type=="F"){
c = (1.29*quantity*boardFeet);
}
if (type=="C"){
c = (2.25*quantity*boardFeet);
}
if (type=="M"){
c = (4.1*quantity*boardFeet);
}
if (type=="O"){
c = (2.4*quantity*boardFeet);
}
return c;
}

int main() {
cout<<"sdfds";
ifstream inFile;
inFile.open("test.txt");
ofstream outFile;
outFile.open("out.txt");
outFile << " Customer Order Report ";
cout<<"confirm";
string x;
string ID;
string type;
int quantity;
int h;
int w;
int l;
double boardFeet;
double cost;
double totCost;
while (!inFile.eof()) {
inFile >> x;
totCost=0;
inFile>>x;
inFile>>ID;
outFile <<" Customer # "<<ID<<" ";
outFile << "Pieces Size Wood Cost ";
inFile>>type;
string typeFull;
if (type=="P"){
typeFull="Pine";
}
if (type=="F"){
typeFull="Fir";
}
if (type=="C"){
typeFull="Cedar";
}
if (type=="M"){
typeFull="Maple";
}
if (type=="O"){
typeFull="Oak";
}
while(type!="T") {
inFile>>quantity;
inFile>>h;
inFile>>w;
inFile>>l;
boardFeet=calBoardFeet(h,w,l);
cost=calCost(type,quantity,boardFeet);
totCost=totCost+cost;
outFile <<quantity<<" "<<h<<"x"<<w<<"x"<<l<<" "<<typeFull<<" $"<<cost;
}
}
  
inFile.close();
outFile.close();
}

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