airline reservations w/ Linked List help! (getting errors)

I need help writing a program for an airline reservation system that inputs and outputs the first name, last name, flight number, and boarding priority (Platinum, Gold, Silver, or Lead). From my lecture notes, this is what I've written so far. I ran it by my professor and he said the structure was correct but after trying to run it on Visual Studio 2015, I noticed a few errors. The programs compiles and runs, but as soon as I enter a name, the code goes haywire on me. I'm sure the error is happening in the void Airlines::appendNode() portion of the code, but am unsure what is incorrect. Please help
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
#pragma once
#include <iostream>
using namespace std;

const int NAME = 50;

class Airlines
{
	struct ListNode
	{
		char	FName = NAME;
		char	LName = NAME;
		char 	Priority;
		int		FltNum;
		char	value;

		ListNode* next;
	};
		ListNode* head;
	public:
		Airlines() { head = NULL; }
		ListNode pass;
		void appendNode();
		void displayReservation();
};

#include "Airline.h"

void Airlines::appendNode()
{
	ListNode* newNode, *nodePtr;
	newNode = new ListNode;
	cout << "Enter a first name\n";
	cin >> pass.FName;
	cout << "First Name: " << pass.FName << endl;
	newNode->value = pass.FName;
	newNode->next = NULL;

	newNode = new ListNode;
	cout << "Enter a last name\n";
	cin >> pass.LName;
	cout << "Last Name: " << pass.LName << endl;
	newNode->value = pass.LName;
	newNode->next = NULL;

	newNode = new ListNode;
	cout << "Enter a number\n";
	cin >> pass.FltNum;
	cout << "Fight Number: " << pass.FltNum << endl;
	newNode->value = pass.FltNum;
	newNode->next = NULL;

	newNode = new ListNode;
	cout << "Enter a boarding Priority\n";
	cin >> pass.Priority;
	if ((pass.Priority == 'G') || (pass.Priority == 'g'))
		cout << "Your boarding priority is gold\n";
	else ((pass.Priority == 'S') || (pass.Priority == 's'))
		cout << "Your boarding priority is gold\n";
	newNode->value = pass.Priority;
	newNode->next = NULL;

	if (!head)
		head = newNode;
	else
	{
		nodePtr = head;
		while (nodePtr->next)
			nodePtr = nodePtr->next;
		nodePtr->next = newNode;
	}
}


void Airlines::displayReservation(void)
{
	ListNode* nodePtr;
	nodePtr = head;
	if (head == NULL)
		cout << "Your list is empty\n";
	else
	{
		while (nodePtr)
		{
			cout << nodePtr->value << endl;
			nodePtr = nodePtr->next;
		}
	}
}


int main()
{
	Airlines list;
	char prompt;
	char loop = 'y';
	do
	{
		cout << " AIRLINE RESERVATION SYSTEM \n";
		cout << "Press (E) to Enter passenger flight information " << endl;
		cout << "Press (D) to Display the passenger flight information " << endl;
		cout << "Press (Q) to Quit the program " << endl;
		cin >> prompt;

		switch (prompt)
		{
		case 'E':
		case 'e':
			list.appendNode();
			break;

		case 'D':
		case 'd':
			list.displayReservation();
			cout << endl;
			break;

		case 'Q':
		case 'q':
			loop = 'n';
			cout << "\nExiting the program..\n";
			break;

		default: cout << "this is an invalid choice. Please select prompt from the menu.\n";
		}system("pause");
	} while ((loop == 'Y') || (loop == 'y'));

	return 0;
}


This is a sample code I built upon for my assignment:
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
#pragma once
#include <iostream>
using namespace std;

class FloatList
{
	struct ListNode
	{
		double value;
		ListNode* next;
	};
	ListNode* head;
public:
	FloatList() { head = NULL;  }

	void appendNode(double);
	void insertNode(double);
	void deleteNode(double);
	void displayList();
};

#include "link.h"

void FloatList::appendNode(double num)
{
	ListNode* newNode, *nodePtr;
	newNode = new ListNode;
	newNode->value = num;
	newNode->next = NULL;

	if (!head)
		head = newNode;
	else
	{
		nodePtr = head;
		while (nodePtr->next)
			nodePtr = nodePtr->next;
		nodePtr->next = newNode;
	}
}

