Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Form tìm kiếm

Dự án C sau đây chứa mã nguồn C và các ví dụ C được sử dụng cho chương trình danh sách liên kết hàng không (được cập nhật). Đây là một chương trình bắt chước một hệ thống đặt phòng hàng không đơn giản.

Mã nguồn và tệp có trong dự án này được liệt kê trong phần Tệp dự án, vui lòng đảm bảo rằng mã nguồn được liệt kê có đáp ứng nhu cầu của bạn ở đó không.

Tệp dự án: & NBSP;

Tên tập tinKích thước
hãng hàng không.dsp4533
hãng hàng không.dsw537
Hãng hàng không.ncb115712
Hãng hàng không.opt49664
Hãng hàng không.plg1291
AirProgram.cpp7416
Danh sách.cpp1825
Danh sách.H1479
Node.cpp4002
Nút.H7890

SocialTags: 

  • Hàng không
  • Việc kinh doanh
  • Danh sách liên kết
  • Hàng không
  • CXP
  • Không khí zaïre

Tải xuống mã nguồn

[X]

Chương trình danh sách liên kết hàng không (cập nhật) trong C

Tập tin đính kèmKích thước
Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết
hãng hàng không.dsp
hãng hàng không.dsw

Hãng hàng không.ncb

  • Hãng hàng không.opt
  • Hãng hàng không.plg
  • AirProgram.cpp
  • Danh sách.cpp
  • Danh sách.H

  • Diễn đàn
  • Lập trình chung C ++
  • Đặt chỗ hàng không w/ Danh sách liên kết trợ giúp

Đặt chỗ hàng không w/ Danh sách liên kết Trợ giúp! (nhận lỗi)

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Tôi cần trợ giúp viết một chương trình cho một hệ thống đặt phòng hàng không, đầu vào và xuất ra tên, họ, số chuyến bay và ưu tiên lên máy bay (bạch kim, vàng, bạc hoặc chì). Từ ghi chú bài giảng của tôi, đây là những gì tôi đã viết cho đến nay. Tôi đã điều hành nó bởi giáo sư của tôi và anh ấy nói rằng cấu trúc này là chính xác nhưng sau khi cố gắng chạy nó trên Visual Studio 2015, tôi nhận thấy một vài lỗi. Các chương trình biên dịch và chạy, nhưng ngay khi tôi nhập tên, mã sẽ chuyển sang tôi. Tôi chắc chắn rằng lỗi đang xảy ra trong phần

#pragma once
#include 
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;
}
8 của mã, nhưng tôi không chắc chắn điều gì không chính xác. Xin vui lòng giúp đỡ
#pragma once
#include 
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;
}
8
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 
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;
}

Đây là mã mẫu tôi đã xây dựng cho bài tập của mình:

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 
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;
}

Đã chỉnh sửa lần cuối

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Hầu hết các mã liên quan đến lớp Airlines :: PassengerInfo, không phải lớp của các hãng hàng không. Vì vậy, hãy bắt đầu bằng cách di chuyển mã thích hợp ở đó. Nhân tiện, tôi đã thay đổi strcpy_s thành strcpy vì strcpy_s dường như không ở trong tiêu chuẩn.

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 
#include 		// 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! Chỉ như vậy, mã mà bạn phải sửa đổi các shinks từ "hầu hết các chương trình" thành 22 dòng từ 142 thành 164.

Tôi cho rằng bạn không thể sử dụng STD :: Danh sách?

Vì vậy, bạn sẽ phải lập một danh sách các hành khách dựa trên lớp floatlist:

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();
    };

Sửa đổi các phương thức appendNode, insertNode và deletenode. Sau đó, thay đổi hãng hàng không :: mảng p_info thành

#pragma once
#include 
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;
}
9 và tìm cách thay đổi từng vị trí trong mã xuất hiện P_INFO.
#pragma once
#include 
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;
}
9
and figure how to change each of the places in the code where p_info appears.

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Trong một bài tập trước, chúng tôi đã làm điều tương tự, nhưng thực hiện nó bằng một mảng. Đây là phần nào mà giáo sư của tôi đang tìm kiếm trong nhiệm vụ đó:

