Answered step by step
Verified Expert Solution
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
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
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