Case Study2
Case Study2
Explanation
1. Data Structure:
o The Table structure holds information about each table, including its number,
the name of the person who reserved it, and whether it is reserved.
2. Initialization:
o The initializeTables function sets up all tables as available.
3. Display Tables:
o The displayTables function shows the status of each table.
4. Reserve Table:
o The reserveTable function allows users to reserve a table, checking if it's
already reserved and updating the reservation status accordingly.
5. Cancel Reservation:
o The cancelReservation function lets users cancel a reservation and updates
the status of the table.
6. User Interface:
o The main function provides a simple text-based menu for users to interact with
the system.
Program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_TABLES 10
#define NAME_LENGTH 50
int tableNumber;
char reservedBy[NAME_LENGTH];
int isReserved;
} Table;
Table tables[MAX_TABLES];
void initializeTables() {
int i;
tables[i].tableNumber = i + 1;
void displayTables() {
int i;
printf("------------------------------\n");
if (tables[i].isReserved) {
} else {
printf("%d\t\tAvailable\n", tables[i].tableNumber);
void reserveTable() {
int tableNumber;
char name[NAME_LENGTH];
scanf("%s", name);
scanf("%d", &tableNumber);
return;
if (tables[tableNumber - 1].isReserved) {
} else {
tables[tableNumber - 1].isReserved = 1;
void cancelReservation() {
int tableNumber;
scanf("%d", &tableNumber);
return;
if (!tables[tableNumber - 1].isReserved) {
} else {
tables[tableNumber - 1].isReserved = 0;
int main() {
int choice;
initializeTables();
do {
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
displayTables();
break;
case 2:
reserveTable();
break;
case 3:
cancelReservation();
break;
case 4:
break;
default:
return 0;
Output