Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MOST OF THE CODE HAS BEEN DONE FOR YOU-PLEASE MODIFY THE BELOW CORRECT CODE AND FINISH ASAP, WILL GIVE THUMBS UP; CPP FILE BUT C

image text in transcribedMOST OF THE CODE HAS BEEN DONE FOR YOU-PLEASE MODIFY THE BELOW CORRECT CODE AND FINISH ASAP, WILL GIVE THUMBS UP; CPP FILE BUT C SYNTAX!

#include  #include  #include  class TravelNetwork { private: // Create the Data Members for the Travel Network here public: // Use a constructor to initialize the Data Members for Travel Network TravelNetwork() { } // The main loop for reading in input void processCommandLoop (FILE* inFile) { char buffer[300]; char* input; input = fgets ( buffer, 300, inFile ); // get a line of input // loop until all lines are read from the input while (input != NULL) { // process each line of input using the strtok functions char* command; command = strtok (input , " \t"); printf ("*%s* ", command); if ( command == NULL ) printf ("Blank Line "); else if ( strcmp (command, "q") == 0) exit(1); else if ( strcmp (command, "?") == 0) showCommands(); else if ( strcmp (command, "t") == 0) doTravel(); else if ( strcmp (command, "r") == 0) doResize(); else if ( strcmp (command, "i") == 0) doInsert(); else if ( strcmp (command, "d") == 0) doDelete(); else if ( strcmp (command, "l") == 0) doList(); else if ( strcmp (command, "f") == 0) doFile(); else if ( strcmp (command, "#") == 0) ; else printf ("Command is not known: %s ", command); input = fgets ( buffer, 300, inFile ); // get the next line of input } } void showCommands() { printf ("The commands for this project are: "); printf (" q "); printf (" ? "); printf (" # "); printf (" t   "); printf (" r  "); printf (" i   "); printf (" d   "); printf (" l "); printf (" f  "); } void doTravel() { int val1 = 0; int val2 = 0; // get an integer value from the input char* next = strtok (NULL, " \t"); if ( next == NULL ) { printf ("Integer value expected "); return; } val1 = atoi ( next ); if ( val1 == 0 && strcmp (next, "0") != 0) { printf ("Integer value expected "); return; } // get another integer value from the input next = strtok (NULL, " \t"); if ( next == NULL ) { printf ("Integer value expected "); return; } val2 = atoi ( next ); if ( val2 == 0 && strcmp (next, "0") != 0) { printf ("Integer value expected "); return; } printf ("Performing the Travel Command from %d to %d ", val1, val2); } void doResize() { int val1 = 0; printf ("Performing the Resize Command with %d ", val1 ); } void doInsert() { } void doDelete() { } void doList() { } void doFile() { // get a filename from the input char* fname = strtok (NULL, " \t"); if ( fname == NULL ) { printf ("Filename expected "); return; } printf ("Performing the File command with file: %s ", fname); // next steps: (if any step fails: print an error message and return ) // 1. verify the file name is not currently in use // 2. open the file using fopen creating a new instance of FILE* // 3. recursively call processCommandLoop() with this new instance of FILE* as the parameter // 4. close the file when processCommandLoop() returns } }; int main (int argc, char** argv) { // set up the variable inFile to read from standard input FILE* inFile = stdin; // set up the data needed for the airport adjcency list TravelNetwork airportData; // call the method that reads and parses the input airportData.processCommandLoop (inFile); printf ("Goodbye "); return 1; } 

For this program, you will write a C++ Program to represent a travel network. This travel network will use an array of linked lists as its primary storage structure. This type of storage structure is typically called an adjacency list. Please note: this write-up was originally taken from a non-C++ assignment. Any reference to non-C++ items were not properly translated into C++. Such items should use their C++ counterparts. Assume you have a small airline that flies planes between a small number of airports. Each airport will be given a number. If a plane flies from airport X to airport Y, the network will have an edge from X to Y. Below are a number of drawings that could represent this idea. The airports are represented by the circled numbers, the edges are represented by the arrows. Consider the first drawing. It has 6 airports. It has a plane that flies from airport 1 to airport 2. Three planes fly from airport 2, one to airport 3, one to airport 4 and one to airport 5. No planes leave from airport 3 or from airport 5 (yes, it would be stupid to strand planes at those airports, but ignore that fact for now). Planes fly from airport 4 to airports 5 and 6. Finally, planes fly from airport 6 to airport 3. In an adjacency list, each location/airport needs a list of those locations/airports that one can get to in one move/flight. In this program, we need a list for each airport. If the travel network has N airports, the array will have N linked lists, one for each airport. If airport X has planes flying to 3 different airports, the linked list for airport X would have 3 nodes. Consider the following image showing a travel network and an adjacency list: There are 5 airports, so we have an array of 5 linked lists. Since Airport 3 can fly planes to two Airports, namely Airport 1 and Airport 4, the linked list for Airport 3 has two nodes: one node containing the value 1; another node containing the value 4.

First you are to write a class called Airport. This class is to contain everything that is known about a specific Airport. This MUST include the airports adjacency list and the visited status for the Depth First Search. Next you are to write a list class. You are encouraged to name the class MyList as the name List is already used in the C++ Standard Template Libraries. Please note that your list class will need another class for the nodes in the list. Thus you must write a class called MyNode also. For your list class, in addition to the normal insertValue( ) and deleteValue( ) operations, you may want to write operations such as getNumberOfCurrentsValues( ) and getNthValue( ). The TravelNetwork class has been started for you. This class must contain the array of Airports and the linked list of filenames for the in-use files needed for the f command. All data members (or instance variables) must be made private. Failure to do this will result is a severe reductions of points for the project. CS211 Programming Practicum Fall 2017 You are not allowed to use any of the classes from the C++ Standard Template Libraries in this program. These classes include ArrayList, Vector, LinkedList, List, Set, Stack, HashMap, etc. If you need such a class, you are to write it yourself. These are sometimes called the C++ Standard Container Library. A full listing of the C++ Standard Template Libraries can be found at: http://www.cplusplus.com/reference/stl/ Multiple Source Code Files Your program is to be written using at least two source code files. One of the source file files is to contain the main function of the program named in a file using your NetId and Program name, like: Ptroy1Proj6.cpp The other source code file must contain your Airport class in a file named: Airport.cpp You may use additional source code files if you wish (i.e. MyList.cpp), but these two are required. The above implies that you will need to write any appropriate .h file(s) and a makefile.

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago