本文实例为大家分享了C语言实现航班管理系统的具体代码,供大家参考,具体内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
/*C语言实现简单的航班管理系统(单个文件)*/ #include <stdio.h> #include <string.h> #include<stdlib.h> #include<assert.h> #define PERSON_MAXNUM 100 #define PERSONNOTICKET_MAX 10 #define MAX_SIZE 10 int _size = 0; int _person_size = 0; int _personnoticket_size = 0; //定义航班信息结构体 typedef struct plane { char ID[10]; char Start_Place[10]; char End_Place[10]; float price; int Buy_num; int Max_num; char time [20]; }Plane; //定义乘客信息结构体 typedef struct Person { int AirPlane_Num; char person_name[20]; }Person; void home(Plane* p,Person* person, Person* person_noticket); //初始页面 void InitAirPlane(Plane** p); //初始化航班信息内存 void InputAirPlane(Plane* p); //输入航班信息 void CheckAirPlane(Plane* p); //查看航班信息 void DelAirPlane(Plane* p); //删除航班信息 void CheckAirPlaneOrder(Plane* p,Person* person); //查看航班订单 void PrintPerson(Plane* p, Person* person, int i); //打印航班乘客 void InitPerson(Person** person); //初始化乘客信息内存 void BookAirPlane(Plane* p, Person* person,Person* person_noticket); //预定航班 int CheckPerson(Plane* p, Person* person); //查看乘客订单信息 void ChangeAirPlane(Plane* p, Person* person); //改签 void ReturnTicket(Plane* p, Person* person); //退票 void PrintPerson(Plane* p, Person* person, int i); void CheckPersonNoTicket(Plane* p, Person* person_noticket); //查看候补名单 /////////////////////////////////////// void home(Plane* p, Person* person, Person* person_noticket) { int a, i, j; printf ( "\n*****************************欢迎进入飞机票务系统*****************************\n" ); printf ( "\n*************您好,现在要确认您的身份!票务人员请按 1 ,旅客请按 0 ***********\n" ); printf ( "请选择:" ); scanf ( "%d" , &a); //航班管理人员操作 if (a == 1) do { printf ( "\n****************** 1.输入航班信息 *******************\n" ); printf ( "\n****************** 2.删除航班信息 *******************\n" ); printf ( "\n****************** 3.浏览航班信息 *******************\n" ); printf ( "\n****************** 4.浏览目前已订票信息 *************\n" ); printf ( "\n****************** 5.查看候补名单 *******************\n" ); printf ( "\n****************** 0.退出 ********************\n" ); printf ( "请选择:" ); scanf ( "%d" , &i); switch (i) { case 0: break ; case 1:InputAirPlane(p); break ; case 2:DelAirPlane(p); break ; case 3:CheckAirPlane(p); break ; case 4:CheckAirPlaneOrder(p, person); break ; case 5:CheckPersonNoTicket(p, person_noticket); break ; default : printf ( "输入错误!\n" ); break ; } } while (i != 0); //乘客操作 if (a == 0) do { printf ( "\n*********************** 1.订票 **********************\n" ); printf ( "\n*********************** 2.改签 **********************\n" ); printf ( "\n*********************** 3.退票 **********************\n" ); printf ( "\n*********************** 4.浏览航班信息 **************\n" ); printf ( "\n*********************** 5.查询个人订票信息 **********\n" ); printf ( "\n*********************** 0.退出 **********************\n" ); printf ( "请选择:" ); scanf ( "%d" , &j); switch (j) { case 0: break ; case 1:BookAirPlane(p, person,person_noticket); break ; case 2:ChangeAirPlane(p, person); break ; case 3:ReturnTicket(p, person); break ; case 4:CheckAirPlane(p); break ; case 5:CheckPerson(p, person); break ; } } while (j != 0); } //初始化 void InitAirPlane(Plane** p) { assert (p); //申请空间 *p = (Plane*) malloc ( sizeof (Plane)*MAX_SIZE); if (NULL == *p) { printf ( "开辟空间失败!\n" ); return ; } (*p)->Buy_num = 0; } //输入航班信息 void InputAirPlane(Plane* p) { if (_size <= MAX_SIZE) { printf ( "航班编号:%d\n" , _size); printf ( "输入航班ID:" ); scanf ( "%s" , (p+_size)->ID); printf ( "输入始发地:" ); scanf ( "%s" , (p + _size)->Start_Place); printf ( "输入目的地:" ); scanf ( "%s" , (p + _size)->End_Place); printf ( "输入航班起飞时间:" ); scanf ( "%s" , (p + _size)-> time ); printf ( "输入价格:" ); scanf ( "%f" , &(p + _size)->price); printf ( "输入航班可乘坐最大人数:" ); scanf ( "%d" , &(p + _size)->Max_num); do { printf ( "目前卖出机票数量:" ); scanf ( "%d" , &(p + _size)->Buy_num); if ((p + _size)->Buy_num > (p + _size)->Max_num) { printf ( "输入已卖出机票数量错误!\n" ); printf ( "请重新输入!\n\n" ); } } while ((p + _size)->Buy_num > (p + _size)->Max_num); _size++; printf ( "添加航班信息完成!\n\n" ); } else { printf ( "内存已满!\n" ); return ; } } //浏览航班信息 void CheckAirPlane(Plane* p) { int i = 0; printf ( "目前在售的航班信息:\n\n" ); for (i = 0; i < _size; i++) { printf ( "航班编号:%d\n" , i); printf ( "ID:%s\n" , (p+i)->ID); printf ( "始发地:%s\n" , (p + i)->Start_Place); printf ( "目的地:%s\n" , (p + i)->End_Place); printf ( "起飞时间:%s\n" , (p + i)-> time ); printf ( "机票价格:%2f\n" , (p + i)->price); printf ( "剩余机票:%d\n" , ((p + i)->Max_num - (p + i)->Buy_num) ); printf ( "\n" ); } } //删除航班信息 void DelAirPlane(Plane* p) { int j = 0; int i = -1; assert (p); printf ( "请输入要删除的航班编号:" ); scanf ( "%d" , &i); for (j = i; j < _size; j++) { strcpy ((p + j)->ID, (p + j + 1)->ID); strcpy ((p + j)->Start_Place, (p + j + 1)->Start_Place); strcpy ((p + j)->End_Place, (p + j)->End_Place); strcpy ((p + j)-> time , (p + j + 1)-> time ); (p + j)->price = (p + j + 1)->price; (p + j)->Max_num = (p + j + 1)->Max_num; (p + j)->Buy_num = (p + j + 1)->Buy_num; } _size--; } //初始化订票信息 void InitPerson(Person** person) { assert (person); *person = (Person*) malloc ( sizeof (Person)*PERSON_MAXNUM); if (NULL == *person) { printf ( "开辟空间失败!\n" ); return ; } } //订票 void BookAirPlane(Plane* p, Person* person, Person* person_noticket) { int i = -1; CheckAirPlane(p); printf ( "请选择你要预定的航班编号:" ); scanf ( "%d" , &i); if ((p + i)->Max_num == (p + i)->Buy_num) { printf ( "对不起,该航班机票已售完!\n" ); printf ( "请输入您的姓名(我们将把您添加进候补名单):" ); scanf ( "%s" , (person_noticket+_personnoticket_size)->person_name); (person_noticket + _personnoticket_size)->AirPlane_Num = i; _personnoticket_size++; printf ( "添加候补名单成功!\n\n" ); return ; } else { if (_person_size > PERSON_MAXNUM) { printf ( "存储容量不足!\n" ); return ; } printf ( "请输入姓名:" ); scanf ( "%s" , (person + _person_size)->person_name); (person + _person_size)->AirPlane_Num = i; _person_size++; (p + i)->Buy_num++; printf ( "预定成功!\n" ); } } //查看个人订票信息 int CheckPerson(Plane* p, Person* person) { int flag = 0; int i = 0; char _name[20] = { 0 }; printf ( "请输入您的姓名:" ); scanf ( "%s" , &_name); printf ( "您的个人订票信息:\n\n" ); for (i = 0; i < _person_size; i++) { if (0 == strcmp (_name, (person + i)->person_name)) { flag = 1; printf ( "订单编号:%d\n" , i); printf ( "姓名:%s\n" , (person + i)->person_name); printf ( "航班编号:%d\n" , (person + i)->AirPlane_Num); printf ( "航班ID:%s\n" , (p + (person + i)->AirPlane_Num)->ID); printf ( "始发地:%s\n" , (p + (person + i)->AirPlane_Num)->Start_Place); printf ( "目的地:%s\n" , (p + (person + i)->AirPlane_Num)->End_Place); printf ( "起飞时间:%s\n" , (p + (person + i)->AirPlane_Num)-> time ); printf ( "机票价格:%f\n" , (p + (person + i)->AirPlane_Num)->price); printf ( "\n" ); } } if (0 == flag) { printf ( "未找到该乘客订票信息!\n" ); return 0; } return 1; } //改签 void ChangeAirPlane(Plane* p, Person* person) { int i = -1; int j = -1; if (0 == CheckPerson(p, person)) { return ; } printf ( "请输入要改签的订单编号:" ); printf ( "\n" ); scanf ( "%d" , &i); (p + i)->Buy_num--; CheckAirPlane(p); do { printf ( "请输入要改签的航班编号:" ); scanf ( "%d" , &j); if ((p + j)->Buy_num >= (p + j)->Max_num) { printf ( "该次航班已满员,请重新选择!\n" ); } } while ((p + j)->Buy_num >= (p + j)->Max_num); (person + i)->AirPlane_Num = j; (p + j)->Buy_num++; printf ( "改签成功!\n\n" ); } //删除订单 void ReturnTicket(Plane* p, Person* person) { int i = -1; int j = 0; CheckPerson(p, person); printf ( "请输入要删除的订单编号:" ); scanf ( "%d" , &i); for (j = i; j < _person_size; j++) { (person + j)->AirPlane_Num = (person + j + 1)->AirPlane_Num; strcpy ((person + j)->person_name, (person + j + 1)->person_name); } printf ( "退票成功!\n" ); } //查看目前订票信息 void CheckAirPlaneOrder(Plane* p, Person* person) { int i = -1; for (i = 0; i < _size; i++) { printf ( "航班编号:%d\n" , i); printf ( "ID:%s\n" , (p + i)->ID); printf ( "始发地:%s\n" , (p + i)->Start_Place); printf ( "目的地:%s\n" , (p + i)->End_Place); printf ( "起飞时间:%s\n" , (p + i)-> time ); printf ( "机票价格:%2f\n" , (p + i)->price); printf ( "剩余机票:%d\n" , ((p + i)->Max_num - (p + i)->Buy_num)); printf ( "买票人信息:" ); PrintPerson(p,person, i); } } void PrintPerson(Plane* p, Person* person, int i) { int ticket_num = 0; int j = 0; for (j = 0; j < _person_size; j++) { if ((person + j)->AirPlane_Num == i) { printf ( "%s ," , (person + j)->person_name); ticket_num++; } } printf ( "\n\n" ); } //候补名单初始化 void InitPersonNoTicket(Person** person_noticket) { assert (person_noticket); *person_noticket = (Person*) malloc ( sizeof (Person)*PERSONNOTICKET_MAX); if (NULL == *person_noticket) { printf ( "开辟空间失败!\n" ); return ; } } //查看候补名单 void CheckPersonNoTicket(Plane* p, Person* person_noticket) { int i = 0; printf ( "候补名单:\n\n" ); if (0 == _personnoticket_size) { printf ( "候补名单为空!\n\n" ); return ; } for (i = 0; i < _personnoticket_size; i++) { printf ( "姓名:%s\n" , (person_noticket + i)->person_name); printf ( "所需要航班编号:%d\n" , (person_noticket + i)->AirPlane_Num); printf ( "航班ID:%s\n" , (p + ((person_noticket + i)->AirPlane_Num))->ID); printf ( "始发地:%s\n" , ((p + ((person_noticket + i)->AirPlane_Num))->Start_Place)); printf ( "目的地:%s\n" , (p + ((person_noticket + i)->AirPlane_Num))->End_Place); } } //主函数 int main() { Plane* p=NULL; Person* person=NULL; Person* person_noticket = NULL; InitPersonNoTicket(&person_noticket); InitAirPlane(&p); InitPerson(&person); while (1) { home(p, person, person_noticket); } system ( "pause" ); return 0; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/h___q/article/details/81506230