-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.c
214 lines (195 loc) · 5.8 KB
/
Main.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int max = 0;
int seat = 0;
struct node
{
char name[100];
char passport_number[10];
char Email[100];
int seat_number;
struct node *next;
};
struct node *insert(struct node *head, char *name, char *pass, char *email)
{
struct node *new = (struct node *)malloc(sizeof(struct node));
struct node *temp = NULL;
strcpy(new->name, name);
strcpy(new->passport_number, pass);
strcpy(new->Email, email);
new->seat_number = ++seat;
if (head == NULL)
{
new->next = NULL;
head = new;
}
else
{
temp = head;
while (temp->next != NULL)
{
temp = temp->next;
}
new->next = temp->next;
temp->next = new;
}
max++;
printf("\n\t\t\tYOUR RESERVATION IS SUCCESSFUL.\n");
return head;
}
struct node *RESERVATION(struct node *head)
{
char name[100];
char pass[10];
char email[100];
printf("\n\t\t\tWELCOME TO THE RESERVTION SYSTEM ~~\n\n");
fflush(stdin);
printf("\n\t\t\tPLEASE ENTER YOUR NAME : ");
gets(name);
printf("\n\t\t\tPLEASE ENTER YOUR PASS-PORT NUMBER : ");
gets(pass);
fflush(stdin);
printf("\n\t\t\tPLEASE ENTER YOUR E-MAIL : ");
gets(email);
fflush(stdin);
if (max <= 40)
{
head = insert(head, name, pass, email);
return head;
}
else
{
printf("\t\t\tYOU HAVE REACHED THE MAX LIMIT OF PASSENGERS . SORRY FOR THE INCONVENIENCE .\n");
return head;
}
}
void PRINT(struct node *head)
{
struct node *ptr = NULL;
ptr = head;
if (ptr == NULL)
{
printf("\n\t\t\tTHERE IS NOT A SINGLE ENTRY .\n");
}
else
{
while (ptr)
{
printf("\n\t\t\tNAME : %s\n", ptr->name);
printf("\t\t\tPASSPORT NUMBER : %s\n", ptr->passport_number);
printf("\t\t\tE-MAIL : %s\n", ptr->Email);
printf("\t\t\tSEAT NUMBER : 2A-%d\n", ptr->seat_number);
ptr = ptr->next;
}
}
}
void CANCEL(struct node *head)
{
struct node *temp = head;
struct node *ptr = NULL;
if (temp == NULL)
{
printf("\n\t\t\tTHERE ARE NO RESERVATIONS .\n");
return;
}
printf("\n\t\t\tPLEASE ENTER THE PASSSPORT-NUMBER OF THE PASSENGER YOU WANT TO CANCEL : ");
char pass[10];
fflush(stdin);
gets(pass);
if (strcmp(temp->passport_number, pass) == 0 && temp == head)
{
ptr = head;
temp = temp->next;
head = temp;
ptr->next = NULL;
free(ptr);
printf("\n\t\t\tBOOKING HAS BEEN CANCELED\n");
max--;
return;
}
while (temp->next)
{
if (strcmp(temp->next->passport_number, pass) == 0)
{
ptr = temp->next;
temp->next = temp->next->next;
free(ptr);
printf("\n\t\t\tBOOKING HAS BEEN DELETED .\n");
max--;
return;
}
temp = temp->next;
}
printf("\n\t\t\tERROR ! YOU HAVE ENTERED THE WRONG PASSPORT NUMBER .\n");
}
void SAVEFILE(struct node *head)
{
FILE *fpointer = fopen("AIRLINE RESERVATION", "w");
if (!fpointer)
{
printf("\t\t\tTHERE IS AN ERROR IN OPENING THE FILE .\n");
return;
}
fprintf(fpointer, "\t\tPASSPORT NUMBER\t\t\tNAME\t\t\t\t\tE-MAIL\n\n\n");
struct node *temp = head;
while (temp)
{
fprintf(fpointer, "\t\t%s\t\t", temp->passport_number);
fprintf(fpointer, "\t\t%s\t\t", temp->name);
fprintf(fpointer, "\t\t%s\t\t", temp->Email);
fprintf(fpointer, "\n");
temp = temp->next;
}
printf("\n\n\t\t\tTHE DETAILS HAVE BEEN SAVED IN FILE(AIRLINE RESERVATION).\n");
fclose(fpointer);
}
void SHOW_NUMBER_OF_PASSENGERS()
{
printf("\n\t\t\tTHE TOTAL NUMBER OF RESERVATIONS ARE %d .\n\t\t\tTHERE ARE %d RESERVATIONS LEFT .\n", max, (40 - max));
}
int main()
{
printf("\t\t\t\t\t\t|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n");
printf("\t\t\t\t\t\t|_________________________________________________________________|\n");
printf("\t\t\t\t\t\t| WELCOME TO THE AIRLINE RESERVATION SYSTEM . |\n");
printf("\t\t\t\t\t\t|_________________________________________________________________|\n");
printf("\t\t\t\t\t\t|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n");
struct node *head = (struct node *)malloc(sizeof(struct node));
head = NULL;
int choice;
do
{
printf("\t\t\t\t\t\t _________________________________________________________________ \n");
printf("\t\t\t\t\t\t| 1. RESERVATION |\n");
printf("\t\t\t\t\t\t| 2. CANCEL RESERVATION. |\n");
printf("\t\t\t\t\t\t| 3. PRINT ALL THE PASSENGER RESERVATIONS. |\n");
printf("\t\t\t\t\t\t| 4. SHOW THE NUMBER OF RESERVATIONS. |\n");
printf("\t\t\t\t\t\t| 5. EXIT. |\n");
printf("\t\t\t\t\t\t|_________________________________________________________________|\n");
printf("\n\t\t\t\t\t\tPLEASE ENTER YOUR CHOICE : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
head = RESERVATION(head);
break;
case 2:
CANCEL(head);
break;
case 3:
PRINT(head);
break;
case 4:
SHOW_NUMBER_OF_PASSENGERS();
break;
case 5:
SAVEFILE(head);
break;
default:
printf("\n\t\t\tYOU HAVE ENTERED THE WRONG OPTION .\n");
break;
}
} while (choice != 5);
return 0;
}