-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAirline Reservation System.c
205 lines (178 loc) · 4.3 KB
/
Airline Reservation System.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
/*Team members : Sathwik
Shraddesh
Sana
Sahil
*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<Windows.h>
struct airline
{
char passport[6];
char name[15];
char destination[15];
int seat_num;
char email[15];
struct airline *following;
}
*begin, *stream;
struct airline *dummy;
void main()
{
void reserve(int x), cancel(), display(), savefile();
int choice;
begin = stream = NULL;
int num = 1;
do
{
printf("\n\n\t*******************************************************************");
printf("\n\t AIRLINE RESERVATION SYSTEM ");
printf("\n\t*******************************************************************");
printf("\n\n\n\t\t Please enter your choice from below (1-4):");
printf("\n\n\t\t 1. Reservation");
printf("\n\n\t\t 2. Cancel");
printf("\n\n\t\t 3. Records");
printf("\n\n\t\t 4. EXIT");
printf("\n\n\t\t Enter your choice :");
scanf("%d", &choice); fflush(stdin);
system("cls");
switch (choice)
{
case 1:
reserve(num);
num++;
break;
case 2:
cancel();
break;
case 3:
display();
break;
case 4:
{
savefile();
break;
}
default:
printf("\n\n\t SORRY INVALID CHOICE!");
printf("\n\n\t PLEASE CHOOSE FROM 1-4");
printf("\n\n\t Do not forget to chose from 1-4");
}
getch();
} while (choice != 4);
}
void details()
{
printf("\n\t Enter your passport number:");
gets(stream->passport); fflush(stdin);
printf("\n\t Enter your name:");
gets(stream->name); fflush(stdin);
printf("\n\t Enter your email address:");
gets(stream->email); fflush(stdin);
printf("\n\t Enter the Destination : ");
gets(stream->destination); fflush(stdin);
}
void details();
void reserve(int x)
{
stream = begin;
if (begin == NULL)
{
// first user
begin = stream = (struct airline*)malloc(sizeof(struct airline));
details();
stream->following = NULL;
printf("\n\t Seat booking successful!");
printf("\n\t your seat number is: Seat A-%d", x);
stream->seat_num = x;
return;
}
else if (x > 15) // FULL SEATS
{
printf("\n\t\t Seat Full.");
return;
}
else
{
while (stream->following)
stream = stream->following;
stream->following = (struct airline *)malloc(sizeof(struct airline));
stream = stream->following;
details();
stream->following = NULL;
printf("\n\t Seat booking succesful!");
printf("\n\t your seat number is: Seat A-%d", x);
stream->seat_num = x;
return;
}
}
void savefile()
{
FILE *fpointer = fopen("air_records", "w");
if (!fpointer)
{
printf("\n Error in opening file!");
return;
Sleep(800);
}
stream = begin;
while (stream)
{
fprintf(fpointer, "%-6s", stream->passport);
fprintf(fpointer, "%-15s", stream->name);
fprintf(fpointer, "%-15s", stream->email);
fprintf(fpointer, "%-15s", stream->destination);
fprintf(fpointer, "\n");
stream = stream->following;
}
printf("\n\n\t Details have been saved to a file");
fclose(fpointer);
}
void display()
{
stream = begin;
while (stream)
{
printf("\n\n Passport Number : %-6s", stream->passport);
printf("\n name : %-15s", stream->name);
printf("\n email address: %-15s", stream->email);
printf("\n Seat number: A-%d", stream->seat_num);
printf("\n Destination:%-15s", stream->destination);
printf("\n\n++*=====================================================*++");
stream = stream->following;
}
}
void cancel()
{
stream = begin;
system("cls");
char passport[6];
printf("\n\n Enter passort number to delete record?:");
gets(passport); fflush(stdin);
if (strcmp(begin->passport, passport) == 0)
{
dummy = begin;
begin = begin->following;
free(dummy);
printf(" booking has been deleted");
Sleep(800);
return;
}
while (stream->following)
{
if (strcmp(stream->following->passport, passport) == 0)
{
dummy = stream->following;
stream->following = stream->following->following;
free(dummy);
printf("has been deleted ");
getch();
Sleep(800);
return;
}
stream = stream->following;
}
printf("passport number is wrong please check your passport");
}