CS 231 – Data structures – Implement a C++ program for a RESTAURANT that has multiple branches, and each branch has menus of food items, their stock and a list of customers.
C++ RESTAURANT program
A branch may have for example a breakfast menu and lunch menu with different food items, and the stock (available quantity) of each food item in the branch. Also, the branch will have a list of regular customers and their contact information to contact them for offers and new food items. Class Names Data and Member Functions
1. Food Data Members: ID, Name, Calories, Price Member Functions: getID, getName, getCalories, getPrice setID, setName, setCalories, setPrice
2. Stock Data Members: ID, Food, Stock Member Functions: getID, getFood, getStock setID, setFood, setStock
3. Customer Data Members: ID, Name, Phone Member Functions: getID, getName, getPhone setID, setName, setPhoe
4. Menu Data Members: ID, Name, foodList Member Functions: getID, getName, getFoodList setID, setName
5. Branch Data Members: ID, Address, menuList, stockList, customerList Member Functions: getID, getAddress, getMenuList, getStockList, getCustomerList setID, setAddress
After developing these classes, the following three parts of the project must be implemented:
Part1: Create the following Linked Lists:
1. foodList must store Food objects.
2. stockList that stores Stock objects.
3. customerList to store Customer objects.
4. menuList to store Menu objects.
5. RESTAURANT has branchList to store a Linked list of Branch objects with their menuList, stockList and customerList.
The main function to test the above classes and data structures must display the following menu to the user:
Main Menu:
1. Branches
2. Food Items
3. Menus
4. Customers
The Submenu under each item of the Main Menu must have the following operations:
a. Display
b. Insert
c. Delete
d. Modify
e. Find
Part 2: Covert the above lists in part 1 into Stack.
Part 3: Covert the above lists in part 1 into Queue
C++ RESTAURANT program
ALGORITHM:
Program RestaurantManagementSystem
Define a list of Branches
Define a list of FoodItems
Define a list of Customers
Main Menu Loop
Display “Main Menu”
Display “1. Branches”
Display “2. Food Items”
Display “3. Customers”
Display “4. Exit”
Input UserChoice
If UserChoice is 1 Then
Branch Menu Loop
Display “Branch Operations”
Display “1. Display”
Display “2. Insert”
Display “3. Back to Main Menu”
Input BranchChoice
If BranchChoice is 1 Then
Call DisplayBranches()
ElseIf BranchChoice is 2 Then
Call AddBranch()
EndIf
ElseIf UserChoice is 2 Then
Food Item Menu Loop
Display “Food Item Operations”
Display “1. Display”
Display “2. Insert”
Display “3. Back to Main Menu”
Input FoodChoice
If FoodChoice is 1 Then
Call DisplayFoodItems()
ElseIf FoodChoice is 2 Then
Call AddFoodItem()
EndIf
ElseIf UserChoice is 3 Then
Customer Menu Loop
Display “Customer Operations”
Display “1. Display”
Display “2. Insert”
Display “3. Back to Main Menu”
Input CustomerChoice
If CustomerChoice is 1 Then
Call DisplayCustomers()
ElseIf CustomerChoice is 2 Then
Call AddCustomer()
EndIf
ElseIf UserChoice is 4 Then
Exit Program
EndIf
End Main Menu Loop
Function DisplayBranches()
If Branches list is empty Then
Display “No branches available.”
Else
For each Branch in Branches list
Display “Branch ID: “, Branch.ID, “, Address: “, Branch.Address
EndFor
EndIf
EndFunction
Function AddBranch()
Input BranchID
Input BranchAddress
Add new Branch to Branches list with BranchID and BranchAddress
Display “Branch added successfully.”
EndFunction
Function DisplayFoodItems()
If FoodItems list is empty Then
Display “No food items available.”
Else
For each FoodItem in FoodItems list
Display “Food ID: “, FoodItem.ID, “, Name: “, FoodItem.Name, “, Calories: “, FoodItem.Calories, “, Price: $”, FoodItem.Price
EndFor
EndIf
EndFunction
Function AddFoodItem()
Input FoodID
Input FoodName
Input FoodCalories
Input FoodPrice
Add new FoodItem to FoodItems list with FoodID, FoodName, FoodCalories, and FoodPrice
Display “Food item added successfully.”
EndFunction
Function DisplayCustomers()
If Customers list is empty Then
Display “No customers available.”
Else
For each Customer in Customers list
Display “Customer ID: “, Customer.ID, “, Name: “, Customer.Name, “, Phone: “, Customer.Phone
EndFor
EndIf
EndFunction
Function AddCustomer()
Input CustomerID
Input CustomerName
Input CustomerPhone
Add new Customer to Customers list with CustomerID, CustomerName, and CustomerPhone
Display “Customer added successfully.”
EndFunction
CODE:
#include <iostream>
#include <string>
class Food {
private:
int ID;
std::string Name;
int Calories;
double Price;
public:
Food(int id, std::string name, int calories, double price) : ID(id), Name(name), Calories(calories), Price(price) {}
int getID() const { return ID; }
std::string getName() const { return Name; }
int getCalories() const { return Calories; }
double getPrice() const { return Price; }
Food* next;
};
class Customer {
private:
int ID;
std::string Name;
std::string Phone;
public:
Customer(int id, std::string name, std::string phone) : ID(id), Name(name), Phone(phone) {}
int getID() const { return ID; }
std::string getName() const { return Name; }
std::string getPhone() const { return Phone; }
Customer* next;
};
class Branch {
private:
int ID;
std::string Address;
public:
Branch(int id, std::string address) : ID(id), Address(address) {}
int getID() const { return ID; }
std::string getAddress() const { return Address; }
Branch* next;
};
// Function Prototypes
void displayBranches(const Branch* branches);
void addBranch(Branch*& branches);
void displayFoodItems(const Food* foodItems);
void addFoodItem(Food*& foodItems);
void displayCustomers(const Customer* customers);
void addCustomer(Customer*& customers);
int main() {
Branch* branches = nullptr;
Food* foodItems = nullptr;
Customer* customers = nullptr;
int mainChoice;
do {
std::cout << “\nMain Menu:\n”
<< “1. Branches\n”
<< “2. Food Items\n”
<< “3. Customers\n”
<< “4. Exit\n”
<< “Enter your choice: “;
std::cin >> mainChoice;
switch (mainChoice) {
case 1:
int branchChoice;
std::cout << “Branch Operations:\n”
<< “1. Display\n”
<< “2. Insert\n”
<< “3. Back to Main Menu\n”
<< “Enter your choice: “;
std::cin >> branchChoice;
if (branchChoice == 1) displayBranches(branches);
else if (branchChoice == 2) addBranch(branches);
break;
case 2:
int foodChoice;
std::cout << “Food Item Operations:\n”
<< “1. Display\n”
<< “2. Insert\n”
<< “3. Back to Main Menu\n”
<< “Enter your choice: “;
std::cin >> foodChoice;
if (foodChoice == 1) displayFoodItems(foodItems);
else if (foodChoice == 2) addFoodItem(foodItems);
break;
case 3:
int customerChoice;
std::cout << “Customer Operations:\n”
<< “1. Display\n”
<< “2. Insert\n”
<< “3. Back to Main Menu\n”
<< “Enter your choice: “;
std::cin >> customerChoice;
if (customerChoice == 1) displayCustomers(customers);
else if (customerChoice == 2) addCustomer(customers);
break;
case 4:
std::cout << “Exiting program.\n”;
break;
default:
std::cout << “Invalid choice, try again.\n”;
break;
}
} while (mainChoice != 4);
return 0;
}
void displayBranches(const Branch* branches) {
if (branches == nullptr) {
std::cout << “No branches available.\n”;
return;
}
const Branch* current = branches;
while (current != nullptr) {
std::cout << “Branch ID: ” << current->getID() << “, Address: ” << current->getAddress() << std::endl;
current = current->next;
}
}
void addBranch(Branch*& branches) {
int id;
std::string address;
std::cout << “Enter Branch ID: “;
std::cin >> id;
std::cin.ignore();
std::cout << “Enter Branch Address: “;
getline(std::cin, address);
Branch* newBranch = new Branch(id, address);
newBranch->next = nullptr;
if (branches == nullptr) {
branches = newBranch;
} else {
Branch* current = branches;
while (current->next !=nullptr) {
current = current->next;
}
current->next = newBranch;
}
std::cout << “Branch added successfully.\n”;
}
void displayFoodItems(const Food* foodItems) {
if (foodItems == nullptr) {
std::cout << “No food items available.\n”;
return;
}
const Food* current = foodItems;
while (current != nullptr) {
std::cout << “Food ID: ” << current->getID() << “, Name: ” << current->getName() << “, Calories: ” << current->getCalories() << “, Price: ” << current->getPrice() << std::endl;
current = current->next;
}
}
void addFoodItem(Food*& foodItems) {
int id, calories;
double price;
std::string name;
std::cout << “Enter Food ID: “;
std::cin >> id;
std::cin.ignore();
std::cout << “Enter Food Name: “;
getline(std::cin, name);
std::cout << “Enter Food Calories: “;
std::cin >> calories;
std::cout << “Enter Food Price: “;
std::cin >> price;
Food* newFoodItem = new Food(id, name, calories, price);
newFoodItem->next = nullptr;
if (foodItems == nullptr) {
foodItems = newFoodItem;
} else {
Food* current = foodItems;
while (current->next != nullptr) {
current = current->next;
}
current->next = newFoodItem;
}
std::cout << “Food item added successfully.\n”;
}
void displayCustomers(const Customer* customers) {
if (customers == nullptr) {
std::cout << “No customers available.\n”;
return;
}
const Customer* current = customers;
while (current != nullptr) {
std::cout << “Customer ID: ” << current->getID() << “, Name: ” << current->getName() << “, Phone: ” << current->getPhone() << std::endl;
current = current->next;
}
}
void addCustomer(Customer*& customers) {
int id;
std::string name, phone;
std::cout << “Enter Customer ID: “;
std::cin >> id;
std::cin.ignore();
std::cout << “Enter Customer Name: “;
getline(std::cin, name);
std::cout << “Enter Customer Phone: “;
getline(std::cin, phone);
Customer* newCustomer = new Customer(id, name, phone);
newCustomer->next = nullptr;
if (customers == nullptr) {
customers = newCustomer;
} else {
Customer* current = customers;
while (current->next != nullptr) {
current = current->next;
}
current->next = newCustomer;
}
std::cout << “Customer added successfully.\n”;
}