void FloatList::displayList(void)
{
	ListNode* nodePtr;
	nodePtr = head;
	while (nodePtr)
	{
		cout << nodePtr->value << endl;
		nodePtr = nodePtr->next;
	}
}

void FloatList::insertNode(double num)
{
	ListNode *newNode, *nodePtr, *previousNode;

	newNode = new ListNode;
	newNode->value = num;

	if (!head)
	{
		head = newNode;
		newNode->next = NULL;
	}

	else
	{
		nodePtr = head;

		while ((nodePtr != NULL) && (nodePtr->value < num))
		{
			previousNode = nodePtr;
			nodePtr = nodePtr->next;
		}

		previousNode = nodePtr;
		nodePtr = nodePtr->next;
	}
}

void FloatList::deleteNode(double num)
{
	ListNode *nodePtr, *previousNode;

	if (!head)
		return;

	if (head->value == num)
	{
		nodePtr = head->next;
		delete head;
		head = nodePtr;
	}
	
	else
	{
		nodePtr = head;

		while ((nodePtr != NULL) && (nodePtr->value != num))
		{
			previousNode = nodePtr;
			nodePtr = nodePtr->next;
		}
		previousNode->next = nodePtr->next;
		delete nodePtr;
	}
}

int main()
{
	FloatList list;

	list.appendNode(2.5);
	list.appendNode(4.5);
	list.appendNode(7.9);
	list.appendNode(12.6);
	list.appendNode(67.9);

	list.displayList();
	cout << endl;

	cout << "now you are deleting 7.9.\n";
	cout << "remaining nodes: \n";
	list.deleteNode(7.9);
	list.displayList();
	cout << endl;

	cout << "now you are deleting 12.6.\n";
	cout << "remaining nodes: \n";
	list.deleteNode(12.6);
	list.displayList();
	cout << endl;

	system("pause");
	return 0;
}
Last edited on
Most of the code deals with the Airlines::PassengerInfo class, not the Airlines class. So lets start by moving the appropriate code there. By the way, I changed strcpy_s to strcpy since strcpy_s doesn't seem to be in the standard.

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
const short SIZE = 10;
const short PSIZE = 10;
const int NAME = 50;

class Airlines
{
    int pass_count;
    struct PassengerInfo
    {
	char FName[NAME];
	char LName[NAME];
	char Priority[PSIZE];
	int FltNum;
	void read();
	void selectPriority();
	void display();
    };
  public:
      Airlines():pass_count(0)
    {
    };
    PassengerInfo p_info[SIZE];
    void topMenu();
    void addPassenger();
    void displayPassenger();
    void selectPriority();
};

#include <iostream>
#include <cstring>		// dmh
using     std::cout;
using    std::cin;
using    std::endl;
using    std::system;

#include "TAirlines.h"

void
Airlines::PassengerInfo::read()
{
    bool flt_flag;
    long FName_len = 0;
    long LName_len = 0;

    cout << " ENTER THE PASSENGER(S) FLIGHT RESERVATION(S) \n";

    cin.get();
    cout << "Please enter your first name: ";

    cin.getline(FName, NAME);

    FName_len = cin.gcount();

    while (FName[0] == '\0' || FName_len > 15) {
	cout <<
	    "\nFirst Name cannot be empty and length MUST be less than 16 characters. \n";

	cout << "Please re-enter your First Name: ";
	cin.getline(FName, NAME);
	FName_len = cin.gcount();
    }

    cout << "Please enter your Last Name: ";

    cin.getline(LName, NAME);

    LName_len = cin.gcount();

    while (LName[0] == '\0' || LName_len > 15) {
	cout <<
	    "\nLast Name cannot be empty and length MUST be less than 16 characters. \n";

	cout << "Please re-enter your Last Name: ";
	cin.getline(LName, NAME);
	LName_len = cin.gcount();
    }

    selectPriority();

    cout << "Pleas enter your Flight Number: ";
    cin >> FltNum;
    flt_flag = cin.fail();

    while (flt_flag == true) {
	cin.clear();
	cin.ignore(10000, '\n');
	cout << "Please re-enter your Flight Number: ";
	cin >> FltNum;
	flt_flag = cin.fail();
    }
}


