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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education