Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please revise the code which called Routes.1.cpp (v.1) to design and test a class that represents a route between two cities along a path made

Please revise the code which called Routes.1.cpp (v.1) to design and test a class that represents a route between two cities along a path made up of adjacent Leg objects. Here are the specifications for the Route class:

  1. Two Private Data Members

Write twoprivate data members: a bag to hold the Leg objects that make up the route, and a numeric member for the total distance -- the sum of all the Leg objects making up the path. The distance should beconstant.

Since the bag will hold only Leg objects, there's no need for generic pointers (that require type casting). So use avector of read-only Leg pointersinstead of read-only generic pointers -- it saves a step.

2.Two Route Constructor Functions

Include twoconstructors-- one to create a Route object consisting of only one Leg, and another to create a new Route object by appending a Leg object to the end of an existing Route object. (Our solution in the next lab assignment generates new routes by adding Leg objects one-at-a-time to a growing collection of existing Route objects.)

Throw an exception from the second constructor if the start city of the appended Leg object does not match the end city of the last Leg in the bag. Use any data type you like for the exception handling.

You'll have to figure out how to set the constant "total distance" data member in these constructors. Use the Q&A section of this module to share ideas with classmates.

3.Two Getter Functions

Writetwogetters in class Route -- one to return the distance and another to produce nicely formatted output.

The output getter should have one parameter -- anostreamreference, so that output can be directed to any stream-oriented source. The "nicely formatted output" should look something like this: "Route: San Francisco to Sacramento to Las Vegas to Salt Lake City to Denver to Oakley to Kansas City to Springfield to Columbus to Washington to New York City, 3502 miles". You decide on the exact appearance, but donotrepeat any city name, anddoinclude the start city of the first Leg and the end city of the last Leg andeverycity in between.

Hint: the Route class will need access to the Leg class' private data members, and no getter function was specified for city names. There's another way to make this happen... Use the Q&A section of this module to share ideas with classmates.

Route class and Leg class declarations:

image text in transcribed
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; }

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

What is liquidation ?

Answered: 1 week ago

Question

Explain the different types of Mergers.

Answered: 1 week ago

Question

What is dividend payout ratio ?

Answered: 1 week ago