the Assignment 5 (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: a constant Route object reference to an already-existing Route , and a constant Leg object reference to be appended to the end of that Route to form the new Route . Here's the algorithm: Copy the first parameter's bag into the host object's bag. If the endCity of the last Leg in the bag does not equal the beginCity of the Leg parameter, throw an exception. Otherwise, Append the Leg object parameter to the bag. Make sure to handle the exception in the constructor function 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 The last Leg pointer in a bag is bag.back( ) . How to get it's endCity ... Remember how to compare C strings? It's not with the equals-equals operator... Remember the total distance of the Route is a constant variable. How will it be updated? Write just the function definition, not inline.
For the Assignment 5 (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
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:
- a constant Route object reference to an already-existing Route , and
- a constant Leg object reference to be appended to the end of that Route to form the new Route .
Here's the
- Copy the first parameter's bag into the host object's bag.
- If the endCity of the last Leg in the bag does not equal the beginCity of the Leg parameter, throw an exception. Otherwise,
- Append the Leg object parameter to the bag.
- Make sure to handle the exception in the constructor function
- 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
- The last Leg pointer in a bag is bag.back( ) . How to get it's endCity ...
- Remember how to compare C strings? It's not with the equals-equals operator...
- Remember the total distance of the Route is a constant variable. How will it be updated?
Write just the function definition, not inline.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps