Migrating CPP Code from Visual Studio 2008 to g++ compiler

Hi,

I have a small problem with migrating my code. I wrote it in Visual Studio 2008, and it works just fine.

I copied the source files, and tried to compile them in Linux Mint, the compiler throws the following errors:

1
2
3
4
5
$ g++ airprogram.cpp -o air
airprogram.cpp: In function ‘int main()’:
airprogram.cpp:37:5: error: ‘list’ was not declared in this scope
airprogram.cpp:37:10: error: expected ‘;’ before ‘flight’
airprogram.cpp:111:6: error: ‘flight’ was not declared in this scope


The Project contains two header files, and three CPP files
I will post the files in subsequent posts, plz don't ban, its important for me :D
Last edited on

1. List.h

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// FILE: node1.h
// PROVIDES: A class for a node in a linked list, and list manipulation
// functions, all within the namespace main_savitch_5
//
// TYPEDEF for the node class:
//     Each node of the list contains a piece of data and a pointer to the
//     next node. The type of the data is defined as node::value_type in a
//     typedef statement. The value_type may be any
//     of the built-in C++ classes (int, char, ...) or a class with a copy
//     constructor, an assignment operator, and a test for equality (x == y).
//
// CONSTRUCTOR for the node class:
//   node(
//     const value_type& init_data = value_type(),
//     node* init_link = NULL
//   )
//     Postcondition: The node contains the specified data and link.
//     NOTE: The default value for the init_data is obtained from the default
//     constructor of the value_type. In the ANSI/ISO standard, this notation
//     is also allowed for the built-in types, providing a default value of
//     zero. The init_link has a default value of NULL.
//
// NOTE:
//   Some of the functions have a return value which is a pointer to a node.
//   Each of these  functions comes in two versions: a non-const version (where
//   the return value is node*) and a const version (where the return value
//   is const node*). 
// EXAMPLES:
//    const node *c;
//    c->link( ) activates the const version of link
//    list_search(c,... calls the const version of list_search
//    node *p;
//    p->link( ) activates the non-const version of link
//    list_search(p,... calls the non-const version of list_search
//
// MEMBER FUNCTIONS for the node class:
//   void set_data(const value_type& new_data)
//     Postcondition: The node now contains the specified new data.
//   
//   void set_link(node* new_link)
//     Postcondition: The node now contains the specified new link.
//
//   value_type data( ) const
//     Postcondition: The return value is the data from this node.
//
//   const node* link( ) const <----- const version
//   node* link( ) <----------------- non-const version
//   See the note (above) about the const version and non-const versions:
//     Postcondition: The return value is the link from this node.
//   
// FUNCTIONS in the linked list toolkit:
//   size_t list_length(const node* head_ptr)
//     Precondition: head_ptr is the head pointer of a linked list.
//     Postcondition: The value returned is the number of nodes in the linked
//     list.
//
//   void list_head_insert(node*& head_ptr, const node::value_type& entry) 
//     Precondition: head_ptr is the head pointer of a linked list.
//     Postcondition: A new node containing the given entry has been added at
//     the head of the linked list; head_ptr now points to the head of the new,
//     longer linked list.
//
//   void list_insert(node* previous_ptr, const node::value_type& entry) 
//     Precondition: previous_ptr points to a node in a linked list.
//     Postcondition: A new node containing the given entry has been added
//     after the node that previous_ptr points to.
//
//   const node* list_search(const node* head_ptr, const node::value_type& target) 
//   node* list_search(node* head_ptr, const node::value_type& target) 
//   See the note (above) about the const version and non-const versions:
//     Precondition: head_ptr is the head pointer of a linked list.
//     Postcondition: The pointer returned points to the first node containing
//     the specified target in its data member. If there is no such node, the
//     null pointer is returned.
//
//   const node* list_locate(const node* head_ptr, size_t position) 
//   node* list_locate(node* head_ptr, size_t position) 
//   See the note (above) about the const version and non-const versions:
//     Precondition: head_ptr is the head pointer of a linked list, and
//     position > 0.
//     Postcondition: The pointer returned points to the node at the specified
//     position in the list. (The head node is position 1, the next node is
//     position 2, and so on). If there is no such position, then the null
//     pointer is returned.
//
//   void list_head_remove(node*& head_ptr) 
//     Precondition: head_ptr is the head pointer of a linked list, with at
//     least one node.
//     Postcondition: The head node has been removed and returned to the heap;
//     head_ptr is now the head pointer of the new, shorter linked list.
//
//   void list_remove(node* previous_ptr) 
//     Precondition: previous_ptr points to a node in a linked list, and this
//     is not the tail node of the list.
//     Postcondition: The node after previous_ptr has been removed from the
//     linked list.
//
//   void list_clear(node*& head_ptr) 
//     Precondition: head_ptr is the head pointer of a linked list.
//     Postcondition: All nodes of the list have been returned to the heap,
//     and the head_ptr is now NULL.
//
//   void list_copy(const node* source_ptr, node*& head_ptr, node*& tail_ptr) 
//     Precondition: source_ptr is the head pointer of a linked list.
//     Postcondition: head_ptr and tail_ptr are the head and tail pointers for
//     a new list that contains the same items as the list pointed to by
//     source_ptr. The original list is unaltered.
//  void list_piece(
//    const node* start_ptr, const node* end_ptr, 
//    node*& head_ptr, node*& tail_ptr
//  )
//    Precondition: start_ptr and end_ptr are pointers to nodes on the same
//    linked list, with the start_ptr node at or before the end_ptr node
//    Postcondition: head_ptr and tail_ptr are the head and tail pointers for a
//    new list that contains the items from start_ptr up to but not including 
//    end_ptr.  The end_ptr may also be NULL, in which case the new list 
//    contains elements from start_ptr to the end of the list.
//
// DYNAMIC MEMORY usage by the toolkit: 
//   If there is insufficient dynamic memory, then the following functions throw
//   bad_alloc: the constructor, list_head_insert, list_insert, list_copy,
//   list_piece.

