Answered step by step
Verified Expert Solution
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 after the study of graphs and the Dijkstra algorithm. The COMSC solution is very specific to solving the shortest route between two preselected cities, in a network with no "deadends", no "loops", and all westtoeast "legs". In this exercise, you will build and test the third of the three classes needed to solve the shortestroute problem. Start by copying your Routescpp source file to Routescpp 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. Create A Network Create a constant array of Legs with at least 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:
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: San Francisco is the start, and has no ways in The first city west of San Francisco can have only one way in from San Francisco. New York City is the end, and has no ways out. The first city east of New York City can have only one way out to New York City. Its 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 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 easttowest Legs except for that superhighway note that all Legs are oneway. Accommodating these features would complicate the solution, and we handle these in Comsc 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: Legconst char const, const
Hide Transcribed Text
class Leg const char const startCity; const char const endCity; const int distance; public: Legconst char const, const char const, int; Leg& operatorconst Leg&; for swap int getDistance const return distance;
void outputostream& const; friend class Route; friend class ShortestRoute; ; class Route vector legs; bag of legs const int totalDis; public: Routeconst Leg&; Routeconst Route& const Leg&; Route& operatorconst Route&; int getDistance const return totalDis; void output ostream& const; friend bool operatorconst Route& const Route&; 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 route ShortestRoute: :anyRouteSan Francisco", "New York City"; route outputRoutecout 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 nd function, described below.
Find The Shortest Route Write the recursive function, static const Route shortestRouteconst char const from, const c
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started