void
Airlines::PassengerInfo::selectPriority()
{
    char pr;
    cin.clear();
    cout << "Please enter your boarding priority: " << endl;

    cout << "             BOARDING PRIORITY OPTIONS                \n";

    cout << "(P) - Platinum " << endl;
    cout << "(G) - Gold " << endl;
    cout << "(S) - Silver " << endl;
    cout << "(L) - Lead " << endl;
    cout << "CHOICE: ";
    cin >> pr;

    if (pr == 'P' || pr == 'p') {
	// DMH
	strcpy(Priority, "Platinum ");
	cout << "\nPriority is \"" << Priority << "\" now.\n\n";
    } else if (pr == 'G' || pr == 'g') {
	strcpy(Priority, "Gold ");
	cout << "\nPriority is \"" << Priority << "\" now.\n\n";
    } else if (pr == 'S' || pr == 's') {
	strcpy(Priority, "Silver ");
	cout << "\nPriority is \"" << Priority << "\" now.\n\n";
    } else if (pr == 'L' || pr == 'l') {
	strcpy(Priority, "Lead ");
	cout << "\nPriority is \"" << Priority << "\" now.\n\n";
    } else {
	cout << "\nThis is an invalid Boarding Priority, Please re-enter your choices:\n";
	system("pause");
	system("CLS");
	selectPriority();
    }
}

void
Airlines::PassengerInfo::display()
{
    cout << "First Name: " << FName << endl;
    cout << "Last Name: " << LName << endl;
    cout << "Priority: " << Priority << endl;
    cout << "Flight Number: " << FltNum << endl;
}



void
Airlines::displayPassenger()
{
    system("cls");
    cout << "      PASSENGER INFO       \n";

    if (pass_count == 0)
	cout << "No Records Found!\nAdd at least one Passenger Record\n";

    for (int i = 0; i < pass_count; i++) {
	p_info[i].display();
    }
    topMenu();
}

void
Airlines::addPassenger()
{
    p_info[pass_count].read();
    pass_count++;
    system("CLS");
    topMenu();
}


void
Airlines::topMenu()
{
    char ch;
    cout << " AIRLINE RESERVATION SYSTEM \n";

    cout << "Press (E) to Enter passenger flight information " << endl;
    cout << "Press (D) to Display the passenger flight information " << endl;
    cout << "Press (Q) to Quit the program " << endl;
    cin >> ch;

    if (ch == 'E' || ch == 'e')
	addPassenger();
    else if (ch == 'D' || ch == 'd')
	displayPassenger();
    else if (ch == 'Q' || ch == 'q')
	cout << "\nExiting the program..\n";
    else {
	cout << "\nPlease enter a correct value from the menu.\n";
	topMenu();
    }
}

int
main()
{
    std::cin.clear();
    Airlines air;
    air.topMenu();
    return 0;
}

Poof! Just like that, the code that you have to modify shinks from "most of the program" to 22 lines from 142 to 164.

I assume you can't use std::list?

So you'll have to make a list of PassengerInfo based on the FloatList class:
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
class Airlines
{
    int pass_count;
    struct PassengerInfo
    {
        char FName[NAME];
        char LName[NAME];
        char Priority[PSIZE];
        int FltNum;
        void read();
        void selectPriority();
        void display();
    };

    class List
    {
        struct ListNode
        {
            PassengerInfo value;
            ListNode* next;
        };
        ListNode* head;
    public:
        List() { head = NULL;  }

