Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Help. Practice Program for school. Description You find yourself as the manager of a small fleet of delivery trucks, and you wanted to track

C++ Help. Practice Program for school.

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 thedistancebetween two grid locations (x1,y1) and (x2,y2), denoted asd((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 programdoes not have totake 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 ofsome unknown numberof 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

Define the term Working Capital Gap.

Answered: 1 week ago