#ifndef MAIN_SAVITCH_NODE_H  
#define MAIN_SAVITCH_NODE_H
#include <cstdlib> // Provides size_t and NULL
#include <string>

typedef std::string value_type;


class node
{
public:
    // TYPEDEF
    typedef std::string value_type;
    
    // CONSTRUCTOR
    node(
	const value_type& init_data = value_type( ),
	node* init_link = NULL
	)
    { data_field = init_data; link_field = init_link; }
    
    // Member functions to set the data and link fields:
    void set_data(const value_type& new_data) { data_field = new_data; }
    void set_link(node* new_link)             { link_field = new_link; }
    
    // Constant member function to retrieve the current data:
    value_type data( ) const { return data_field; }
    
    // Two slightly different member functions to retreive
    // the current link:
    const node* link( ) const { return link_field; }
    node* link( )             { return link_field; }
    
private:
    value_type data_field;
    node* link_field;
};

// FUNCTIONS for the linked list toolkit
size_t list_length(const node* head_ptr);
void list_head_insert(node*& head_ptr, value_type entry);
void list_insert(node*& head_ptr, node* previous_ptr, value_type entry);
bool list_search(node* head_ptr, node*& cur_ptr, node*& previous_ptr, value_type target);
bool list_search(const node* head_ptr, node*& cur_ptr, node*& previous_ptr, value_type target);
node* list_locate(node* head_ptr, size_t position);
const node* list_locate(const node* head_ptr, size_t position);
void list_head_remove(node*& head_ptr);
void list_remove(node* previous_ptr);
void list_clear(node*& head_ptr);
void list_copy(const node* source_ptr, node*& head_ptr, node*& tail_ptr);


#endif 