        void appendNode(const PassengerInfo &);
        void insertNode(const PassengerInfo &);
        void deleteNode(const PassengerInfo &);
        void displayList();
    };

Modify the appendNode, insertNode and deleteNode methods. Then change Airlines::p_info array to List p_info and figure how to change each of the places in the code where p_info appears.
In a previous assignment, we were to do the same thing, but implement it using an array. This is somewhat what my professor was looking for in that assignment:

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
#include "Airline.h"
void Airlines::addPassenger()
{
	bool flt_flag;
	long FName_len = 0;
	long LName_len = 0;

	cout << " ENTER THE PASSENGER(S) FLIGHT RESERVATION(S) \n";

	cin.get();
	cout << "Please enter your first name: ";

	cin.getline(p_info[pass_count].FName, NAME);

	FName_len = cin.gcount();

	while (p_info[pass_count].FName[0] == '\0' || FName_len > 15)
	{
		cout << "\nFirst Name cannot be empty and length MUST be less than 16 characters. \n";

		cout << "Please re-enter your First Name: ";
		cin.getline(p_info[pass_count].FName, NAME);
		FName_len = cin.gcount();
	}

	cout << "Please enter your Last Name: ";

	cin.getline(p_info[pass_count].LName, NAME);

	LName_len = cin.gcount();

	while (p_info[pass_count].LName[0] == '\0' || LName_len > 15)
	{
		cout << "\nLast Name cannot be empty and length MUST be less than 16 characters. \n";

		cout << "Please re-enter your Last Name: ";
		cin.getline(p_info[pass_count].LName, NAME);
		LName_len = cin.gcount();
	}

	selectPriority();

	cout << "Pleas enter your Flight Number: ";
	cin >> p_info[pass_count].FltNum;
	flt_flag = cin.fail();

	while (flt_flag == true)
	{
		cin.clear();
		cin.ignore(10000, '\n');
		cout << "Please re-enter your Flight Number: ";
		cin >> p_info[pass_count].FltNum;
		flt_flag = cin.fail();
	}

	pass_count++;
	system("CLS");
}
void Airlines::selectPriority()
{
		char pr;
		cin.clear();
		cout << "Please enter your boarding priority: " << endl;

		cout << "             BOARDING PRIORITY OPTIONS                \n";

		cout << "(P) - Platinum " << endl;
		cout << "(G) - Gold " << endl;
		cout << "(S) - Silver " << endl;
		cout << "(L) - Lead " << endl;
		cout << "CHOICE: ";
		cin >> pr;

		if (pr == 'P' || pr == 'p')
		{
			strcpy_s(p_info[pass_count].Priority, "Platinum ");
			cout << "\nPriority is \"" << p_info[pass_count].Priority << "\" now.\n\n";
		}
		else if (pr == 'G' || pr == 'g')
		{
			strcpy_s(p_info[pass_count].Priority, "Gold ");
			cout << "\nPriority is \"" << p_info[pass_count].Priority << "\" now.\n\n";
		}
		else if (pr == 'S' || pr == 's')
		{
			strcpy_s(p_info[pass_count].Priority, "Silver ");
			cout << "\nPriority is \"" << p_info[pass_count].Priority << "\" now.\n\n";
		}
		else if (pr == 'L' || pr == 'l')
		{
			strcpy_s(p_info[pass_count].Priority, "Lead ");
			cout << "\nPriority is \"" << p_info[pass_count].Priority << "\" now.\n\n";
		}
		else
		{
			cout << "\nThis is an invalid Boarding Priority, Please re-enter your choices:\n";
			system("pause");
			system("CLS");
			selectPriority();
		}
}
Last edited on
Okay, so you've replaced PassengerInfo with ListNode and added ListNode *next and double value to the struct.

What is the purpose of double value?

Why do appendNode() and insertNode() take a double as a parameter?

Why does displayList() display value?

The answer is that the code you're using as an example is a list of doubles. What you want is a list of PassengerInfo's So conceptually, you want to replace double value in the list with PassengerInfo value.

Now look back at my first post. That's exactly what I've suggested.
For this assignment we didn't need insertNode() that was just part of the example i was refencing
Last edited on
You don't seem to be taking my suggestions. I'm sorry but I'm unable to help you further. Maybe someone else can.
It has to look like this, but I am unsure where I am getting my errors

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
#pragma once
#include <iostream>
using namespace std;

const int NAME = 50;

class Airlines
{
	struct ListNode
	{
		char	FName = NAME;
		char	LName = NAME;
		char 	Priority;
		int		FltNum;
		char	value;

