Question
Description You find yourself as the manager of a small fleet of delivery trucks, and you wanted to track the statistics of the deliveries so
Description
You find yourself as the manager of a small fleet of delivery trucks, and you wanted to track the statistics of the deliveries so that you can help the company to improve the delivery routes.
You will write a C++ program whose purpose is to analyze a set of delivery routes. We assume that each delivery route is associated with a different delivery truck driver. Your program will take the input as a sequence of delivery routes and then compute, for each delivery route, the following statistics.
The shortest distance traveled between consecutive deliveries.
The longest distance traveled between consecutive deliveries.
The total distance traveled.
The average distance traveled between consecutive deliveries.
Your program should also keep track of the total distance traveled and the total number of deliveries made in the fleet. After all the delivery routes are processed, your program will output the following statistics.
The total number of delivery routes.
The total number of deliveries made in the fleet.
The total distance traveled for all delivery routes in the fleet.
The route number that has the shortest travel distance in the fleet.
The route number that has the longest travel distance in the fleet.
Your delivery fleet operates within the limits of a city. Therefore, we will represent (the locations of) deliveries using ordered pairs of integers (a.k.a., grid locations) such as (0, 0), (1, 3) or (3, 7), etc. For the sake of simplicity, we will assume that the distribution center is located at the grid location (0, 0). Your program must compute the distance between consecutive deliveries according to the taxicab metric, where the distance between two grid locations (x1, y1) and (x2, y2), denoted as d((x1, y1),(x2, y2)), is computed as: d((x1, y1),(x2, y2)) = |x1 - x2| + |y1 - y2|, where |x1 - x2| and |y1 - y2| denote the absolute value of the expression. For example, the distance between (0, 0) and (1, 3) is computed as: |0 - 1| + |0 - 3|, which is 4; the distance between (1, 3) and (3, 7) is computed as |1 - 3| + |3 - 7|, which is 6. Luckily, since your fleet operates within the limits of a city, your program does not have to take into account the curvature of the earth when computing distances between deliveries!
Input
The input is not prompted and your program must continue to accept input until the EOF has been detected.
The input to your program will consist of some unknown number of delivery routes that each correspond to a different delivery truck. Since delivery trucks are constantly in and out of the maintenance shop, you do not know in advance how many delivery routes will be input to the program. The order of the delivery routes in the input matters so that the first route is route #1, the second route is route #2, and so on.
A delivery route (for a particular truck) consists of:
the number of deliveries for that truck, followed by
a list of the locations of the deliveries as represented by pairs of integers (these pairs of integers could correspond to grid points on a city map relative to the location of the distribution center for the fleet). The order of the delivery locations in the input represents the exact order in which the driver visits each location in order to make his/her delivery.
An example follows.
2 1 3 3 7
The previous sample input represents a delivery route for a truck that makes only two deliveries: first it drives from the distribution center, which is located at (0, 0), to the location (1, 3), makes its delivery, and then drives from location (1, 3) to (3,7) to make its last delivery. To keep things relatively simple, we will not consider the final return trip to the distribution center. The following example input contains the delivery routes for four delivery trucks.
7 2 1 1 9 10 11 17 12 15 16 17 18 19 20 2 7 2 19 1 3 1 20 3 4 5 6 1 3 5
Output
Your program must output statistics for each delivery route including the following.
The shortest distance traveled between consecutive deliveries.
The longest distance traveled between consecutive deliveries.
The total distance traveled.
The average distance traveled between consecutive deliveries.
After the statistics for each delivery route have been displayed, your program must print the following fleet-level statistics.
The total number of delivery routes.
The total number of deliveries made in the fleet.
The total distance traveled for all delivery routes in the fleet.
The route number that has the shortest travel distance in the fleet.
The route number that has the longest travel distance in the fleet.
Sample Runs
Consider the following sample input.
7 2 1 1 9 10 11 17 12 15 16 17 18 19 20 2 7 2 19 1 3 1 20 3 4 5 6 1 3 5
The corresponding output for the previous sample input follows.
**Statistics for route #1** Shortest distance between deliveries: 3 Longest distance between deliveries: 11 Distance traveled: 45 Average distance between deliveries: 6.43 **Statistics for route #2** Shortest distance between deliveries: 9 Longest distance between deliveries: 13 Distance traveled: 22 Average distance between deliveries: 11.00 **Statistics for route #3** Shortest distance between deliveries: 4 Longest distance between deliveries: 21 Distance traveled: 43 Average distance between deliveries: 14.33 **Statistics for route #4** Shortest distance between deliveries: 8 Longest distance between deliveries: 8 Distance traveled: 8 Average distance between deliveries: 8.00 Total number of delivery routes: 4 Total number of deliveries: 13 Total distance traveled for all routes: 118 Route #4 has the shortest travel distance: 8 Route #1 has the longest travel distance: 45 Normal Termination.
Consider the following sample input.
2 1 3 3 7
The corresponding output for the previous sample input follows.
**Statistics for route #1** Shortest distance between deliveries: 4 Longest distance between deliveries: 6 Distance traveled: 10 Average distance between deliveries: 5.00 Total number of delivery routes: 1 Total number of deliveries: 2 Total distance traveled for all routes: 10 Route #1 has the shortest travel distance: 10 Route #1 has the longest travel distance: 10 Normal Termination.
Consider the following sample input.
2 1 1 3 3 3 1 1 3 3 5 5
The corresponding output for the previous sample input follows.
**Statistics for route #1** Shortest distance between deliveries: 2 Longest distance between deliveries: 4 Distance traveled: 6 Average distance between deliveries: 3.00 **Statistics for route #2** Shortest distance between deliveries: 2 Longest distance between deliveries: 4 Distance traveled: 10 Average distance between deliveries: 3.33 Total number of delivery routes: 2 Total number of deliveries: 5 Total distance traveled for all routes: 16 Route #1 has the shortest travel distance: 6 Route #2 has the longest travel distance: 10 Normal Termination.
Requirements
Make all attempts to submit your program by the due date.
You must submit by the grace date. Late submissions are worth zero points!
The maximum number of submitting the program to the Grader is 30.
You must submit the program to pass this course.
You must follow the programming ground rules.
You are not allowed to use arrays or write functions to solve this program. Violating this rule results in 0 points.
As always, START EARLY and if you have any questions, do not hesitate to ask your instructor for help.
Hints
Work on getting your program to process (i.e., compute the distance between) one pair of consecutive deliveries. Assuming the first delivery for a particular route is at the grid location (3, 17), compute the distance from (0, 0) to (3, 17)!
Once your program can process one pair of consecutive deliveries, add a loop to process all of the deliveries of a route IN ORDER. First, compute the distance from (0, 0) to (3, 17). Then compute the distance from (3, 17) to (2, 8)! And so on, until reaching the final delivery.
Once your program can process an entire delivery route, add an outer loop to process multiple delivery routes until EOF.
Remember that several variables will need to be reset at the beginning of each delivery route, but other variables, those for computing fleet-level statistics (e.g., the total number of deliveries over all of the delivery routes) should not be reset.
Press Ctrl-Z and hit Enter will trigger an end of file (EOF) on standard input.
To set precision for 2 decimal places for output use the following code:
//--------------------------------------- // turn on 2 decimal precision for the // output of the Average Score //--------------------------------------- cout << fixed << showpoint << setprecision(2);
To reset the output to default output (no decimals for whole numbers) use the the following code (you do not necessarily need to use this if you do not need it):
//--------------------------------------- // turns off 2 digit decimal precision //--------------------------------------- cout << scientific << noshowpoint;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started