2. Node.h

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// FILE: node1.h
// PROVIDES: A class for a node in a linked list, and list manipulation
// functions, all within the namespace main_savitch_5
//
// TYPEDEF for the node class:
//     Each node of the list contains a piece of data and a pointer to the
//     next node. The type of the data is defined as node::value_type in a
//     typedef statement. The value_type may be any
//     of the built-in C++ classes (int, char, ...) or a class with a copy
//     constructor, an assignment operator, and a test for equality (x == y).
//
// CONSTRUCTOR for the node class:
//   node(
//     const value_type& init_data = value_type(),
//     node* init_link = NULL
//   )
//     Postcondition: The node contains the specified data and link.
//     NOTE: The default value for the init_data is obtained from the default
//     constructor of the value_type. In the ANSI/ISO standard, this notation
//     is also allowed for the built-in types, providing a default value of
//     zero. The init_link has a default value of NULL.
//
// NOTE:
//   Some of the functions have a return value which is a pointer to a node.
//   Each of these  functions comes in two versions: a non-const version (where
//   the return value is node*) and a const version (where the return value
//   is const node*). 
// EXAMPLES:
//    const node *c;
//    c->link( ) activates the const version of link
//    list_search(c,... calls the const version of list_search
//    node *p;
//    p->link( ) activates the non-const version of link
//    list_search(p,... calls the non-const version of list_search
//
// MEMBER FUNCTIONS for the node class:
//   void set_data(const value_type& new_data)
//     Postcondition: The node now contains the specified new data.
//   
//   void set_link(node* new_link)
//     Postcondition: The node now contains the specified new link.
//
//   value_type data( ) const
//     Postcondition: The return value is the data from this node.
//
//   const node* link( ) const <----- const version
//   node* link( ) <----------------- non-const version
//   See the note (above) about the const version and non-const versions:
//     Postcondition: The return value is the link from this node.
//   
// FUNCTIONS in the linked list toolkit:
//   size_t list_length(const node* head_ptr)
//     Precondition: head_ptr is the head pointer of a linked list.
//     Postcondition: The value returned is the number of nodes in the linked
//     list.
//
//   void list_head_insert(node*& head_ptr, const node::value_type& entry) 
//     Precondition: head_ptr is the head pointer of a linked list.
//     Postcondition: A new node containing the given entry has been added at
//     the head of the linked list; head_ptr now points to the head of the new,
//     longer linked list.
//
//   void list_insert(node* previous_ptr, const node::value_type& entry) 
//     Precondition: previous_ptr points to a node in a linked list.
//     Postcondition: A new node containing the given entry has been added
//     after the node that previous_ptr points to.
//
//   const node* list_search(const node* head_ptr, const node::value_type& target) 
//   node* list_search(node* head_ptr, const node::value_type& target) 
//   See the note (above) about the const version and non-const versions:
//     Precondition: head_ptr is the head pointer of a linked list.
//     Postcondition: The pointer returned points to the first node containing
//     the specified target in its data member. If there is no such node, the
//     null pointer is returned.
//
//   const node* list_locate(const node* head_ptr, size_t position) 
//   node* list_locate(node* head_ptr, size_t position) 
//   See the note (above) about the const version and non-const versions:
//     Precondition: head_ptr is the head pointer of a linked list, and
//     position > 0.
//     Postcondition: The pointer returned points to the node at the specified
//     position in the list. (The head node is position 1, the next node is
//     position 2, and so on). If there is no such position, then the null
//     pointer is returned.
//
//   void list_head_remove(node*& head_ptr) 
//     Precondition: head_ptr is the head pointer of a linked list, with at
//     least one node.
//     Postcondition: The head node has been removed and returned to the heap;
//     head_ptr is now the head pointer of the new, shorter linked list.
//
//   void list_remove(node* previous_ptr) 
//     Precondition: previous_ptr points to a node in a linked list, and this
//     is not the tail node of the list.
//     Postcondition: The node after previous_ptr has been removed from the
//     linked list.
//
//   void list_clear(node*& head_ptr) 
//     Precondition: head_ptr is the head pointer of a linked list.
//     Postcondition: All nodes of the list have been returned to the heap,
//     and the head_ptr is now NULL.
//
//   void list_copy(const node* source_ptr, node*& head_ptr, node*& tail_ptr) 
//     Precondition: source_ptr is the head pointer of a linked list.
//     Postcondition: head_ptr and tail_ptr are the head and tail pointers for
//     a new list that contains the same items as the list pointed to by
//     source_ptr. The original list is unaltered.
//  void list_piece(
//    const node* start_ptr, const node* end_ptr, 
//    node*& head_ptr, node*& tail_ptr
//  )
//    Precondition: start_ptr and end_ptr are pointers to nodes on the same
//    linked list, with the start_ptr node at or before the end_ptr node
//    Postcondition: head_ptr and tail_ptr are the head and tail pointers for a
//    new list that contains the items from start_ptr up to but not including 
//    end_ptr.  The end_ptr may also be NULL, in which case the new list 
//    contains elements from start_ptr to the end of the list.
//
// DYNAMIC MEMORY usage by the toolkit: 
//   If there is insufficient dynamic memory, then the following functions throw
//   bad_alloc: the constructor, list_head_insert, list_insert, list_copy,
//   list_piece.

