codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  The Ballarat Airline Company (BAC)  arjunu at 00:45 on Tuesday, September 23, 2008
 

Can you please help me to do in C++ and send me at arjun.upadhya@yahoo.com
Question is:
Introduction. The Ballarat Airline Company (BAC) wants a simple program to process customer requests to fly from some origin city to some destination city: For each customer request, the program has to indicate whether a sequence of BAC flights exists from the origin city to the destination city, and, if such a sequence exists, the program prints it.
The following figure represents the routs that BAC flies (for simplicity cities on the figure are denoted by C1, C2, …, C9):



Notice that not all BAC flights have return flights, for example there is a BAC flight from C1 to C2, but not a BAC flight from C2 to C1.

The algorithm for processing customer requests is described in the following section and uses stacks. You must “translate” the algorithm into C++, and create auxiliary C++ classes as specified below.
1. The Main Algorithm. Let us assume that we have a request to find a sequence of flights from X to Y. The request must be processed in the following way:

I We create an empty stack;
II All cities are marked as “unvisited”;
III We mark city X as “visited” and push it onto the stack;
IV While the stack is not empty and top city in the stack is not the destination city Y:
• If there is some “unvisited” city adjacent to the top city, we mark it as “visited” and push it onto the stack
• Else we pop the stack
IV Return the stack. If the stack is not empty it contains the sequence of flights from X to Y. If the stack is empty, such sequence does not exist.


2. classes Stack<T> and List<T> [4 marks each]. Create class templates Stack<T> and List<T>. You may need to make appropriate changes to the classes Stack and List discussed in the lectures. Class Stack<T> should contain a function with the following prototype

friend ostream& operator<<(ostream& stream, Stack<T*> &c);

that prints contents of the stack.

3. Class City [4 marks]. Create a class City, which has the following private instance variables:

• string name; // name of the city
• List<City*> *nextCities; // A pointer to a List of the cities to which there is a flight from the city.
• bool visited; // the variable that shows whether the city has already been visited during the request processing algorithm.

The class also should contain constructor(s) and get and set functions for the instance variables.
There also should be a public function City* getNextUnvisitedCity() that returns a pointer to some “unvisited” city from the nextCities list, if there is any, otherwise returns NULL.

4. A function with the header
function Stack<City>* isPath(City * originCity, City * destinationCity)
that implements the Main Algorithm described in section 1.
[5 marks]
5. main function, in which you create 9 cities according to the information given in the flight map (figure in section 0) and then process customer requests for three different pairs of cities (you can choose the pairs yourself). [3 marks]









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  ridding of beginning/ending spacebars in each element of a list.
•  Excel to XML
•  DHTML tutorials?
•  The Ballarat Airline Company (BAC)
•  Re: Problem to declare global variable in Object oriented perl
•  Issue with Javascript between web servers
•  Not Allowing Copying from Site
•  Re: dereferenceing a string to a constant name
•  Scrolling Javascript Product Slider


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008