You are on page 1of 12

#include <stdio.

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

HAS BEEN OCCUPIED! **\n");


}
}
}
}
else if (dcs == 2)
{
do
{
printf("Which room do you want to book (1-3)? ")
;
scanf("%d", &booking);
}
while (booking < 1 || booking > 3);
for (i = 0; i < 3; i++)
{
if (booking == private_room[i] && ava_room[i] ==
'*')
{
ava_room[i] = 'X';
Customer_Room();
system("cls");

printf("\n\t\t\t** RESERVATION SUCCESSFU


L! **\n");
printf("\t\t** Your reservation has been
marked with X **\n");
}
else if (booking == private_room[i] && ava_room[
i] == 'X')
{
printf("\n\t\t

** THIS ROOM HAS BEEN

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,

"Table %d,\t", booking);


"%s,\t", a[booking-1].firstname);
"%s,\t", a[booking-1].lastname);
"%d,\t", a[booking-1].pax);
"%s,\t\t", a[booking-1].email);
"%s,\t\n", a[booking-1].contactnum);

fclose(file);
}
void Customer_Room()
{
file = fopen("CustomerData.txt", "a+");

printf("\nPlease enter your First Name\t\t: ");


scanf("%s", b[booking-1].firstname);
printf("Please enter your Last Name\t\t: ");
scanf("%s", b[booking-1].lastname);
do
{
printf("Please enter pax\t\t\t: ");
scanf("%d", &b[booking-1].pax);
if (b[booking-1].pax < 1)
{
printf("\n\t\t** INVALID NUMBER **\n\n");
}
else if (b[booking-1].pax > 10)
{
printf("\n\t\t** WE APOLOGIZE **\n");
printf("** A ROOM COULD ONLY ACCOMODATE UP TO 10 PEOPLE
**\n\n");
}
}
while (b[booking-1].pax < 1 || b[booking-1].pax > 10);
printf("Please enter your e-mail address\t: ");
scanf("%s", b[booking-1].email);
printf("Please enter your contact number\t: ");
scanf("%s", b[booking-1].contactnum);
fprintf(file,
fprintf(file,
fprintf(file,
fprintf(file,
fprintf(file,
fprintf(file,

"Room %d,\t\t", booking);


"%s,\t", b[booking-1].firstname);
"%s,\t", b[booking-1].lastname);
"%d,\t", b[booking-1].pax);
"%s,\t\t", b[booking-1].email);
"%s,\t\n", b[booking-1].contactnum);

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 (strcmp(firstnm, b[booking-1].firstname) == 0 && strc


mp(lastnm, b[booking-1].lastname) == 0)
{
printf("\nPlease update your e-mail address: ");
scanf("%s", b[booking-1].email);
printf("Please update your contact number: ");
scanf("%s", b[booking-1].contactnum);
printf("\n\t** UPDATE SUCCESSFUL **\n\n");
}
else
{
printf("\n\t** YOUR NAME DOES NOT MATCH! **\n\n"
);
}
}
}
while (dcs < 1 || dcs > 2);
printf("Press 1 to back to Continue or 2 to back to Menu: ");
scanf("%d", &option);

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:

printf("\nPress 1 to Continue or 2 to back to Menu: ");


scanf("%d", &option);
if (option == 1)
{
Search();
}
else if (option == 2)
{
Menu();
}
else
{
Menu();
}
}
void Cancel()
{
int rsv;
system("cls");
printf("********************************** CANCEL ********************
***************\n\n");
do
{
printf("What is your reservation (1 = Table, 2 = Room)? ");
scanf("%d", &rsv);
printf("\n");
if (rsv == 1)
{
do
{
printf("Which table have you booked (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("\nAre you sure to cancel this reservatio
n (1 for YES and 2 for NO)? ");
scanf("%d", &dcs);
// read dcs
if (dcs == 1)
{
for (i = 0; i < 5; i++)
{
for (j = 0; j < 4; j++)
{
if (booking == table[i][

j] && ava_table[i][j] == 'X')


{
ava_table[i][j]
= '*';
strcpy(a[booking
-1].firstname, "-FIRST-");
strcpy(a[booking
-1].lastname, "-LAST-");
strcpy(a[booking
-1].email, "-------- NULL --------");
strcpy(a[booking
-1].contactnum, "-- NULL --");
a[booking-1].pax
= 0;
printf("\n\t** Y
OUR RESERVATION HAS BEEN CANCELED **\n\n");
}
}
}
}
else if (dcs == 2)
{
goto AskCancel;
}
}
else
{
printf("\n\t** YOUR NAME DOES NOT MATCH! **\n\n"
);
}
}
else if (rsv == 2)
{
do
{
printf("Which room have you booked (1-3)? ");
scanf("%d", &booking);
}
while (booking < 1 || booking > 3);
AskName();
if (strcmp(firstnm, b[booking-1].firstname) == 0 && strc
mp(lastnm, b[booking-1].lastname) == 0)
{
printf("\nAre you sure to cancel this reservatio
n (1 for YES and 2 for NO)? ");
scanf("%d", &dcs);
// read dcs
if (dcs == 1)
{
for (i = 0; i < 3; i++)
{
if (booking == private_room[i] &

& ava_room[i] == 'X')


{
ava_room[i] = '*';
strcpy(b[booking-1].firs
tname, "-FIRST-");
strcpy(b[booking-1].last
name, "-LAST-");
strcpy(b[booking-1].emai
l, "-------- NULL --------");
strcpy(b[booking-1].cont
actnum, "-- NULL --");
b[booking-1].pax = 0;
printf("\n\t** YOUR RESE
RVATION HAS BEEN CANCELED **\n\n");
}
}
}
else if (dcs == 2)
{
goto AskCancel;
}
}
else
{
printf("\n\t** YOUR NAME DOES NOT MATCH! **\n\n"
);
}
}
}
while (rsv < 1 || rsv > 2);
AskCancel:
printf("\nPress 1 to Continue or 2 to back to Menu: "); // prompt user's
choice
scanf("%d", &option);
if (option == 1)
{
Cancel();
}

// function call

else if (option == 2)
{
Menu();
}

// function call

else
{
Menu();
}
}
void AskName()
{

// function call

printf("\nEnter your First Name\t: ");


scanf("%s", firstnm);
printf("Enter your Last Name\t: ");
scanf("%s", lastnm);
}

You might also like