Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For the Assignment 6 (Part 2), Routes v.2 at the end of this module you will create a Route class that has a member a

image text in transcribed

For the Assignment 6 (Part 2), Routes v.2 at the end of this module you will create a Route class that has a member a "bag" of Leg objects. The bag is to use a vector of pointers, but since all the objects in the bag are to be Leg s, it's okay to use Leg* instead of void* in the bag's declaration. You wrote its first constructor in a previous exercise. Now write a second one. (You may refer to the Assignment page to refer to the completed class declarations of Leg and Route classes). Assume that class Leg has data member C strings const char* const beginCity; and const char* const endCity; that are available to Route by a friend relationship. Write a constructor function for a Route class that takes exactly two parameters: 1. a constant Route object reference to an already-existing Route , and 2. a constant Leg object reference to be appended to the end of that Route to form the new Route . Here's the algorithm: 1. Copy the first parameter's bag into the host object's bag. 2. If the endCity of the last Leg in the bag does not equal the beginCity of the Leg parameter, throw an exception. Otherwise, 3. Append the Leg object parameter to the bag. 4. Make sure to handle the exception in the constructor function 5. If the new Leg added into the bag, the total distance of the new Route will add the distance of new Leg on. Otherwise, the total distance will be the same as the existing Route Hints 1. The last Leg pointer in a bag is bag.back( ). How to get it's endCity ... 2. Remember how to compare C strings? It's not with the equals-equals operator... 3. Remember the total distance of the Route is a constant variable. How will it be updated? Write just the function definition, not inline

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

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

c. Will leaders rotate periodically?

Answered: 1 week ago

Question

b. Will there be one assigned leader?

Answered: 1 week ago