Hello all again, I have a Lumber Order program I need to write. I need to get the loop to repeat itself and continue reading the infile. As of right now the program reads in the first Customer Order. IF anyone could assist me I would be very grateful!
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 0.89 Fir 1.09 Cedar 2.26 Maple 4.50 Oak 3.10
The lumber is sold in different dimensions (specified in inches for width and for height, and feet for the 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 one customer and his lumber order. The lumber order will have several types of woods and different sizes in each order.
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 are no numbers following or this is the end of the order. The program should print out the customer number and an itemized order and print out the total 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 inches by 6 inches by 8 feet
…
T Flag for the program to print the total cost of
this order.
Output;
Customer Order Report
Customer # 1020
Count Size Wood Cost
10 2x4x8 Pine $47.47
3 1x6x10 Maple $11.25
…
Total: $1340.28
Two sample data to use to test your code.
Customer #: 1234
M 5 1 8 8
C 10 1 6 12
C 5 1 12 12
P 8 2 4 10
P 6 2 6 12
T
Customer #: 3820
P 15 2 4 10
F 20 1 6 16
O 5 1 10 8
P 5 2 8 16
C 3 4 4 12
P 3 1 12 10
T
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream inf("Lumber.in");
if(!inf)
cout << "ERROR CHECK FILE!";
ofstream out("Lumber.out");
string customer_id;
char type, pound, colon;
float total, cost,
price, boardfeet;
int number, width, height, length, quantity;
out << "\t\tCUSTOMER ORDER REPORT\n";
while(inf >> customer_id >> pound >> colon >> number)
{
out << customer_id << " " << pound << " "
<< colon << " " << number << " \n"
<< "Count Size \tWood\tCost\n";
while (inf >> type >> quantity >> width >> height >> length)
{
out << " " << quantity << "\t " << width
<< "x" << height <<"x" << length << " ";
switch(type)
{
case 'P': price = 0.89;
out << " Pine";
break;
case 'F': price = 1.09;
out << " Fir";
break;
case 'C': price = 2.26;
out << " Cedar";
break;
case 'M': price = 4.50;
out << " Maple";
break;
case 'O': price = 3.10;
out << " Oak";
break;
}
boardfeet = (width*height*length*12)/144;
cost = (quantity * price) * boardfeet;
total += cost;
out << setprecision(2) << fixed
<< "\t$" << cost << endl;
}
out << "\n\t\t\t\tTotal: $"<< total;
}
out.close();
inf.close();
return 0;
}
| |
Here's the input data:
Customer #: 1234
M 5 1 8 8
C 10 1 6 12
C 5 1 12 12
P 7 2 4 10
P 6 2 6 12
T
Customer #: 3820
P 15 2 4 10
F 20 1 6 16
O 6 1 10 8
P 5 2 8 16
C 2 4 4 12
P 3 1 12 10
T
Customer #: 7923
O 8 1 6 10
O 5 2 6 8
O 4 1 8 10
O 2 1 12 10
T
Customer #: 2482
C 10 1 8 10
C 8 2 5 16
M 9 4 6 12
F 5 6 6 12
C 2 1 12 16
T
Customer #: 7783
F 2 1 4 10
M 8 2 5 10
T
Customer #: 4913
P 15 2 4 9
P 20 2 6 24
P 14 2 10 20
P 20 2 4 10
F 1 1 6 10
F 10 2 6 12
T
Customer #: 1178
P 25 2 4 10
P 20 2 4 8
P 10 2 4 12
F 20 1 6 16
F 15 1 4 12
O 6 1 10 8
P 5 2 8 16
P 8 2 8 10
C 2 4 4 12
C 2 4 4 8
P 3 1 12 10
T
This is my output from the code above:
CUSTOMER ORDER REPORT
Customer # : 1234
Count Size Wood Cost
5 1x8x8 Maple $112.50
10 1x6x12 Cedar $135.60
5 1x12x12 Cedar $135.60
7 2x4x10 Pine $37.38
6 2x6x12 Pine $64.08
Total: $485.16