#ifndef MAIN_SAVITCH_NODE_H  
#define MAIN_SAVITCH_NODE_H
#include <cstdlib> // Provides size_t and NULL
#include <string>

typedef std::string value_type;


class node
{
public:
    // TYPEDEF
    typedef std::string value_type;
    
    // CONSTRUCTOR
    node(
	const value_type& init_data = value_type( ),
	node* init_link = NULL
	)
    { data_field = init_data; link_field = init_link; }
    
    // Member functions to set the data and link fields:
    void set_data(const value_type& new_data) { data_field = new_data; }
    void set_link(node* new_link)             { link_field = new_link; }
    
    // Constant member function to retrieve the current data:
    value_type data( ) const { return data_field; }
    
    // Two slightly different member functions to retreive
    // the current link:
    const node* link( ) const { return link_field; }
    node* link( )             { return link_field; }
    
private:
    value_type data_field;
    node* link_field;
};

// FUNCTIONS for the linked list toolkit
size_t list_length(const node* head_ptr);
void list_head_insert(node*& head_ptr, value_type entry);
void list_insert(node*& head_ptr, node* previous_ptr, value_type entry);
bool list_search(node* head_ptr, node*& cur_ptr, node*& previous_ptr, value_type target);
bool list_search(const node* head_ptr, node*& cur_ptr, node*& previous_ptr, value_type target);
node* list_locate(node* head_ptr, size_t position);
const node* list_locate(const node* head_ptr, size_t position);
void list_head_remove(node*& head_ptr);
void list_remove(node* previous_ptr);
void list_clear(node*& head_ptr);
void list_copy(const node* source_ptr, node*& head_ptr, node*& tail_ptr);


#endif 

3. List.CPP

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
// Robert Boettcher
// 01/01/2013
// Implemention file for list class

// Header files

#include <iostream>
#include "list.h"	// List header file
#include "node.h"	// Node header file for linked list operations
#include <cstdlib>	// Provides NULL
using namespace std;




// Con/Destructors

list::list()
{
    head_ptr = NULL;
    many_nodes = 0;
    previous_ptr= NULL;
    
}

list::~list()
{
    list_clear(head_ptr);
    many_nodes = 0;
    
    
}

// Mutators

void list::add(const value_type entry)
{
    node *cur_ptr;	// Pointer to point one node ahead of previous_ptr
    
    list_search(head_ptr, cur_ptr, previous_ptr, entry);
    list_insert(head_ptr, previous_ptr, entry);
    ++many_nodes;
}

void list::del(const value_type target)
{
    
    bool found;	    // True false found target variable
    node *cur_ptr;  // Points to current node
    
    found = list_search(head_ptr, cur_ptr, previous_ptr, target);
    
    // Test for action based on value of found
    
    if (found == true)
    {       
	if (previous_ptr != NULL)
	    list_remove(previous_ptr);
	else
	    list_head_remove(head_ptr);
    
	--many_nodes;
    }
    else
    {
	cout << "Can't delete name because it was not found" << endl << endl;
	system ("pause");
    }
    
}

// Accessors