		ListNode* next;
	};
		ListNode* head;
	public:
		Airlines() { head = NULL; }
		ListNode pass;
		void appendNode();
		void displayReservation();
};

#include "Airline.h"

void Airlines::appendNode()
{
	ListNode* newNode, *nodePtr;
	newNode = new ListNode;
	cout << "Enter a first name\n";
	cin >> pass.FName;
	cout << "First Name: " << pass.FName << endl;
	newNode->value = pass.FName;
	newNode->next = NULL;

	newNode = new ListNode;
	cout << "Enter a last name\n";
	cin >> pass.LName;
	cout << "Last Name: " << pass.LName << endl;
	newNode->value = pass.LName;
	newNode->next = NULL;

	newNode = new ListNode;
	cout << "Enter a number\n";
	cin >> pass.FltNum;
	cout << "Fight Number: " << pass.FltNum << endl;
	newNode->value = pass.FltNum;
	newNode->next = NULL;

	newNode = new ListNode;
	cout << "Enter a boarding Priority\n";
	cin >> pass.Priority;
	if ((pass.Priority == 'G') || (pass.Priority == 'g'))
		cout << "Your boarding priority is gold\n";
	else ((pass.Priority == 'S') || (pass.Priority == 's'))
		cout << "Your boarding priority is gold\n";
	newNode->value = pass.Priority;
	newNode->next = NULL;

	if (!head)
		head = newNode;
	else
	{
		nodePtr = head;
		while (nodePtr->next)
			nodePtr = nodePtr->next;
		nodePtr->next = newNode;
	}
}


void Airlines::displayReservation(void)
{
	ListNode* nodePtr;
	nodePtr = head;
	if (head == NULL)
		cout << "Your list is empty\n";
	else
	{
		while (nodePtr)
		{
			cout << nodePtr->value << endl;
			nodePtr = nodePtr->next;
		}
	}
}


int main()
{
	Airlines list;
	char prompt;
	char loop = 'y';
	do
	{
		cout << " AIRLINE RESERVATION SYSTEM \n";
		cout << "Press (E) to Enter passenger flight information " << endl;
		cout << "Press (D) to Display the passenger flight information " << endl;
		cout << "Press (Q) to Quit the program " << endl;
		cin >> prompt;

		switch (prompt)
		{
		case 'E':
		case 'e':
			list.appendNode();
			break;

		case 'D':
		case 'd':
			list.displayReservation();
			cout << endl;
			break;

		case 'Q':
		case 'q':
			loop = 'n';
			cout << "\nExiting the program..\n";
			break;

		default: cout << "this is an invalid choice. Please select prompt from the menu.\n";
		}system("pause");
	} while ((loop == 'Y') || (loop == 'y'));

	return 0;
}
Last edited on
I omitted the function read() and display() from struct PassengerInfo because they seemed unnecessary to the code.

No, they are a big reason why making the change from array to list is pretty easy. As I said in my first post
Poof! Just like that, the code that you have to modify shinks from "most of the program" to 22 lines from 142 to 164.


I gave you code that you should work from. Use it.
I cannot use your version because it doesn't follow the structure my code is supposed to be in. I need help with the code I have written here; it works (sorta). When I compile and run it, as soon as I enter the first name it glitches and jumps to the menu and then it becomes a mess. I'm not sure what is causing this.
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
#pragma once
#include <iostream>
using namespace std;

const int NAME = 50;

class Airlines
{
	struct ListNode
	{
		char	FName = NAME;
		char	LName = NAME;
		char 	Priority;
		int		FltNum;
		char	value;

