0% found this document useful (0 votes)
12 views10 pages

Restaurant

The document is a C++ program for a Restaurant Management System that allows users to manage a food menu and customer orders. It includes functionalities for inserting, displaying, and deleting food items and orders, as well as sorting the menu by price. The program utilizes a queue structure to handle orders in a first-in-first-out manner.

Uploaded by

netsanet580
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)
12 views10 pages

Restaurant

The document is a C++ program for a Restaurant Management System that allows users to manage a food menu and customer orders. It includes functionalities for inserting, displaying, and deleting food items and orders, as well as sorting the menu by price. The program utilizes a queue structure to handle orders in a first-in-first-out manner.

Uploaded by

netsanet580
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/ 10

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

const int MAX_MENU_ITEMS = 10;

string foodMenuNames[MAX_MENU_ITEMS];

double foodMenuPrices[MAX_MENU_ITEMS];

int foodCount = 0;

struct OrderItem {

string name;

double price;

OrderItem* next;

};

struct OrderQueue {

OrderItem* front;

OrderItem* rear;

int orderIdCounter;

};

OrderQueue orders = { nullptr, nullptr, 1 };


int findFoodIndex(const string& foodName) {

for (int i = 0; i < foodCount; ++i) {

if (foodMenuNames[i] == foodName) return i;

return -1;

void sortMenuByPriceDesc() {

for (int i = 0; i < foodCount - 1; ++i) {

for (int j = 0; j < foodCount - i - 1; ++j) {

if (foodMenuPrices[j] < foodMenuPrices[j + 1]) {

swap(foodMenuPrices[j], foodMenuPrices[j + 1]);

swap(foodMenuNames[j], foodMenuNames[j + 1]);

void insertFoodItem() {

if (foodCount >= MAX_MENU_ITEMS) {

cout << "Menu is full. Cannot add more items.\n";

return;

cin.ignore();
cout << "Enter the name of the food item: ";

getline(cin, foodMenuNames[foodCount]);

if (findFoodIndex(foodMenuNames[foodCount]) != -1) {

cout << "Food item already exists.\n";

return;

cout << "Enter the price of " << foodMenuNames[foodCount] << ": ";

cin >> foodMenuPrices[foodCount];

foodCount++;

sortMenuByPriceDesc();

void displayFoodItems() {

if (foodCount == 0) {

cout << "No food items available.\n";

return;

cout << "\n----------------------------------------------------\n";

cout << " | Food Name | Price |\n";

cout << "----------------------------------------------------\n";

for (int i = 0; i < foodCount; ++i) {


cout << " | ";

cout.width(25);

cout << left << foodMenuNames[i];

cout << " | Birr_";

cout.width(7);

cout << right << fixed << setprecision(2) << foodMenuPrices[i];

cout << " |\n";

cout << "----------------------------------------------------\n";

void deleteFoodItem() {

cin.ignore();

string foodName;

cout << "Enter the food item to delete: ";

getline(cin, foodName);

int index = findFoodIndex(foodName);

if (index == -1) {

cout << "Food item not found.\n";

return;

for (int i = index; i < foodCount - 1; ++i) {

foodMenuNames[i] = foodMenuNames[i + 1];


foodMenuPrices[i] = foodMenuPrices[i + 1];

foodCount--;

cout << "Food item deleted: " << foodName << endl;

void enqueue(const string& foodName, double price) {

OrderItem* newOrder = new OrderItem{ foodName, price, nullptr };

if (orders.rear) {

orders.rear->next = newOrder;

} else {

orders.front = newOrder;

orders.rear = newOrder;

cout << "Order added: ID = " << orders.orderIdCounter

<< ", Food = " << foodName << " (Birr_" << price << ")\n";

orders.orderIdCounter++;

void dequeue() {

if (!orders.front) {

cout << "No orders to delete.\n";


return;

OrderItem* temp = orders.front;

orders.front = orders.front->next;

if (!orders.front) orders.rear = nullptr;

cout << "Deleted order: " << temp->name << endl;

delete temp;

void displayOrders() {

if (!orders.front) {

cout << "No orders in the queue.\n";

return;

OrderItem* temp = orders.front;

int orderId = 1;

cout << "Current orders (FIFO):\n";

while (temp) {

cout << "Order ID = " << orderId++ << ": "

<< temp->name << " (Birr_" << temp->price << ")\n";

temp = temp->next;

}
}

void insertOrder() {

cin.ignore();

string foodName;

cout << "Enter the food item to order: ";

getline(cin, foodName);

int index = findFoodIndex(foodName);

if (index != -1) {

enqueue(foodMenuNames[index], foodMenuPrices[index]);

} else {

cout << "Food item not found in menu.\n";

void cleanUp() {

while (orders.front) {

OrderItem* temp = orders.front;

orders.front = orders.front->next;

delete temp;

int main() {
foodMenuNames[foodCount] = "Shekla Tibs(ሸክላ ጥብስ)"; foodMenuPrices[foodCount++] = 580;

foodMenuNames[foodCount] = "Kitfo(ክትፎ) "; foodMenuPrices[foodCount++] = 450;

foodMenuNames[foodCount] = "Beyeaynet(በያይነት) "; foodMenuPrices[foodCount++] = 200;

foodMenuNames[foodCount] = "Enkulal firfir(እንቁላል ፍርፍር)"; foodMenuPrices[foodCount++] =


170;

foodMenuNames[foodCount] = "ሽሮ(shiro)"; foodMenuPrices[foodCount++] = 200;

sortMenuByPriceDesc();

int choice;

char cont;

do {

cout << "\nRestaurant Management System Menu:\n";

cout << "1. Insert food item\n";

cout << "2. Display food items\n";

cout << "3. Insert orders\n";

cout << "4. Display orders\n";

cout << "5. Delete orders\n";

cout << "6. Delete food item\n";

cout << "7. Exit\n";

cout << "Enter your choice: ";

cin >> choice;

switch (choice) {

case 1:
do {

insertFoodItem();

cout << "Add another food item? (Y/N): ";

cin >> cont;

} while (cont == 'Y' || cont == 'y');

break;

case 2:

displayFoodItems();

break;

case 3:

do {

insertOrder();

cout << "Insert another order? (Y/N): ";

cin >> cont;

} while (cont == 'Y' || cont == 'y');

break;

case 4:

displayOrders();

break;

case 5:

dequeue();

break;

case 6:

deleteFoodItem();

break;
case 7:

cout << "Exiting the program.\n";

cleanUp();

break;

default:

cout << "Invalid choice. Try again.\n";

} while (choice != 7);

return 0;

You might also like