Professional Documents
Culture Documents
Reservation
Reservation
h>
#include <string.h>
#include <stdlib.h>
void
void
void
void
void
void
void
void
AddReservation();
Customer_Table();
Customer_Room();
Update();
Search();
Cancel();
AskName();
DefaultData();
int i, j;
int option, booking, dcs;
char firstnm[10], lastnm[10];
FILE *file;
static char ava_table[5][4] = {{'*', '*', '*', '*'},
{'*', '*', '*', '*'},
{'*', '*', '*', '*'},
{'*', '*', '*', '*'},
{'*', '*', '*', '*'}}
;
static int table[5][4] = {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16},
{17, 18, 19, 20}};
static char ava_room[3] = {'*', '*', '*'};
static int private_room[3] = {1, 2, 3};
struct CustomerData
{
char firstname[8],
lastname[8],
email[30],
contactnum[13];
int pax;
} a[20], b[3];
void AddReservation()
{
system("cls");
printf("****************************** ADD RESERVATION ***************
***************\n\n");
do
{
printf("What do you want to book (1 for Table, 2 for Room)? ");
scanf("%d", &dcs);
printf("\n");
if (dcs == 1)
{
do
{
printf("Which table do you want to book (1-20)?
");
scanf("%d", &booking);
}
while (booking < 1 || booking > 20);
for (i = 0; i < 5; i++)
{
for (j = 0; j < 4; j++)
{
if (booking == table[i][j] && ava_table[
i][j] == '*')
{
ava_table[i][j] = 'X';
Customer_Table();
system("cls");
printf("\n\t\t\t** RESERVATION S
UCCESSFUL! **\n");
printf("\t\t** Your reservation
has been marked with X **\n");
}
else if (booking == table[i][j] && ava_t
able[i][j] == 'X')
{
printf("\n\t\t
** THIS TABLE
OCCUPIED! **\n");
}
}
}
}
while (dcs < 1 || dcs > 2);
printf("\t------------------------------------------------------------\n
");
for (i = 0; i < 5; i++)
{
for (j = 0; j < 4; j++)
{
printf("\tTable %d ", table[i][j]);
if (table[i][j] < 10)
{
printf(" ");
}
printf("[%c]", ava_table[i][j]);
}
printf("\n");
}
printf("\t------------------------------------------------------------\n
");
for (i = 0; i < 3; i++)
{
printf("\tPrivate Room %d\t[%c]\n", private_room[i], ava_room[i]
);
}
printf("\t------------------------------------------------------------\n
");
printf("\t[*] -- Available\n");
printf("\t[X] -- Occupied\n");
printf("\t------------------------------------------------------------\n
\n");
printf("Press 1 to Continue or 2 to back to Menu: ");
scanf("%d", &option);
if (option == 1)
{
AddReservation();
}
else if (option == 2)
{
Menu();
}
else
{
Menu();
}
}
void Customer_Table()
{
file = fopen("CustomerData.txt", "a+");
printf("\nPlease enter your First Name\t\t: ");
scanf("%s", a[booking-1].firstname);
printf("Please enter your Last Name\t\t: ");
scanf("%s", a[booking-1].lastname);
do
{
printf("Please enter pax\t\t\t: ");
scanf("%d", &a[booking-1].pax);
if (a[booking-1].pax < 1)
{
printf("\n\t\t** INVALID NUMBER **\n\n");
}
else if (a[booking-1].pax > 5)
{
printf("\n\t\t** WE APOLOGIZE **\n");
printf("** A TABLE COULD ONLY ACCOMODATE UP TO 5 PEOPLE
**\n\n");
}
}
while (a[booking-1].pax < 1 || a[booking-1].pax > 5);
printf("Please enter your e-mail address\t: ");
scanf("%s", a[booking-1].email);
printf("Please enter your contact number\t: ");
scanf("%s", a[booking-1].contactnum);
fprintf(file,
fprintf(file,
fprintf(file,
fprintf(file,
fprintf(file,
fprintf(file,
fclose(file);
}
void Customer_Room()
{
file = fopen("CustomerData.txt", "a+");
fclose(file);
}
void Update()
{
system("cls");
printf("********************************** UPDATE ********************
***************\n\n");
do
{
printf("Press 1 for Table or 2 for Room: ");
scanf("%d", &dcs);
printf("\n");
if (dcs == 1)
{
do
{
printf("Enter your table number (1-20): ");
scanf("%d", &booking);
}
while (booking < 1 || booking > 20);
AskName();
if (strcmp(firstnm, a[booking-1].firstname) == 0 && strc
mp(lastnm, a[booking-1].lastname) == 0)
{
printf("\nPlease update your e-mail address: ");
scanf("%s", a[booking-1].email);
printf("Please update your contact number: ");
scanf("%s", a[booking-1].contactnum);
printf("\n\t** UPDATE SUCCESSFUL **\n\n");
}
else
{
printf("\n\t** YOUR NAME DOES NOT MATCH! **\n\n"
);
// notification
}
}
else if (dcs == 2)
{
do
{
printf("Enter your room number (1-3): ");
scanf("%d", &booking);
}
while (booking < 1 || booking > 20);
AskName();
if (option == 1)
{
Update();
}
else if (option == 2)
{
Menu();
}
else
{
Menu();
}
}
void Search()
{
system("cls");
printf("********************************** SEARCH ********************
***************\n\n");
do
{
printf("What do you want to search (1 = Table, 2 = Room)? ");
scanf("%d", &dcs);
printf("\n");
if (dcs == 1)
{
do
{
printf("Which table do you want to search (1-20)
? ");
scanf("%d", &booking);
}
while (booking < 1 || booking > 20);
for (i = 0; i < 5; i++)
{
for (j = 0; j < 4; j++)
{
if (booking == table[i][j] && ava_table[
i][j] == '*')
{
printf("\n\t** THIS TABLE IS AVA
ILABLE! **\n\n");
printf("Do you want to add reser
vation (1 for YES or 2 for NO)? ");
scanf("%d", &option);
// read option
if (option == 1)
{
AddReservation();
}
else if (option == 2)
{
goto AskSearch;
}
}
else if (booking == table[i][j] && ava_t
able[i][j] == 'X')
{
printf("\n\t** THIS TABLE HAS BE
EN OCCUPIED! **\n");
}
}
}
}
else if (dcs == 2)
{
do
{
printf("Which room do you want to search (1-3)?
");
scanf("%d", &booking);
}
while (booking < 1 || booking > 3);
for (i = 0; i < 3; i++)
{
if (booking == private_room[i] && ava_room[i] ==
'*')
{
printf("\n\t** THIS ROOM IS AVAILABLE! *
*\n\n");
printf("Do you want to add reservation (
1 for YES or 2 for NO)? ");
scanf("%d", &option);
if (option == 1)
{
AddReservation();
}
else if (option == 2)
{
goto AskSearch;
}
}
else if (booking == private_room[i] && ava_room[
i] == 'X')
{
printf("\n\t** THIS ROOM HAS BEEN OCCUPI
ED! **\n");
}
}
}
}
while (dcs < 1 || dcs > 2);
AskSearch:
// function call
else if (option == 2)
{
Menu();
}
// function call
else
{
Menu();
}
}
void AskName()
{
// function call