0% found this document useful (0 votes)
17 views7 pages

Case Study2

Uploaded by

Sonia Devi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

Case Study2

Uploaded by

Sonia Devi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Data Structures and Applications (CS204) Case Study 2

A tree is a finite set of


one or more nodes such
that: (i) there is a
specially designated
node called the root;
(ii) the remaining nodes
are partitioned into n 0
disjoint sets T1, ...,Tn
where each of these
sets is a
tree. T1, ...,Tn are called
the subtrees of the root.
Case Studies:
b. Efficiently manage table reservations for a restaurant: Managing table reservations for
a restaurant efficiently involves handling various aspects such as availability of tables,
booking requests, and ensuring a smooth flow of operations.

Explanation

Prof.V.Sonia Devi, Dept. of CSE, CITech 2024-25 Page 1


Data Structures and Applications (CS204) Case Study 2

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

typedef struct table{

int tableNumber;

char reservedBy[NAME_LENGTH];

int isReserved;

} Table;

Table tables[MAX_TABLES];

void initializeTables() {

int i;

for (i = 0; i < MAX_TABLES; i++) {

tables[i].tableNumber = i + 1;

Prof.V.Sonia Devi, Dept. of CSE, CITech 2024-25 Page 2


Data Structures and Applications (CS204) Case Study 2

tables[i].isReserved = 0; // All tables are initially free

void displayTables() {

int i;

printf("Table Number\tReserved By\n");

printf("------------------------------\n");

for (i = 0; i < MAX_TABLES; i++) {

if (tables[i].isReserved) {

printf("%d\t\t%s\n", tables[i].tableNumber, tables[i].reservedBy);

} else {

printf("%d\t\tAvailable\n", tables[i].tableNumber);

void reserveTable() {

int tableNumber;

char name[NAME_LENGTH];

printf("Enter your name: ");

scanf("%s", name);

printf("Enter table number (1-%d): ", MAX_TABLES);

scanf("%d", &tableNumber);

if (tableNumber < 1 || tableNumber > MAX_TABLES) {

printf("Invalid table number. Please try again.\n");

return;

if (tables[tableNumber - 1].isReserved) {

Prof.V.Sonia Devi, Dept. of CSE, CITech 2024-25 Page 3


Data Structures and Applications (CS204) Case Study 2

printf("Table %d is already reserved by %s.\n", tableNumber, tables[tableNumber -


1].reservedBy);

} else {

tables[tableNumber - 1].isReserved = 1;

strncpy(tables[tableNumber - 1].reservedBy, name, NAME_LENGTH);

printf("Table %d successfully reserved for %s.\n", tableNumber, name);

void cancelReservation() {

int tableNumber;

printf("Enter table number to cancel reservation (1-%d): ", MAX_TABLES);

scanf("%d", &tableNumber);

if (tableNumber < 1 || tableNumber > MAX_TABLES) {

printf("Invalid table number. Please try again.\n");

return;

if (!tables[tableNumber - 1].isReserved) {

printf("Table %d is not reserved.\n", tableNumber);

} else {

tables[tableNumber - 1].isReserved = 0;

printf("Reservation for table %d has been canceled.\n", tableNumber);

int main() {

int choice;

initializeTables();

Prof.V.Sonia Devi, Dept. of CSE, CITech 2024-25 Page 4


Data Structures and Applications (CS204) Case Study 2

do {

printf("\nRestaurant Reservation System\n");

printf("1. Display Tables\n");

printf("2. Reserve Table\n");

printf("3. Cancel Reservation\n");

printf("4. Exit\n");

printf("Choose an option: ");

scanf("%d", &choice);

switch (choice) {

case 1:

displayTables();

break;

case 2:

reserveTable();

break;

case 3:

cancelReservation();

break;

case 4:

printf("Exiting the system. Thank you!\n");

break;

default:

printf("Invalid choice. Please try again.\n");

} while (choice != 4);

return 0;

Prof.V.Sonia Devi, Dept. of CSE, CITech 2024-25 Page 5


Data Structures and Applications (CS204) Case Study 2

Output

Prof.V.Sonia Devi, Dept. of CSE, CITech 2024-25 Page 6


Data Structures and Applications (CS204) Case Study 2

Prof.V.Sonia Devi, Dept. of CSE, CITech 2024-25 Page 7

You might also like