1,105,594 Community Members

Linux Redirection homework help please!!

Member Avatar
c++ failure
Newbie Poster
2 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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


How do I even start? help!!

Member Avatar
ixmike88
Junior Poster in Training
54 posts since Sep 2010
Reputation Points: -3 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

file input/output:

http://www.cplusplus.com/doc/tutorial/files/

string manipulation:
http://www.cplusplus.com/reference/string/string/

i would make a while loop that goes to end of file and looks for the start/end of each job and parse each line to get the info you need, then store it to variables then output later

Member Avatar
c++ failure
Newbie Poster
2 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

im still kinda lost but i think im getting a good start with it?

#include <iostream> 
#include <iomanip> 
using namespace std; 
int main() 
{
	int data;
	char q;
	char Q;
	double time;
	double diameter;
	double M = 100;// medium tree plant
	double m = 100;// medium tree plant
	double S = 35;// small tree plant
	double s = 35;// small tree plant
	double L = 100;// large tree plant
	double l = 100;// large tree plant
	double t = time * 50; //  tree trimming
	double r = 150; // tree removal
	double St = 75 + (10*diameter); // stump removal

while (data != q || Q)
{
	data_count++;
	cin >> data;

}







 cout << "Section #3 Assignment #7" << endl;
 cout << "Tree Stump Total" << endl;
 cout << "Job#" << setw(6) << "Planting" << setw(6) << "Removal" << setw(6) << "Trimming" << setw(6) << "Removal" << setw(6) <<  "Billed" << setw(6) << endl;

 return 0; 
}
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: