Help with Compiling Errors

I'm trying to make an airline reservations program based on a linked list of passenger objects. Below is my code so far, I've commented out the two functions that I'm yet to fix, but I'm getting the error /main.cc:9:11: error: use of undeclared identifier 'menu' - switch (menu()) and nothing I try is making it any better. I assume there's probably more issues in the code than just that, but it's all the compiler is showing right now.

(database.h)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<fstream>
#define SL_LIST
using namespace std;

class Passenger {
public:
	Passenger(string, string, string);
	bool operator==(const Passenger&) const;
	bool operator<(const Passenger&) const;

private:
	string fname, lname, destination;
	list<Passenger> flight_list;
};


(database.cc)
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
#include "database.h"

Passenger::Passenger(string first, string last, string dest)
{
 	fname = first;
 	lname = last;
 	destination = dest;
}

bool Passenger::operator==(const Passenger& p) const
{
	return fname == p.fname && lname == p.lname;
}

bool Passenger::operator<(const Passenger& p) const
{
	return fname < p.fname || (fname == p.fname && lname < p.lname);
}

int menu()
{
	int option;
	cout << endl;
	cout << "Enter one of the following options:" << endl;
	cout << "1. load reservations from file:" << endl;
	cout << "2. reserve a ticket" << endl;
	cout << "3. cancel a reservation" << endl;
	cout << "4. check reservation" << endl;
	cout << "5. display passenger list" << endl; 
	cout << "6. save passenger list" << endl;
	cout << "7. exit" << endl << endl;
	cin >> option;
	cin.get();
	return option;
}

void read_from_file(list<Passenger>& flist, string filename)
{
	string fname, lname, destination;
	ifstream input(filename.c_str());
	while (input >> fname >> lname >> destination) 
	{					
		flist.push_back(Passenger(fname, lname, destination));
	}
	input.close();
}

void insert(list<Passenger>& flist, string fname, string lname, string destination)
{
	flist.push_back(Passenger(fname, lname, destination));
}

void remove(list<Passenger>& flist, string fname, string lname, string destination)
{
	flist.remove(Passenger(fname, lname, destination));
}

bool check_reservation(list<Passenger>& flist, string fname, string lname, string destination)
{
	list<Passenger>::iterator i1, i2;
	i1 = flist.begin();
	i2 = flist.end();
	return flist.end() != find(flist.begin(), flist.end(), Passenger(fname, lname, destination));
}

/*void display_list(list<Passenger>& flist)
{
	flist.sort();
	list<Passenger>::iterator i1, i2;
	i1 = flist.begin();
	i2 = flist.end();
	for ( ; i1 != i2; ++i1) {
		cout << *i1 << endl;
	}
}

void save_to_file(list<Passenger>& flist, string filename)
{
	flist.sort();
	list<Passenger>::iterator i1, i2;
	i1 = flist.begin();
	i2 = flist.end();
	ofstream output(filename.c_str());
	for ( ; i1 != i2; ++i1) {
		output << *i1 << " ";
	}
	output.close();
}
*/


(main.cc)
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
#include "database.h"

int main()
{	

	while (true) 
	{
		switch (menu())
		{
			case 1:	
				{
					read_from_file(flight_list, "ticket_reservations.dat");
					break;
				}

			case 2: 
				{
					cout << "first name of passenger:" << endl; 
					cin >> fname;
					cout << "last name of passenger" << endl;
					cin >> lname;
					cout << "destination of passenger" << endl;
					cin >> destination;
					insert(flight_list, fname, lname, destination);
					break;
				}

			case 3: 
				{
					cout << "first name of passenger:" << endl; 
					cin >> fname;
					cout << "last name of passenger" << endl;
					cin >> lname;
					cout << "destination of passenger" << endl;
					cin >> destination;
					remove(flight_list, fname, lname, destination);
					break;
				}

			case 4: 
				{
					cout << "first name of passenger:" << endl; 
					cin >> fname;
					cout << "last name of passenger" << endl;
					cin >> lname;
					cout << "destination of passenger" << endl;
					cin >> destination;
					if (check_reservation(flight_list, fname, lname, destination))
						cout << "this passenger has a ticket reservation" << endl;
					else
						cout << "this passenger does not have a ticket reservation" << endl;
					break;
				}

			/*case 5:	
				{
					display_list(flight_list);
					break;
				}

			case 6: 
				{
					save_to_file(flight_list, "ticket_reservations.dat");
				}
				break;
			*/

			case 7:
				return 0;
		}
	}
	
	return 0;
}


Any help with this code at all would be much appreciated!
Last edited on
At line 8 in your file main.cc, you attempt to use the function menu().

At this point, the compiler has never heard of this function. The header file database.h declares the Passenger class, but all the other functions don't get a mention. They should.
database.h line 17: Your Passenger object contains a list of Passengers? That seems recursive.
Based on the following comment, I suspect this line is misplaced.

main.cc line 12,24,36,48: Where is flight_list defined? flight_list is a member of Passenger, but you don't have a passenger object. I suspect you want flight_list defined at line 5 of main, rather than as a member of Passenger.

Lines 18-23, 30-35, 40-47: Any time you do the same thing multiple times, it is a good indication a function is needed.

If I were you, I'd create a FlightList class. insert, remove, find, display all belong as members of this class.
1
2
3
4
5
6
7
8
9
10
11
class FlightList 
{  std::list<Passenger>   flist;
public:
    void Insert (Passegner & pass);
    void Delete (Passenger & pass);
    bool Find (Passenger & pass);
    void Display ();  // If you're ambitious overload the >> operator instead
};

//  Then at line 5 of main: 
  FlightList  flight_list;


Topic archived. No new replies allowed.