Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

undefined Route class and Leg class declarations: class Leg { const char* const startCity; const char* const endCity; const double distance; public: Leg(const char* const,

image text in transcribedimage text in transcribedundefined

Route class and Leg class declarations: class Leg { const char* const startCity; const char* const endCity; const double distance; public: Leg(const char* const, const char* const, const double); Leg& operator=(const Leg&);// for swap() double getDistance() const {return distance;} void output(ostream&) const; friend class Route; }; class Route { vector legs; // bag of legs const double totalDis; public: Route(const Leg&); Route(const Route&, const Leg&); Route& operator=(const Route&); double getDistance() const {return totalDis;} void output(ostream&) const; }; 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. 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... Route class and Leg class declarations: class Leg { const char* const startCity; const char* const endCity; const double distance; public: Leg(const char* const, const char* const, const double); Leg& operator=(const Leg&);// for swap() double getDistance() const {return distance;} void output(ostream&) const; friend class Route; }; class Route { vector legs; // bag of legs const double totalDis; public: Route(const Leg&); Route(const Route&, const Leg&); Route& operator=(const Route&); double getDistance() const {return totalDis;} void output(ostream&) const; }; 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. 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

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Explain Industrial market segment.

Answered: 1 week ago

Question

Explain the market segmentation.

Answered: 1 week ago