void list::getlist() const
{
    node *loop_ptr; // Pointer to take value of constant head_ptr
    
    // Loop to display names on flight
    
    for (loop_ptr = head_ptr; loop_ptr != NULL; loop_ptr = loop_ptr->link())
    {
	cout << loop_ptr->data() << endl;
    }
    
}

void list::getnum() const
{
    cout << list_length(head_ptr) << " people on the flight" << endl << endl;
}
4. Node.CPP

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// FILE: node1.cxx
// IMPLEMENTS: The functions of the node class and the
// linked list toolkit (see node1.h for documentation).
// INVARIANT for the node class:
//   The data of a node is stored in data_field, and the link in link_field.

#include "node.h"
#include <cassert>    // Provides assert
#include <cstdlib>    // Provides NULL and size_t
using namespace std;


size_t list_length(const node* head_ptr)
// Library facilities used: cstdlib
{
    const node *cursor;
    size_t answer;
    
    answer = 0;
    for (cursor = head_ptr; cursor != NULL; cursor = cursor->link( ))
	++answer;
    
    return answer;
}

void list_head_insert(node*& head_ptr, value_type entry)
{
    head_ptr = new node(entry, head_ptr);
}

void list_insert(node*& head_ptr, node* previous_ptr, value_type entry)
{
    node *insert_ptr;		// Points to new node
    
    insert_ptr = new node(entry);
    if (previous_ptr != NULL)
    {
	insert_ptr->set_link(previous_ptr-> link());
	previous_ptr->set_link(insert_ptr);
    }
    else        // inserting at head of list
    {
	insert_ptr->set_link(head_ptr);
	head_ptr = insert_ptr;
    }
    
}

bool list_search(node* head_ptr, node*& cur_ptr, node*& previous_ptr, value_type target)
// Library facilities used: cstdlib
{
    bool found = false;
    
    cur_ptr = head_ptr;
    previous_ptr = NULL;
    
    while ((!found) && (cur_ptr != NULL) && (cur_ptr->data() <= target))
    {
	if (cur_ptr->data() == target)
	{
	    found = true;
	}
	else
	{
	    previous_ptr = cur_ptr;
	    cur_ptr = cur_ptr->link();
	}
    }
    return found;
}

bool list_search(const node* head_ptr, const node*& cur_ptr, const node*& previous_ptr, value_type target)
// Library facilities used: cstdlib
{
    bool found = false;
    
    cur_ptr = head_ptr;
    previous_ptr = NULL;
    
    while ((!found) && (cur_ptr != NULL) && (cur_ptr->data() <= target))
    {
	if (cur_ptr->data() == target)
	{
	    found = true;
	}
	else
	{
	    previous_ptr = cur_ptr;
	    cur_ptr = cur_ptr->link();
	}
    }
    return found;
}

node* list_locate(node* head_ptr, size_t position)
// Library facilities used: cassert, cstdlib
{
    node *cursor;
    size_t i;
    
    assert (0 < position);
    cursor = head_ptr;
    for (i = 1; (i < position) && (cursor != NULL); i++)
	cursor = cursor->link( );
    return cursor;
}

const node* list_locate(const node* head_ptr, size_t position)
// Library facilities used: cassert, cstdlib
{
    const node *cursor;
    size_t i;
    
    assert (0 < position);
    cursor = head_ptr;
    for (i = 1; (i < position) && (cursor != NULL); i++)
	cursor = cursor->link( );
    return cursor;
}

void list_head_remove(node*& head_ptr)
{
    node *remove_ptr;
    
    remove_ptr = head_ptr;
    head_ptr = head_ptr->link( );
    delete remove_ptr;
}

void list_remove(node* previous_ptr)
{
    node *remove_ptr;
    
    remove_ptr = previous_ptr->link( );
    previous_ptr->set_link( remove_ptr->link( ) );
    delete remove_ptr;
}

void list_clear(node*& head_ptr)
// Library facilities used: cstdlib
{
    while (head_ptr != NULL)
	list_head_remove(head_ptr);
}

