HPAir flight map problem

Oct 10, 2014 at 9:36pm
I am trying to write a program that will read three txt file, first has city names,second the flight map,and third has the request flight.for this input the program should produce the following output:

Request is to fly from Albuquerque to San Diego.
HPAir flies from Albuquerque to San Diego.

Request is to fly from Albuquerque to Paris.
Sorry.HPAir does not serve Paris.

I made some of the header file and just started doing the main, but I don't know how.please help me understand and build the correct code, I have the pseudo code for some of them but not all and I couldn't translate it to a code.
the following is the header file and main part:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 #pragma once

#include <string>
#include <iostream>
#include <fstream>
#include "Node.h"

using namespace std;

typedef int City;

const int MAX_CITIES = 50;
const City NO_CITY = -1;

class Map
{
private:
	string cities[MAX_CITIES];
	bool visited[MAX_CITIES];
	Node<City>* map[MAX_CITIES];
	int numCities;
	
	void unvisitedAll();
	
	void markVisited(City);
		/*
	markVisited(city,c)
	visited[c]=true
	*/
	

	City getNextCity(City);
	/*
		city getNextCity(city c)
			node<city>* ptr=map[c];
			bool found=false
			city next=NO_CITY
			while (ptr != nullptr and !found)
			{
				if (!isVisited(ptr->getitem()))
					{
					next=ptr->get item()
					found = true
					}
				ptr=pts->getnext();
			}
			return next
	*/
	bool isPath(City, City);
	bool isVisited(City);
	City getIndex(string);
	/*
		city getIndex (string c)
		bool found=false;  city index=0;
		while (!found and index < numCities)
			if (c==cities[index])
			  found=true
			else
			index++
		if (found)
			return index
			return NO-CITY
	*/
	void insertAdjacent(City, City);
	/*
		insertAdjacent( city fromcity, city tocity)
		node<city>*newcity= new node<city>(tocity, map[fromcity])
		map[fromcity]=newcity
	*/
	void splitCities(string, string&, string&);

public:
	Map();

	void readFlightMap(string, string);

	void flights(string);

};
template<class ItemType>
void Map::unvisitedAll()
{
	for (int cities = 0; cities < numCities; cities++)

		visited[cities] = false;
}
template<class ItemType>
void Map::markVisited()
{
	markVisited(city, c);
	visited[c] = true;
}
template<class ItemType>
City Map::getNextCity(City)
{
	/* City getNextCity(city c)
		node<city>* ptr = map[c];
	bool found = false;
	city next = NO_CITY;
	while (ptr != nullptr and !found)
	{
		if (!isVisited(ptr->getitem()))
		{
			next = ptr->get item();
				found = true;
		}
		ptr = pts->getnext();
	}
	return next; */
}



/* this is the main */

#include <iostream>
#include <string>
#include "Map.h"


using namespace std;

int main()
{
	Map HPAir;
        HPAir.readFlightMap("cities.txt", "flightmap.txt");
	HPAir.flights("request.txt");
	
	

	system("pause");
	return 0;
}
Oct 10, 2014 at 9:43pm
How is data in request.txt , cities.txt, flightmap.txt structured?
Last edited on Oct 10, 2014 at 9:44pm
Oct 10, 2014 at 11:14pm
request.txt:
Albuquerque, San Diego
San Diego, Chicago
etc...

------------------------------------

cities.txt:
Albuquerque
Chicago
San Diego
etc...

------------------------------------

flightmap.txt:
Albuquerque, San Diego
San Diego, Chicago
etc...

I am working on the same problem by the way :)
Oct 10, 2014 at 11:59pm
From mimi88's code and pseudo code, i am beginning to think there is much more to the question.

First, depending on the sample output and input text files, i dont see any use for cities.txt.

You simply check in the flightmap for a corresponding match in request.

Also, i see
bool visited, Node<City> *, getNextCity(), isPath(), etc... . This tells me that you are actually building a route. Is that part of the question?

It would be better if for all of us if you lay out your ideas. @cpp hoping to hear from you.
Oct 11, 2014 at 10:04pm
I guess we should build a rout to know which city we visited and if there is a rout from-to the city requested.
Oct 14, 2014 at 12:10am
any one want to help?
Topic archived. No new replies allowed.