作业程序写完了不知道那里的问题 不能读data file 帮看看 在线等
The Green Tree Service Company offers the following services to its customers:* tree planting - $35 for a small tree, $100 for a medium tree, $250 for a large tree
* tree removal - $150 per tree
* tree trimming - $50 per hour
* stump removal - $75 for stumps with a diameter of 10 inches or less, $10 per inch for stumps with a diameter greater than 10 inches
Write a C++ program that will read a series of data values from a file using Linux redirection. The data values will represent a group of jobs that the Green Tree Service Company has completed. The program will compute the amount billed for each job and display a nicely formatted report that lists each job, the billed amounts, and a total due. Use named constants for fixed values (minimum of 5).
Input
The input file will contain data for several jobs. Each job will have a Job # which will be an integer. After the Job #, the work performed will be indicated using the following codes:
* P, p = tree planting, this code will be followed by an integer indicating how many trees were planted and one character code (S,s,M,m,L,l) for the size of each tree planted
* R, r = tree removal, this code will be followed by an integer indicating how many trees were removed
* T, t = tree trimming, this code will be followed by a floating point value indicating how many hours were spent trimming
* S, s = stump removal, this code will be followed by a series of integers that represent the diameters of the stumps removed, 0 will serve as a sentinel to signal the end of the stump data
* Q, q = end of job details
Here is a sample file:
123
P 3 M m S
t 2.5
Q
45
S 5 12 3 10 7 16 0
r 4
p 1 L
q
Here is an explanation of the sample file:
123 Job# 123
P 3 M m S planted 3 trees, 2 medium, 1 small
t 2.5 trimmed trees for 2.5 hours
Q end of job# 123
45 Job# 45
S 5 12 3 10 7 16 0 removed 6 stumps with diameters of 5, 12, 3,
10, 7, 16 inches
r 4 removed 4 trees
p 1 L planted 1 large tree
Q end of job# 45
The program must keep processing data until the end of file is encountered.
Output
Display your name, section #, and assignment #. Then output a nicely formatted report with 6 columns labeled as shown in the example below. Job #s should be left justified and will have a maximum of 6 digits. The values displayed in each of the remaining columns will be right justified. Assume the largest $ amount to be displayed will be $100,000.00. Include $ signs and 2 digits to the right of the decimal for all monetary amounts. Display the total amount billed on the last line of the report (do NOT total any other columns).
Sample report (based on sample input file shown above).
Lee Misch Section #_ Assignment #7
Tree Stump Total
Job# Planting Removal Trimming Removal Billed
123 $ 235.00 $ 0.00 $ 125.00 $ 0.00 $ 360.00
45 $ 250.00 $ 600.00 $ 0.00 $ 580.00 $ 1430.00
TOTAL $ 1790.00
Assumptions
* No invalid data will be included in the file.
* The data for each job will end with the Q or q code.
* For each job, there will be at most 1 set of input values per type of service.
* All service codes may be entered as capital or lower case letters
Here is data file:
123
P 3 M m S
t 2.5
Q
45
S 5 12 3 10 7 16 0
r 4
p 1 L
q
///////////////////////////////
#include <iostream>
#include <iomanip>
using namespace std;
const double m = 100;
const double M = 100;
const double S = 35;
const double s = 35;
const double L = 250;
const double l = 250;
const double r = 150;
const double t = 50;
int main()
{
int jn,i;
char size, ty;
double num,tp, tr, tt, ts, tb;
double m, M, S, s, L, l;
cin >> jn;
cout << "Fei Teng CS 135 Section #2 Assignment #7" << endl;
cout << right << setw (29) << "Tree" << right << setw (24) << "Stump" << right << setw (11) << "Total" << endl;
cout << "Job#" << right << setw(15) << "Planting" << right << setw(12) << "Removal" << right << setw(12) << "Trimming" << right << setw(11) << "Removal" << right << setw(10) << "Billed" << endl;
while(!cin.eof())
{
cin >> ty;
while( ty != 'Q' )
{
if (ty=='p')
{
cin >> num;
for (i=1; i<=num; i++)
{
cin >> size;
if (size=='M'||size=='m')
{
tp = M*i+ m*(num-i) ;
}
if (size=='S'||size=='s')
{
tp = S*i+ s*(num-i);
}
if (size=='L'||size=='l')
{
tp = L*i+ l*(num-i);
}
}
tb = ts+tr+tt+tp; }
else
{
if (ty=='r')
{
cin >> num;
tr= r*num;
}
if (ty=='t')
{
cin >> num;
tt= t*num;
}
if (ty=='s')
{
cin >> num;
for (i=1; i<=num; i++)
if (num<=10)
{
ts = 75 ;
}
else
{
ts = 75 +10*(num-10);
}
}
cout << fixed << showpoint << setprecision(2);
cout << left << setw(6) << jn << right << setw (4) << "$" << right << setw(10) << tp << right << setw(3) << "$" << setw(10) << tr << right << setw(3) << "$" << right << setw(10) << tt << right << setw(3) << "$" << right << setw(10) << tr << right << setw(3) << "$" << right << setw(10) << tb << endl;
cin >> jn;
}
if (ty=='Q')
{
tb = ts+tr+tt+tp;
cout << fixed << showpoint << setprecision(2);
cout << "TOTAL" << right << setw(54) << "$" << right << setw(10) << tb << endl;
}
}}return 0;}
////////////////////////////////