void list_copy(const node* source_ptr, node*& head_ptr, node*& tail_ptr)
// Library facilities used: cstdlib
{
    head_ptr = NULL;
    tail_ptr = NULL;
    
    node *previous_ptr;
    
    // Handle the case of the empty list.
    if (source_ptr == NULL)
	return;
    
    // Make the head node for the newly created list, and put data in it.
    list_head_insert(head_ptr, source_ptr->data( ));
    tail_ptr = head_ptr;
    
    // Copy the rest of the nodes one at a time, adding at the tail of new list.
    source_ptr = source_ptr->link( );
    while (source_ptr != NULL)
    {
	list_insert(tail_ptr, previous_ptr, source_ptr->data( ));
	tail_ptr = tail_ptr->link( );
	source_ptr = source_ptr->link( );
    }
}
5. Airprogram.CPP

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// Robert Boettcher
// 
// 
// Prog 1: Airline Program
// Description: This program is a simple airline reservation system
// It allows the user to enter a name on 4 different flights, you can
// also delete, list and see how many people are on a flight, etc.



// Header files

#include <iostream>		// Standard header file
#include <string>		// String functions
#include <cctype>		// Character functions
#include "list.h"		// My header file

using namespace std;		// Standard namespace


void instruct ();			    // Instruct user
string uppercase (string wholename);	    // Make string uppercase
inline istream& Flush (istream& stream);    // Flush cin

///////////////////////// Main program ///////////////////////////////

int main ()
{
    char choice;	    // Users menu choice
    int menu = 0;	    // Menu flag exit variable
    int num;		    // Flight number user enters
    int counter = 0;	    // Counter for loop
    string firstname;	    // Passengers first name
    string lastname;	    // Passengers last name
    string wholename;	    // Whole name
    
    list flight[4];	    // Initialize 4 flights as class object
			    // array
    
    instruct();		    // Show title and instructions
    cout << endl << endl;
    system("pause");	    // Pause program
    system("cls");	    // Clear the screen
    
    // Main program and menu selection loop

    do {		// while menu != 1
	
	// Show menu
	
	cout << "                 Menu" << endl << endl
	    << "Enter 'A' to add a person to a flight" << endl << endl
	    << "Enter 'D' to delete a person from a flight" << endl << endl
	    << "Enter 'L' to list all passengers on a flight" << endl << endl
	    << "Enter 'I' to see how many passengers are on a flight" << endl << endl
	    << "Enter 'S' to see all flights" << endl << endl
	    << "Enter 'Q' to quit" << endl << endl << endl;
	
	cout << "Enter choice: ";
	cin >> choice;
	
	// Test for bad data
	
	while (!cin)
	{
	    system ("cls");
	    Flush (cin);
	    cout << "Enter choice again: ";
	    cin >> choice;
	}
	
	// end test

	system ("cls");
	
	// Switch to test for choice
	
	switch(toupper(choice))
	{
	case 'A':   // Add name to flight
	    cout << "What flight (1 - 4) : ";
	    cin >> num;
	    
	    // Test for bad data
	    
	    while (!cin || (num < 1 || num > 4))
	    {
		Flush(cin);
		cout << "Enter flight (1 - 4) : ";
		cin >> num;
	    }
	    
	    // End check

	    cout << endl << endl << "Enter name of passenger" << endl
		<< "First name: ";
	    cin.ignore(80, '\n');
	    getline(cin, firstname);
	    if (firstname.at(firstname.length() - 1) == '\n')
		firstname.erase(firstname.length() - 1, 1);
	    cin.ignore(80, '\n');
	    cout << "Last name : ";
	    getline(cin, lastname);
	    if (lastname.at(lastname.length() - 1) == '\n')
		lastname.erase(lastname.length() - 1, 1);
	    
	    // Put first and lastname together in one variable
	    
	    wholename = lastname + " " + firstname;
	    
	    flight[num - 1].add(uppercase(wholename));
	    cout << endl << endl << "Name added" << endl << endl;
	    system ("pause");
	    system ("cls");
	    break;
	case 'D':	// Delete name from flight
	    cout << "What flight (1 - 4) : ";
	    cin >> num;
	    
	    // Check for bad data
	    
	    while (!cin || (num < 1 || num > 4))
	    {
		Flush(cin);
		cout << "Enter flight (1 - 4) : ";
		cin >> num;
	    }
	    
	    // End check

	    cout << endl << endl << "Enter name of passenger" << endl
		<< "First name: ";
	    cin.ignore(80, '\n');
	    getline(cin, firstname);
	    if (firstname.at(firstname.length() - 1) == '\n')
		firstname.erase(firstname.length() - 1, 1);
	    cin.ignore(80, '\n');
	    cout << "Last name : ";
	    getline(cin, lastname);
	    if (lastname.at(lastname.length() - 1) == '\n')
		lastname.erase(lastname.length() - 1, 1);
	    
	    wholename = lastname + " " + firstname;
	    
	    flight[num - 1].del(uppercase(wholename));
	    cout << endl << endl << "Name Deleted" << endl << endl;
	    system ("pause");
	    system ("cls");
	    break;
	case 'L':	// List passengers on a flight
	    cout << "What flight (1 - 4) : ";
	    cin >> num;
	    
	    // Check for bad data
	    
	    while (!cin || (num < 1 || num > 4))
	    {
		Flush(cin);
		cout << "Enter flight (1 - 4) : ";
		cin >> num;
	    }
	    
	    // End check

	    cout << endl;
	    flight[num - 1].getlist();
	    cout << endl << endl;
	    system ("pause");
	    system ("cls");
	    break;
	case 'I':	// See number of passengers on a flight
	    cout << "What flight do you want to check (1 - 4) : ";
	    cin >> num;
	    
	    // Check for bad data

	    while (!cin || (num < 1 || num > 4))
	    {
		Flush(cin);
		cout << "Enter flight (1 - 4) : ";
		cin >> num;
	    }
	    
	    // End check

	    cout << endl;
	    flight[num - 1].getnum();
	    cout << endl << endl;
	    system ("pause");
	    system ("cls");
	    break;
	case 'S':	// See passengers on all flights

	    // Start display loop

	    do {	// While counter !=4
		cout << "Flight " << counter + 1 << " :" << endl << endl;
		flight[counter].getlist();
		cout << endl << endl;
		system ("pause");
		counter++;
		system ("cls");
	    } while (counter != 4);

	    // End loop
	    
	    counter = 0;    // Reset counter
	    system ("cls");
	    break;
	case 'Q':	// Quit program
	    menu = 1;		// set menu = 1 to make loop exit
	    cout << "Goodbye" << endl << endl;
	    system ("pause");
	    break;
	default:	// Bad choice switch selection, go to menu
	    cerr << "Invalid choice" << endl << endl;
	    system ("pause");
	    system ("cls");
	}			    // end switch
    } while (menu != 1);
    
    // End main menu selection and main program loop

    return 0;
    
}