		ListNode* next;
	};
		ListNode* head;
	public:
		Airlines() { head = NULL; }
		ListNode pass;
		void appendNode();
		void displayReservation();
};

#include "Airline.h"

void Airlines::appendNode()
{
	ListNode* newNode, *nodePtr;
	newNode = new ListNode;
	cout << "Enter a first name\n";
	cin >> pass.FName;
	cout << "First Name: " << pass.FName << endl;
	newNode->value = pass.FName;
	newNode->next = NULL;

	newNode = new ListNode;
	cout << "Enter a last name\n";
	cin >> pass.LName;
	cout << "Last Name: " << pass.LName << endl;
	newNode->value = pass.LName;
	newNode->next = NULL;

	newNode = new ListNode;
	cout << "Enter a number\n";
	cin >> pass.FltNum;
	cout << "Fight Number: " << pass.FltNum << endl;
	newNode->value = pass.FltNum;
	newNode->next = NULL;

	newNode = new ListNode;
	cout << "Enter a boarding Priority\n";
	cin >> pass.Priority;
	if ((pass.Priority == 'G') || (pass.Priority == 'g'))
		cout << "Your boarding priority is gold\n";
	else if ((pass.Priority == 'S') || (pass.Priority == 's'))
		cout << "Your boarding priority is gold\n";
	newNode->value = pass.Priority;
	newNode->next = NULL;

	if (!head)
		head = newNode;
	else
	{
		nodePtr = head;
		while (nodePtr->next)
			nodePtr = nodePtr->next;
		nodePtr->next = newNode;
	}
}


void Airlines::displayReservation(void)
{
	ListNode* nodePtr;
	nodePtr = head;
	if (head == NULL)
		cout << "Your list is empty\n";
	else
	{
		while (nodePtr)
		{
			cout << nodePtr->value << endl;
			nodePtr = nodePtr->next;
		}
	}
}


int main()
{
	Airlines list;
	char prompt;
	char loop = 'y';
	do
	{
		cout << " AIRLINE RESERVATION SYSTEM \n";
		cout << "Press (E) to Enter passenger flight information " << endl;
		cout << "Press (D) to Display the passenger flight information " << endl;
		cout << "Press (Q) to Quit the program " << endl;
		cin >> prompt;

		switch (prompt)
		{
		case 'E':
		case 'e':
			list.appendNode();
			break;

		case 'D':
		case 'd':
			list.displayReservation();
			cout << endl;
			break;

		case 'Q':
		case 'q':
			loop = 'n';
			cout << "\nExiting the program..\n";
			break;

		default: cout << "this is an invalid choice. Please select prompt from the menu.\n";
		}system("pause");
	} while ((loop == 'Y') || (loop == 'y'));

	return 0;
}


I came across this code in my notes which somewhat does what I need; void push() acts like void Airlines::appendNode() and void pop() acts like void Airlines::displayReservation(void) (but it doesn't display all the entries, which is what I need my program to do). How would I go about implementing this in my code above to get it to work how I need it to?
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
#include <iostream>
using namespace std;

short const SIZE = 20;

struct node
{
	char name[SIZE];
	int age;
	float height;
	node *next;
};
node *start_ptr = NULL;
void push();
void pop();

void push()
{
	node *temp;
	
	temp = new node;
	cout << "Enter name of person: ";
	cin >> temp->name;
	cout << "Enter age of person: ";
	cin >> temp->age;
	cout << "Enter height of person: ";
	cin >> temp->height;

	if (start_ptr == NULL)
	{
		temp->next = NULL;
		start_ptr = temp;
	}
	else
	{
		temp->next = start_ptr;
		start_ptr = temp;
	}
}

void pop()
{
	node *temp1, *temp2;

	if (start_ptr == NULL)
		cout << "List is empty ";
	else
	{
		temp1 = start_ptr;
		temp2 = temp1;

		while (temp1->next != NULL)
		{
			temp2 = temp1;
			temp1 = temp1->next;
		}

		if (temp1 == temp2)
		{
			cout << "Name is: " << temp1->name << endl;
			cout << "Age is: " << temp1->age << endl;
			cout << "Height is: " << temp1->height << endl;
			start_ptr = NULL;
		}
		else
		{
			cout << "Name is: " << temp1->name << endl;
			cout << "Age is: " << temp1->age << endl;
			cout << "Height is: " << temp1->height << endl;
			temp2->next = NULL;
		}
	}
}

int main()
{
	char prompt;
	system("cls");
	cout << "QUEUE\n";
	cout << "------\n";

	do
	{
		cout << "Select an operation:\n";
		cout << "p->push\n";
		cout << "o->pop\n";
		cout << "q->quit\n";
		cin >> prompt;

		switch (prompt)
		{
		case 'p':
		case 'P':
			push();
			break;
		case 'o':
		case 'O':
			pop();
			break;
		case 'q':
		case 'Q':
			exit(0);
		}
	} while ((prompt != 'q') || (prompt != 'Q'));

		return 0;
}
1
2
  char	FName = NAME;
  char	LName = NAME;


You create one character and store the value 50 in it. Is this what you want?
Do you maybe want to create a character array to store the name?
Should be char FName[NAME]; then.
I cannot use your version because it doesn't follow the structure my code is supposed to be in.
Can you elaborate on exactly what structure the code is supposed to be in? Post the assignment itself if possible.
I cannot use your version because it doesn't follow the structure my code is supposed to be in

but did you at least try and customize it for your needs and, if so, where did it fail? or did you study the code and see how it could be applied to your context? it's not always possible to get exactly what you want
Topic archived. No new replies allowed.