Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note that this is NOT a solution that allows calculation of a route between any two cities in the network. That solution will come in

Note that this is NOT a solution that allows calculation of a route between any two cities in the network. That solution will come in COMSC-210 after the study of graphs and the Dijkstra algorithm. The COMSC-200 solution is very specific to solving the shortest route between two preselected cities, in a network with no "dead-ends", no "loops", and all west-to-east "legs". In this exercise, you will build and test the third of the three classes needed to solve the shortest-route problem. Start by copying your Routes.2.cpp source file to Routes.3.cpp.1. Specification For this assignment, write a static class named ShortestRoute to find the shortest route between San Francisco to New York City. (What makes it "static" is that all its members will be static.) The class will include two static recursive functions -- the first is simple, and just finds a valid route through the network, without regards to shortest distance. The second finds the shortest route. Both are explained below. 2. Create A Network Create a constant array of Legs with at least 40 Leg objects. The Leg array you made for the previous Routes versions will probably have to be modified because of the requirements below. Store the Leg array as a static data member of the ShortestRoute class. The Legs must represent a network of interconnecting cities, between San Francisco and New York City. Use a map of the United States to get the names of intermediate cities of your choice, and the distance between them. Distances do not have to be exact, but they do have to be reasonably close, so that the results generated by your program can be verified.
Every city should have more than one way in (from the west) and more than one way out (to the east), with these exceptions: 1
Hide Transcribed Text
Every city should have more than one way in (from the west) and more than one way out (to the east), with these exceptions: 1. San Francisco is the start, and has no ways in.2. The first city west of San Francisco can have only one way in - from San Francisco. 3. New York City is the end, and has no ways out. 4. The first city east of New York City can have only one way out - to New York City. (It's okay if any other city connected directly to San Francisco has only one way in (from San Francisco), and it's okay if a city connected directly to New York City has only one way out (to New York).) Spread out across the country - even go into Mexico and Canada if you wish. Allow for lots of possible routes with varied combinations of Legs. Do not create one series of connected Legs. Do not create just a few paths, like a northern route, and southern route, and a middle route. Let your Legs cross over so that there are so many path possibilities that you cannot solve the problem with a calculator! After your network satisfies all the above requirements, add one more leg as described here. We anticipate a new superhighway, with bridges, from San Francisco to New York City, going the other way around the world -- west from San Francisco, across the Pacific, across Asia and the Mediterranean, and across the Atlantic. The distance will be 21,000 miles in length, with no stops. For the last Leg, in your network, include this new superhighway link as a single Leg. Carefully design your network so that there are no dead ends, no loops, and no east-to-west Legs except for that superhighway -- note that all Legs are one-way. Accommodating these features would complicate the solution, and we handle these in Comsc-210 when we study "graphs". For purposes of our studies of OOP, what we are doing here is sufficient. Updated class declarations for Leg and Route classes:
class Leg { const char* const startCity; const char* const endCity; const int distance; public: Leg(const char* const, const
Hide Transcribed Text
class Leg \{ const char* const startCity; const char* const endCity; const int distance; public: Leg(const char* const, const char* const, int); Leg\& operator=(const Leg\&);// for swap() int getDistance() const \{return distance;
}
void output(ostream\&) const; friend class Route; friend class ShortestRoute; \}; class Route \{ vector legs; // bag of legs const int totalDis; public: Route(const Leg\&); Route(const Route\&, const Leg\&); Route\& operator=(const Route\&); int getDistance() const \{return totalDis; void output (ostream\&) const; friend bool operator<(const Route\&, const Route\&); 3. Find Any Route solution is explained at the bottom of this writeup, and will be discussed in lecture. Write the main program with a code block like the following: const Route route1= ShortestRoute: :anyRoute("San Francisco", "New York City"); route1. outputRoute(cout) end of your database, as specified. The function should not produce output -- no cout's! It should return a Route object, period. Same for the 2nd function, described below.
4. Find The Shortest Route Write the recursive function, static const Route shortestRoute(const char* const from, const c

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_2

Step: 3

blur-text-image_3

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

=+vii. Bullet points to emphasize important ideas.

Answered: 1 week ago