// End main

////////////////////////// Subprograms ///////////////////////////////

// Program title and instructions

void instruct()
{
    cout << "        *************************************************************" << endl
	<< "        *                                                           *" << endl
	<< "        *          Airlines Tycoon Flight Reservation System         *" << endl
	<< "        *                                                           *" << endl
	<< "        *************************************************************" << endl << endl << endl
	<< " Currently 4 flights are available" << endl
	<< " Add, Delete, List and Count people on flight" << endl 
	<< " and lookup single pax info";
}

// End instruct

// Flushes cin stream

inline istream& Flush(istream& stream)
{
    stream.clear();
    int chars_to_skip = stream.rdbuf()->in_avail();
    return stream.ignore(chars_to_skip);
}

// End flush function

// Change string to uppercase

string uppercase(string wholename)
{
    // Go through string and change letters to uppercase as needed

    for (int i = 0; i < wholename.length(); i++)
    {
	if (islower(wholename.at(i)))
	{
	    wholename.replace(i, 1, 1, toupper(wholename.at(i)));
	}
    }

    return wholename;
}

// End function

//////////////////////// End program /////////////////////////////// 
The problem is probably something to do with list.h, but you haven't shown us that. It looks like you've accidentally copied in the contents of node1.h twice instead. Easily done... :)
Last edited on
Topic archived. No new replies allowed.