________số 8
#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();
		}
}

Đã chỉnh sửa lần cuối

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Hầu hết các mã liên quan đến lớp Airlines :: PassengerInfo, không phải lớp của các hãng hàng không. Vì vậy, hãy bắt đầu bằng cách di chuyển mã thích hợp ở đó. Nhân tiện, tôi đã thay đổi strcpy_s thành strcpy vì strcpy_s dường như không ở trong tiêu chuẩn.

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
0with
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
1
and added
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
2
and
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
3
to the struct.

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 
#include 		// 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! Chỉ như vậy, mã mà bạn phải sửa đổi các shinks từ "hầu hết các chương trình" thành 22 dòng từ 142 thành 164.

Tôi cho rằng bạn không thể sử dụng STD :: Danh sách?

Vì vậy, bạn sẽ phải lập một danh sách các hành khách dựa trên lớp floatlist:

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();
    };

Sửa đổi các phương thức appendNode, insertNode và deletenode. Sau đó, thay đổi hãng hàng không :: mảng p_info thành
#pragma once
#include 
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;
}
9 và tìm cách thay đổi từng vị trí trong mã xuất hiện P_INFO.

Trong một bài tập trước, chúng tôi đã làm điều tương tự, nhưng thực hiện nó bằng một mảng. Đây là phần nào mà giáo sư của tôi đang tìm kiếm trong nhiệm vụ đó: in the list with

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
5.

________số 8

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

#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();
		}
}

Đã chỉnh sửa lần cuối

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Hầu hết các mã liên quan đến lớp Airlines :: PassengerInfo, không phải lớp của các hãng hàng không. Vì vậy, hãy bắt đầu bằng cách di chuyển mã thích hợp ở đó. Nhân tiện, tôi đã thay đổi strcpy_s thành strcpy vì strcpy_s dường như không ở trong tiêu chuẩn.

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

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

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 
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;
}

Đã chỉnh sửa lần cuối

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Hầu hết các mã liên quan đến lớp Airlines :: PassengerInfo, không phải lớp của các hãng hàng không. Vì vậy, hãy bắt đầu bằng cách di chuyển mã thích hợp ở đó. Nhân tiện, tôi đã thay đổi strcpy_s thành strcpy vì strcpy_s dường như không ở trong tiêu chuẩn.

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 
#include 		// 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;

}

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Poof! Chỉ như vậy, mã mà bạn phải sửa đổi các shinks từ "hầu hết các chương trình" thành 22 dòng từ 142 thành 164.

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 
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;
}

Đây là mã mẫu tôi đã xây dựng cho bài tập của mình:

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
6 acts like
#pragma once
#include 
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;
}
8
and
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
8
acts like
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
9
(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
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 
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;
}

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Đã chỉnh sửa lần cuối Hầu hết các mã liên quan đến lớp Airlines :: PassengerInfo, không phải lớp của các hãng hàng không. Vì vậy, hãy bắt đầu bằng cách di chuyển mã thích hợp ở đó. Nhân tiện, tôi đã thay đổi strcpy_s thành strcpy vì strcpy_s dường như không ở trong tiêu chuẩn.

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

Do you maybe want to create a character array to store the name?
Should be
#pragma once
#include 
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;
}
0
then.

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

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 
#include 		// 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;

}

Hướng dẫn airline reservation system project in c++ using linked list - dự án hệ thống đặt chỗ hàng không bằng c ++ sử dụng danh sách liên kết

Tôi không thể sử dụng phiên bản của bạn vì nó không tuân theo cấu trúc mã của tôi được cho là

Nhưng ít nhất bạn đã thử và tùy chỉnh nó cho nhu cầu của bạn và, nếu vậy, nó đã thất bại ở đâu? Hoặc bạn đã nghiên cứu mã và xem làm thế nào nó có thể được áp dụng cho bối cảnh của bạn? Không phải lúc nào cũng có thể có được chính xác những gì bạn muốn

Chủ đề lưu trữ.Không cho phép trả lời mới.