diff --git a/Allergy.cpp b/Allergy.cpp new file mode 100644 index 0000000..d3f6f8e --- /dev/null +++ b/Allergy.cpp @@ -0,0 +1,27 @@ +// Allergy.cpp +#include "allergy.h" +#include + +void AllergyFilter::addCustomerAllergens(const std::string& customerID, const std::vector& allergens) { + customerAllergens[customerID] = allergens; +} + +bool AllergyFilter::hasAllergen(const std::string& customerID, const std::string& itemDescription) const { + auto it = customerAllergens.find(customerID); + if (it == customerAllergens.end()) { + return false; // No allergens for this customer + } + + const auto& allergens = it->second; + return std::any_of(allergens.begin(), allergens.end(), [&itemDescription](const std::string& allergen) { + return itemDescription.find(allergen) != std::string::npos; + }); +} + +std::vector AllergyFilter::getCustomerAllergens(const std::string& customerID) const { + auto it = customerAllergens.find(customerID); + if (it != customerAllergens.end()) { + return it->second; + } + return {}; +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d6c407c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.10) +project(ReservationAndAllergiesOrderingSystem) + +set(CMAKE_CXX_STANDARD 17) + +# Add all source files +set(SOURCES + main.cpp + Allergy.cpp + Customer.cpp + Menu.cpp + Notification.cpp + Order.cpp + Payment.cpp + Reservation.cpp + suggestion.cpp +) + +#add_executable(main ${SOURCES}) +add_executable(main main.cpp Controller.cpp Menu.cpp Customer.cpp Order.cpp Reservation.cpp Notification.cpp Allergy.cpp) diff --git a/Controller.cpp b/Controller.cpp new file mode 100644 index 0000000..41b114c --- /dev/null +++ b/Controller.cpp @@ -0,0 +1,118 @@ +// Controller.cpp +#include "Controller.h" +#include +#include "Payment.hpp" + +Controller::Controller() { + loadMenuItems(); +} + +void Controller::loadMenuItems() { + // Example: Load menu items (this could be replaced by file/database loading) + menu.addMenuItem({1, "Vegan Salad", 8.50, {"Gluten"}}); + menu.addMenuItem({2, "Grilled Chicken", 12.00, {"Dairy"}}); + menu.addMenuItem({3, "Seafood Pasta", 15.50, {"Shellfish"}}); +} + +void Controller::displayMenu(const std::string& customerID) const { + std::vector filteredMenu; + if (!customerID.empty()) { + auto allergens = allergyFilter.getCustomerAllergens(customerID); + filteredMenu = menu.getFilteredMenu(allergens); + } else { + filteredMenu = menu.getAllItems(); + } + + std::cout << "--- Menu ---\n"; + for (const auto& item : filteredMenu) { + std::cout << item.id << ": " << item.name << " ($" << item.price << ")\n"; + } +} + +void Controller::registerCustomer(const std::string& name, const std::string& phone, const std::string& email) { + std::string customerID = "C" + std::to_string(customers.size() + 1); + customers[customerID] = Customer(customerID, name, phone, email); + std::cout << "Customer registered: " << name << " (ID: " << customerID << ")\n"; +} + +Customer& Controller::getCustomer(const std::string& customerID) { + if (customers.find(customerID) == customers.end()) { + throw std::runtime_error("Customer not found!"); + } + return customers.at(customerID); +} + +void Controller::placeOrder(const std::string& customerID, const std::vector& itemIDs, const std::string& orderType, int tableNo, const std::string& address) { + Customer& customer = getCustomer(customerID); + std::vector items; + + for (int id : itemIDs) { + for (const auto& item : menu.getAllItems()) { + if (item.id == id) { + items.push_back(item); + break; + } + } + } + + std::shared_ptr order; + if (orderType == "DineIn") { + order = std::make_shared(orders.size() + 1, tableNo); + } else if (orderType == "Delivery") { + order = std::make_shared(orders.size() + 1, address); + } else { + throw std::runtime_error("Invalid order type!"); + } + + for (const auto& item : items) { + order->addItem(item); + } + order->calculateTotal(); + orders.push_back(order); + + std::cout << "Order placed successfully for customer: " << customer.getName() << "\n"; + order->displayOrderDetails(); +} + +void Controller::createReservation(const std::string& customerID, const std::string& date, const std::string& time, int tableNo, const std::string& paymentStatus) { + Customer& customer = getCustomer(customerID); + std::shared_ptr reservation; + + if (!paymentStatus.empty()) { + reservation = std::make_shared("R" + std::to_string(reservations.size() + 1), customerID, date, time, tableNo, paymentStatus); + } else { + reservation = std::make_shared("R" + std::to_string(reservations.size() + 1), customerID, date, time, tableNo); + } + + reservations.push_back(reservation); + std::cout << "Reservation created successfully for customer: " << customer.getName() << "\n"; + reservation->displayReservationDetails(); +} + +void Controller::sendNotification(const std::string& recipient, const std::string& content, const std::string& method) const { + std::unique_ptr notification; + + if (method == "Email") { + notification = std::make_unique(); + } else if (method == "SMS") { + notification = std::make_unique(); + } else { + throw std::runtime_error("Invalid notification method!"); + } + + notification->sendNotification(recipient, content); +} + +void Controller::processPayment(int orderID, double amount, const std::string& paymentMethod) const { + std::unique_ptr payment; + + if (paymentMethod == "Cash") { + payment = std::make_unique(); + } else if (paymentMethod == "CreditCard") { + payment = std::make_unique(); + } else { + throw std::runtime_error("Invalid payment method!"); + } + + payment->processPayment(orderID, amount); +} diff --git a/Controller.h b/Controller.h new file mode 100644 index 0000000..7d4f103 --- /dev/null +++ b/Controller.h @@ -0,0 +1,46 @@ +// Controller.h +#ifndef CONTROLLER_HPP +#define CONTROLLER_HPP + +#include "menu.h" +#include "order.h" +#include "Customer.h" +#include "Reservation.h" +#include "Notification.hpp" +#include "allergy.h" +#include +#include + +class Controller { +private: + Menu menu; + AllergyFilter allergyFilter; + std::map customers; + std::vector> orders; + std::vector> reservations; + +public: + Controller(); + + // Menu Management + void loadMenuItems(); + void displayMenu(const std::string& customerID) const; + + // Customer Management + void registerCustomer(const std::string& name, const std::string& phone, const std::string& email); + Customer& getCustomer(const std::string& customerID); + + // Order Management + void placeOrder(const std::string& customerID, const std::vector& itemIDs, const std::string& orderType, int tableNo = -1, const std::string& address = ""); + + // Reservation Management + void createReservation(const std::string& customerID, const std::string& date, const std::string& time, int tableNo, const std::string& paymentStatus = ""); + + // Notification Management + void sendNotification(const std::string& recipient, const std::string& content, const std::string& method) const; + + void processPayment(int orderID, double amount, const std::string& paymentMethod) const; + +}; + +#endif // CONTROLLER_HPP diff --git a/Customer.cpp b/Customer.cpp index d0ea393..90ccfc2 100644 --- a/Customer.cpp +++ b/Customer.cpp @@ -1,44 +1,17 @@ +// Customer.cpp #include "Customer.h" -#include -using namespace std; -Customer::Customer(string id, string name, string phone, string email, string prefs, string address) - : _customerID(id), _name(name), _phoneNumber(phone), _email(email), _preferences(prefs), _address(address) {} +Customer::Customer(const std::string& id, const std::string& name, const std::string& phone, const std::string& email) + : customerID(id), name(name), phone(phone), email(email) {} -void Customer::updateProfile(string updatedInfo) { - cout << "Profile updated: " << updatedInfo << endl; +void Customer::updatePreferences(const std::vector& newPreferences) { + preferences = newPreferences; } -void Customer::viewOrderHistory() { - cout << "Order History for " << _name << ":\n"; - for (const auto& order : _orderHistory) { - cout << "- " << order << endl; - } +const std::string& Customer::getName() const { + return name; } -void Customer::addOrderHistory(string order) { - _orderHistory.push_back(order); -} - -string Customer::getCustomerID() const { - return _customerID; -} - -string Customer::getAddress() const { - return _address; -} - -void Customer::setAddress(const string& address) { - _address = address; -} - -void Customer::displayCustomerDetails() const { - cout << "Customer ID: " << _customerID << endl; - cout << "Name: " << _name << endl; - cout << "Phone: " << _phoneNumber << endl; - cout << "Email: " << _email << endl; - cout << "Preferences: " << _preferences << endl; - if (!_address.empty()) { - cout << "Address: " << _address << endl; - } +const std::vector& Customer::getPreferences() const { + return preferences; } diff --git a/Customer.h b/Customer.h index 4a70c32..f061ab5 100644 --- a/Customer.h +++ b/Customer.h @@ -1,38 +1,24 @@ +// Customer.h #ifndef CUSTOMER_HPP #define CUSTOMER_HPP #include #include -using namespace std; class Customer { private: - string _customerID; - string _name; - string _phoneNumber; - string _email; - string _preferences; - string _address; - vector _orderHistory; + std::string customerID; + std::string name; + std::string phone; + std::string email; + std::vector preferences; public: - // Constructor - Customer(string id, string name, string phone, string email, string prefs, string address = ""); - - // Methods - void updateProfile(string updatedInfo); - void viewOrderHistory(); - void addOrderHistory(string order); - - // Getters - string getCustomerID() const; - string getAddress() const; - - // Setters - void setAddress(const string& address); - - // Display Details - void displayCustomerDetails() const; + Customer() = default; // Default constructor + Customer(const std::string& id, const std::string& name, const std::string& phone, const std::string& email); + void updatePreferences(const std::vector& newPreferences); + const std::string& getName() const; + const std::vector& getPreferences() const; }; #endif // CUSTOMER_HPP diff --git a/Menu.cpp b/Menu.cpp new file mode 100644 index 0000000..5ceca1d --- /dev/null +++ b/Menu.cpp @@ -0,0 +1,31 @@ +// Menu.cpp +#include "menu.h" +#include + +Menu::Menu() {} + +void Menu::addMenuItem(const MenuItem& item) { + items.push_back(item); +} + +std::vector Menu::getFilteredMenu(const std::vector& allergens) const { + std::vector filteredMenu; + + for (const auto& item : items) { + bool containsAllergen = false; + for (const auto& allergen : allergens) { + if (std::find(item.allergens.begin(), item.allergens.end(), allergen) != item.allergens.end()) { + containsAllergen = true; + break; + } + } + if (!containsAllergen) { + filteredMenu.push_back(item); + } + } + return filteredMenu; +} + +const std::vector& Menu::getAllItems() const { + return items; +} diff --git a/MenuItem.h b/MenuItem.h new file mode 100644 index 0000000..3384cb8 --- /dev/null +++ b/MenuItem.h @@ -0,0 +1,18 @@ +// MenuItem.h +#ifndef MENUITEM_HPP +#define MENUITEM_HPP + +#include +#include + +struct MenuItem { + int id; + std::string name; + double price; + std::vector allergens; + + MenuItem(int id, const std::string& name, double price, const std::vector& allergens) + : id(id), name(name), price(price), allergens(allergens) {} +}; + +#endif // MENUITEM_HPP diff --git a/Notification.cpp b/Notification.cpp index d85708b..e6c63a9 100644 --- a/Notification.cpp +++ b/Notification.cpp @@ -1,18 +1,23 @@ +// Notification.cpp #include "Notification.hpp" #include -#include -using namespace std; +#include +#include -string Notification::getCurrentTime() { - time_t now = time(0); - char* dt = ctime(&now); - return string(dt); +std::string Notification::getCurrentTimestamp() const { + auto now = std::chrono::system_clock::now(); + auto time = std::chrono::system_clock::to_time_t(now); + std::ostringstream oss; + oss << std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S"); + return oss.str(); } -void EmailNotification::sendNotification(const string& email, const string& content) { - cout << "[Email Notification] Email: " << email << " | Message: " << content << " | Timestamp: " << getCurrentTime() << endl; +void EmailNotification::sendNotification(const std::string& email, const std::string& content) const { + std::cout << "[Email Notification] Email: " << email << "\nMessage: " << content + << "\nTimestamp: " << getCurrentTimestamp() << "\n"; } -void SMSNotification::sendNotification(const string& phoneNumber, const string& content) { - cout << "[SMS Notification] Phone: " << phoneNumber << " | Message: " << content << " | Timestamp: " << getCurrentTime() << endl; +void SMSNotification::sendNotification(const std::string& phoneNumber, const std::string& content) const { + std::cout << "[SMS Notification] Phone: " << phoneNumber << "\nMessage: " << content + << "\nTimestamp: " << getCurrentTimestamp() << "\n"; } diff --git a/Notification.hpp b/Notification.hpp index 49622c6..c60b81b 100644 --- a/Notification.hpp +++ b/Notification.hpp @@ -1,31 +1,28 @@ +// Notification.hpp #ifndef NOTIFICATION_HPP #define NOTIFICATION_HPP #include -using namespace std; class Notification { -public: - // Gets the current timestamp - string getCurrentTime(); +protected: + std::string getCurrentTimestamp() const; - // Virtual destructor for proper cleanup +public: virtual ~Notification() = default; - // Pure virtual method to send a notification - virtual void sendNotification(const string& recipient, const string& content) = 0; + // Pure virtual method for sending notifications + virtual void sendNotification(const std::string& recipient, const std::string& content) const = 0; }; class EmailNotification : public Notification { public: - // Sends an email notification - void sendNotification(const string& email, const string& content) override; + void sendNotification(const std::string& email, const std::string& content) const override; }; class SMSNotification : public Notification { public: - // Sends an SMS notification - void sendNotification(const string& phoneNumber, const string& content) override; + void sendNotification(const std::string& phoneNumber, const std::string& content) const override; }; #endif // NOTIFICATION_HPP diff --git a/Order.cpp b/Order.cpp new file mode 100644 index 0000000..0d69361 --- /dev/null +++ b/Order.cpp @@ -0,0 +1,42 @@ +// Order.cpp +#include "order.h" +#include +#include + +Order::Order(int id) : orderID(id), totalAmount(0.0) {} + +void Order::addItem(const MenuItem& item) { + items.push_back(item); +} + +double Order::calculateTotal() { + totalAmount = 0.0; + for (const auto& item : items) { + totalAmount += item.price; + } + return totalAmount; +} + +const std::vector& Order::getItems() const { + return items; +} + +DineInOrder::DineInOrder(int id, int tableNo) : Order(id), tableNumber(tableNo) {} + +void DineInOrder::displayOrderDetails() const { + std::cout << "Dine-In Order #" << orderID << "\nTable Number: " << tableNumber << "\nItems:\n"; + for (const auto& item : items) { + std::cout << "- " << item.name << " ($" << std::fixed << std::setprecision(2) << item.price << ")\n"; + } + std::cout << "Total: $" << totalAmount << "\n"; +} + +DeliveryOrder::DeliveryOrder(int id, const std::string& address) : Order(id), deliveryAddress(address) {} + +void DeliveryOrder::displayOrderDetails() const { + std::cout << "Delivery Order #" << orderID << "\nDelivery Address: " << deliveryAddress << "\nItems:\n"; + for (const auto& item : items) { + std::cout << "- " << item.name << " ($" << std::fixed << std::setprecision(2) << item.price << ")\n"; + } + std::cout << "Total: $" << totalAmount << "\n"; +} diff --git a/Payment.cpp b/Payment.cpp index 7510e9f..67e2f53 100644 --- a/Payment.cpp +++ b/Payment.cpp @@ -1,19 +1,24 @@ #include "Payment.hpp" #include -using namespace std; -void CreditCardPayment::processPayment(int orderID, double amount) { - cout << "[Credit Card Payment Processed] Order ID: " << orderID << " | Amount: $" << amount << " | Status: Processed with Credit Card" << endl; +void CashPayment::processPayment(int orderID, double amount) const { + std::cout << "[Cash Payment] Order ID: " << orderID + << " | Amount: $" << amount + << " | Status: Paid in Cash\n"; } -void CreditCardPayment::refundPayment(int paymentID) { - cout << "[Credit Card Payment Refunded] Payment ID: " << paymentID << " | Status: Refunded to Credit Card" << endl; +void CashPayment::refundPayment(int paymentID) const { + std::cout << "[Cash Refund] Payment ID: " << paymentID + << " | Status: Refunded in Cash\n"; } -void CashPayment::processPayment(int orderID, double amount) { - cout << "[Cash Payment Processed] Order ID: " << orderID << " | Amount: $" << amount << " | Status: Paid in Cash" << endl; +void CreditCardPayment::processPayment(int orderID, double amount) const { + std::cout << "[Credit Card Payment] Order ID: " << orderID + << " | Amount: $" << amount + << " | Status: Charged to Credit Card\n"; } -void CashPayment::refundPayment(int paymentID) { - cout << "[Cash Payment Refunded] Payment ID: " << paymentID << " | Status: Refunded in Cash" << endl; +void CreditCardPayment::refundPayment(int paymentID) const { + std::cout << "[Credit Card Refund] Payment ID: " << paymentID + << " | Status: Refunded to Credit Card\n"; } diff --git a/Payment.hpp b/Payment.hpp index 8a4227d..dde2cb2 100644 --- a/Payment.hpp +++ b/Payment.hpp @@ -1,31 +1,27 @@ #ifndef PAYMENT_HPP #define PAYMENT_HPP +#include #include -using namespace std; class Payment { public: - // Virtual destructor for proper cleanup virtual ~Payment() = default; - - // Pure virtual methods for processing and refunding payments - virtual void processPayment(int orderID, double amount) = 0; - virtual void refundPayment(int paymentID) = 0; + virtual void processPayment(int orderID, double amount) const = 0; }; -class CreditCardPayment : public Payment { +class CashPayment : public Payment { public: - // Process and refund using credit card - void processPayment(int orderID, double amount) override; - void refundPayment(int paymentID) override; + void processPayment(int orderID, double amount) const override { + std::cout << "Processed cash payment for Order #" << orderID << " - Amount: $" << amount << "\n"; + } }; -class CashPayment : public Payment { +class CreditCardPayment : public Payment { public: - // Process and refund using cash - void processPayment(int orderID, double amount) override; - void refundPayment(int paymentID) override; + void processPayment(int orderID, double amount) const override { + std::cout << "Processed credit card payment for Order #" << orderID << " - Amount: $" << amount << "\n"; + } }; #endif // PAYMENT_HPP diff --git a/Reservation.cpp b/Reservation.cpp index 4038459..93910dc 100644 --- a/Reservation.cpp +++ b/Reservation.cpp @@ -1,49 +1,33 @@ +// Reservation.cpp #include "Reservation.h" #include -using namespace std; -Reservation::Reservation(string id, string customerID, string date, string time, int tableNum) - : _reservationID(id), _customerID(customerID), _date(date), _time(time), _tableNumber(tableNum), _status("Active") {} - -void Reservation::createReservation() { - cout << "Reservation created for customer " << _customerID << " on " << _date << " at " << _time << "\n"; -} - -void Reservation::updateReservation(string updatedDetails) { - cout << "Reservation updated with details: " << updatedDetails << "\n"; -} - -void Reservation::cancelReservation() { - _status = "Cancelled"; - cout << "Reservation " << _reservationID << " has been cancelled." << endl; -} - -Reservation::~Reservation() {} - -vector Reservation::getAvailableDays() { - return {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; -} - -vector Reservation::getAvailableTimes() { - return {"12:00 PM", "1:00 PM", "2:00 PM", "3:00 PM", "4:00 PM", "5:00 PM", "6:00 PM", "7:00 PM", "8:00 PM"}; -} - -OnlineReservation::OnlineReservation(string id, string customerID, string date, string time, int tableNum, string paymentStatus) - : Reservation(id, customerID, date, time, tableNum), _paymentStatus(paymentStatus) {} - -void OnlineReservation::createReservation() { - cout << "Online reservation created for customer " << _customerID - << " on " << _date << " at " << _time << " with payment status: " << _paymentStatus << "\n"; -} - -void OnlineReservation::updateReservation(string updatedDetails) { - cout << "Online reservation updated with details: " << updatedDetails << "\n"; -} - -WalkInReservation::WalkInReservation(string id, string customerID, string date, string time, int tableNum) - : Reservation(id, customerID, date, time, tableNum) {} - -void WalkInReservation::createReservation() { - cout << "Walk-in reservation created for customer " << _customerID - << " on " << _date << " at " << _time << "\n"; -} +Reservation::Reservation(const std::string& id, const std::string& customer, const std::string& date, const std::string& time) + : reservationID(id), customerID(customer), date(date), time(time) {} + +OnlineReservation::OnlineReservation(const std::string& id, const std::string& customer, const std::string& date, + const std::string& time, int tableNo, const std::string& paymentStatus) + : Reservation(id, customer, date, time), tableNumber(tableNo), paymentStatus(paymentStatus) {} + +void OnlineReservation::displayReservationDetails() const { + std::cout << "Online Reservation #" << reservationID + << "\nCustomer: " << customerID + << "\nDate: " << date + << "\nTime: " << time + << "\nTable Number: " << tableNumber + << "\nPayment Status: " << paymentStatus + << "\n"; +} + +WalkInReservation::WalkInReservation(const std::string& id, const std::string& customer, const std::string& date, + const std::string& time, int tableNo) + : Reservation(id, customer, date, time), tableNumber(tableNo) {} + +void WalkInReservation::displayReservationDetails() const { + std::cout << "Walk-In Reservation #" << reservationID + << "\nCustomer: " << customerID + << "\nDate: " << date + << "\nTime: " << time + << "\nTable Number: " << tableNumber + << "\n"; +} \ No newline at end of file diff --git a/Reservation.h b/Reservation.h index 577401f..2edee3a 100644 --- a/Reservation.h +++ b/Reservation.h @@ -1,56 +1,42 @@ +// Reservation.h #ifndef RESERVATION_HPP #define RESERVATION_HPP #include -#include -using namespace std; class Reservation { protected: - string _reservationID; - string _date; - string _time; - int _tableNumber; - string _status; - string _customerID; + std::string reservationID; + std::string customerID; + std::string date; + std::string time; public: - // Constructor - Reservation(string id, string customerID, string date, string time, int tableNum); + Reservation(const std::string& id, const std::string& customer, const std::string& date, const std::string& time); + virtual ~Reservation() = default; - // Methods - virtual void createReservation(); - virtual void updateReservation(string updatedDetails); - virtual void cancelReservation(); - - // Dynamic availability - static vector getAvailableDays(); - static vector getAvailableTimes(); - - // Virtual destructor - virtual ~Reservation(); + virtual void displayReservationDetails() const = 0; }; class OnlineReservation : public Reservation { private: - string _paymentStatus; + int tableNumber; // Add tableNumber here + std::string paymentStatus; public: - // Constructor - OnlineReservation(string id, string customerID, string date, string time, int tableNum, string paymentStatus); - - // Override methods - void createReservation() override; - void updateReservation(string updatedDetails) override; + OnlineReservation(const std::string& id, const std::string& customer, const std::string& date, + const std::string& time, int tableNo, const std::string& paymentStatus); + void displayReservationDetails() const override; }; class WalkInReservation : public Reservation { -public: - // Constructor - WalkInReservation(string id, string customerID, string date, string time, int tableNum); +private: + int tableNumber; // Add tableNumber here - // Override methods - void createReservation() override; +public: + WalkInReservation(const std::string& id, const std::string& customer, const std::string& date, + const std::string& time, int tableNo); + void displayReservationDetails() const override; }; #endif // RESERVATION_HPP diff --git a/allergy.cpp b/allergy.cpp deleted file mode 100644 index c38bd67..0000000 --- a/allergy.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "allergy.h" -#include -#include -using namespace std; - -// Base class constructor -AllergyBase::AllergyBase() { - allergenList = {}; -} - -// Derived class constructor -AllergyFilter::AllergyFilter() : AllergyBase() { - customerAllergens = {}; -} - -// Method to flag allergens for a customer -void AllergyFilter::flagAllergens(const string& customerID, const vector& allergens) { - customerAllergens[customerID] = allergens; - cout << "Allergens flagged for customer " << customerID << ": "; - for (const auto& allergen : allergens) { - cout << allergen << " "; - } - cout << endl; -} - -// Method to check if a menu item contains allergens for a customer -bool AllergyFilter::checkAllergens(const string& menuItem, const string& customerID) const { - if (customerAllergens.find(customerID) == customerAllergens.end()) { - cout << "No allergens found for customer " << customerID << "." << endl; - return false; - } - - const auto& customerAllergenList = customerAllergens.at(customerID); - - for (const auto& allergen : customerAllergenList) { - if (menuItem.find(allergen) != string::npos) { - cout << "Allergen detected! Menu item contains " << allergen << ", which customer " << customerID << " is allergic to." << endl; - return true; - } - } - - cout << "No allergens detected for customer " << customerID << " in the menu item." << endl; - return false; -} - -// Getter to retrieve allergens for a specific customer -vector AllergyFilter::getAllergensForCustomer(const string& customerID) const { - if (customerAllergens.find(customerID) != customerAllergens.end()) { - return customerAllergens.at(customerID); - } - return {}; -} diff --git a/allergy.h b/allergy.h index 7d985ad..d8c0802 100644 --- a/allergy.h +++ b/allergy.h @@ -1,41 +1,19 @@ +// Allergy.hpp #ifndef ALLERGY_HPP #define ALLERGY_HPP #include #include #include -using namespace std; -class AllergyBase { -protected: - vector allergenList; - -public: - // Constructor - AllergyBase(); - - // Pure virtual method - virtual void flagAllergens(const string& customerID, const vector& allergens) = 0; - virtual bool checkAllergens(const string& menuItem, const string& customerID) const = 0; - - // Virtual destructor - virtual ~AllergyBase() = default; -}; - -class AllergyFilter : public AllergyBase { +class AllergyFilter { private: - map> customerAllergens; + std::map> customerAllergens; public: - // Constructor - AllergyFilter(); - - // Methods - void flagAllergens(const string& customerID, const vector& allergens) override; - bool checkAllergens(const string& menuItem, const string& customerID) const override; - - // Getter for customer allergens - vector getAllergensForCustomer(const string& customerID) const; + void addCustomerAllergens(const std::string& customerID, const std::vector& allergens); + bool hasAllergen(const std::string& customerID, const std::string& itemDescription) const; + std::vector getCustomerAllergens(const std::string& customerID) const; }; #endif // ALLERGY_HPP diff --git a/diagrams/hLRBRkis4DthAmHa8wFs3nY14SDk0I_oG1EWos8YJcoYV0ZaA8MHzj-l9P7IcBBkTO9uvyFXcGTv3dNd2HpLMcMb0k_pUpHr_f7bfzyYbuJQB_DtBCcwssPfTq9MxUflEGWHeQA9NERnx-oqnqeHulP8VqX5wB2DBq0fT7iq0xCd9yr-DHkd6YZMIZM8Bov5_P-5yYEKVuITKYnpQIZyCw1ncNVf0bGvMPumOUjNXG6Rgf0bsjIUh4RN9o.png b/diagrams/hLRBRkis4DthAmHa8wFs3nY14SDk0I_oG1EWos8YJcoYV0ZaA8MHzj-l9P7IcBBkTO9uvyFXcGTv3dNd2HpLMcMb0k_pUpHr_f7bfzyYbuJQB_DtBCcwssPfTq9MxUflEGWHeQA9NERnx-oqnqeHulP8VqX5wB2DBq0fT7iq0xCd9yr-DHkd6YZMIZM8Bov5_P-5yYEKVuITKYnpQIZyCw1ncNVf0bGvMPumOUjNXG6Rgf0bsjIUh4RN9o.png new file mode 100644 index 0000000..2fa1c63 Binary files /dev/null and b/diagrams/hLRBRkis4DthAmHa8wFs3nY14SDk0I_oG1EWos8YJcoYV0ZaA8MHzj-l9P7IcBBkTO9uvyFXcGTv3dNd2HpLMcMb0k_pUpHr_f7bfzyYbuJQB_DtBCcwssPfTq9MxUflEGWHeQA9NERnx-oqnqeHulP8VqX5wB2DBq0fT7iq0xCd9yr-DHkd6YZMIZM8Bov5_P-5yYEKVuITKYnpQIZyCw1ncNVf0bGvMPumOUjNXG6Rgf0bsjIUh4RN9o.png differ diff --git a/main.cpp b/main.cpp index 5a34592..f811c80 100644 --- a/main.cpp +++ b/main.cpp @@ -1,223 +1,118 @@ #include #include #include -#include -#include "Customer.h" -#include "allergy.h" -#include "menu.h" -#include "order.h" -#include "Notification.hpp" -#include "Reservation.h" -#include "suggestion.h" -#include "Payment.hpp" - -using namespace std; +#include "Controller.h" + +void showMainMenu() { + std::cout << "\n--- Welcome to the HelloThere Restaurant System ---\n"; + std::cout << "1. Register Customer\n"; + std::cout << "2. View Menu\n"; + std::cout << "3. Place Order\n"; + std::cout << "4. Create Reservation\n"; + std::cout << "5. Exit\n"; + std::cout << "Enter your choice: "; +} int main() { - string name, phone, email, address = "", preferences, reserveOption, orderOption; - char deliveryOption; - - cout << "Welcome to the HelloThere restaurant application!\n\n"; - cout << "Do you want to reserve a table at the restaurant? (Yes/No): "; - cin >> reserveOption; - cin.ignore(); - - if (reserveOption == "Yes" || reserveOption == "yes") { - // Reservation process - vector availableDays = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; - cout << "Available Days:\n"; - for (size_t i = 0; i < availableDays.size(); ++i) { - cout << i + 1 << ". " << availableDays[i] << "\n"; - } - - int dayChoice; - cout << "Choose a day (enter the number): "; - cin >> dayChoice; - cin.ignore(); - - if (dayChoice < 1 || dayChoice > static_cast(availableDays.size())) { - cout << "Invalid choice. Please restart the application.\n"; - return 1; - } - - string chosenDay = availableDays[dayChoice - 1]; - cout << "You chose " << chosenDay << ".\n"; - - vector availableTimes = {"12:00 PM", "1:00 PM", "2:00 PM", "3:00 PM", "4:00 PM", "5:00 PM"}; - cout << "Available Times:\n"; - for (size_t i = 0; i < availableTimes.size(); ++i) { - cout << i + 1 << ". " << availableTimes[i] << "\n"; - } - - int timeChoice; - cout << "Choose a time (enter the number): "; - cin >> timeChoice; - cin.ignore(); - - if (timeChoice < 1 || timeChoice > static_cast(availableTimes.size())) { - cout << "Invalid choice. Please restart the application.\n"; - return 1; - } - - string chosenTime = availableTimes[timeChoice - 1]; - cout << "Your reservation is confirmed for " << chosenTime << " on " << chosenDay << ".\n"; - } else { - // Ordering process - cout << "Do you want to pick up, takeaway, or have delivery? (Pick up/Takeaway/Delivery): "; - cin >> orderOption; - cin.ignore(); - - if (orderOption == "Delivery" || orderOption == "delivery") { - cout << "Enter your delivery address: "; - getline(cin, address); - } - } - - // Collect customer details - cout << "Enter your name: "; - getline(cin, name); - cout << "Enter your phone number: "; - getline(cin, phone); - cout << "Enter your email address: "; - getline(cin, email); - - cout << "Enter your food preferences (e.g., Vegan, Vegetarian, etc.): "; - getline(cin, preferences); - - // Generate unique customer ID - static int customerCounter = 1; - string customerID = "C" + to_string(customerCounter++); - - // Create Customer instance - Customer customer(customerID, name, phone, email, preferences, address); - - // Allergen filtering - char isAllergic; - cout << "Are you allergic to any food? (Y/N): "; - cin >> isAllergic; - cin.ignore(); - - AllergyFilter allergyFilter; - vector allergensForCustomer; - - if (isAllergic == 'Y' || isAllergic == 'y') { - vector commonAllergens = {"Peanuts", "Dairy", "Gluten", "Shellfish", "Soy"}; - cout << "Select allergens from the list below (enter 0 to stop):\n"; - for (size_t i = 0; i < commonAllergens.size(); ++i) { - cout << i + 1 << ". " << commonAllergens[i] << "\n"; - } - - int allergenChoice; - while (true) { - cout << "Enter allergen number (0 to finish): "; - cin >> allergenChoice; - cin.ignore(); - - if (allergenChoice == 0) break; - if (allergenChoice < 1 || allergenChoice > static_cast(commonAllergens.size())) { - cout << "Invalid choice. Try again.\n"; - continue; + Controller controller; + std::string customerID; + + while (true) { + showMainMenu(); + + int choice; + std::cin >> choice; + std::cin.ignore(); // To handle newline characters in input. + + switch (choice) { + case 1: { // Register Customer + std::string name, phone, email; + std::cout << "Enter customer name: "; + std::getline(std::cin, name); + std::cout << "Enter phone number: "; + std::getline(std::cin, phone); + std::cout << "Enter email: "; + std::getline(std::cin, email); + controller.registerCustomer(name, phone, email); + break; } - allergensForCustomer.push_back(commonAllergens[allergenChoice - 1]); - } + case 2: { // View Menu + if (customerID.empty()) { + std::cout << "You must register or select a customer first.\n"; + break; + } + controller.displayMenu(customerID); + break; + } - allergyFilter.flagAllergens(customerID, allergensForCustomer); - } + case 3: { // Place Order + if (customerID.empty()) { + std::cout << "You must register or select a customer first.\n"; + break; + } + + controller.displayMenu(customerID); + + std::cout << "\nEnter item IDs separated by spaces (0 to finish): "; + std::vector itemIDs; + int id; + while (std::cin >> id && id != 0) { + itemIDs.push_back(id); + } + std::cin.ignore(); + + std::string orderType; + std::cout << "Order type (DineIn/Delivery): "; + std::getline(std::cin, orderType); + + if (orderType == "DineIn") { + int tableNo; + std::cout << "Enter table number: "; + std::cin >> tableNo; + std::cin.ignore(); + controller.placeOrder(customerID, itemIDs, orderType, tableNo); + } else if (orderType == "Delivery") { + std::string address; + std::cout << "Enter delivery address: "; + std::getline(std::cin, address); + controller.placeOrder(customerID, itemIDs, orderType, -1, address); + } else { + std::cout << "Invalid order type.\n"; + } + break; + } - // Menu with 30 items - vector>> fullMenu = { - {1, {"Vegan Salad: Gluten-Free", 8.50}}, {2, {"Peanut Butter Sandwich", 5.00}}, - {3, {"Grilled Chicken: Dairy-Free", 12.00}}, {4, {"Shrimp Pasta: Contains Shellfish", 15.50}}, - {5, {"Soy Burger", 9.00}}, {6, {"Gluten-Free Pizza", 14.00}}, - {7, {"Tofu Stir Fry", 10.00}}, {8, {"Mango Smoothie", 6.00}}, - {9, {"Seafood Paella", 18.00}}, {10, {"Eggplant Parmesan", 11.00}}, - {11, {"Pasta Alfredo: Contains Dairy", 13.00}}, {12, {"Clam Chowder", 14.50}}, - {13, {"Caesar Salad: Contains Gluten", 8.00}}, {14, {"Turkey Sandwich", 7.50}}, - {15, {"Quinoa Bowl", 10.50}}, {16, {"Fruit Salad", 5.50}}, - {17, {"Grilled Salmon", 16.00}}, {18, {"Cheeseburger: Contains Dairy", 9.50}}, - {19, {"Lobster Bisque", 19.50}}, {20, {"Vegetable Soup", 6.50}}, - {21, {"Avocado Toast", 7.00}}, {22, {"Chickpea Curry", 9.00}}, - {23, {"Steak Tacos", 12.50}}, {24, {"Chicken Parmesan", 15.00}}, - {25, {"Shrimp Tacos", 14.50}}, {26, {"BBQ Ribs", 17.00}}, - {27, {"Stuffed Bell Peppers", 10.00}}, {28, {"Egg Salad", 5.50}}, - {29, {"Mushroom Risotto", 11.50}}, {30, {"Beef Stroganoff", 14.00}} - }; - - vector>> availableMenu; - for (const auto& item : fullMenu) { - bool containsAllergen = false; - for (const auto& allergen : allergensForCustomer) { - if (item.second.first.find(allergen) != string::npos) { - containsAllergen = true; + case 4: { // Create Reservation + if (customerID.empty()) { + std::cout << "You must register or select a customer first.\n"; + break; + } + + std::string date, time, paymentStatus; + int tableNo; + + std::cout << "Enter reservation date (YYYY-MM-DD): "; + std::getline(std::cin, date); + std::cout << "Enter reservation time (HH:MM): "; + std::getline(std::cin, time); + std::cout << "Enter table number: "; + std::cin >> tableNo; + std::cin.ignore(); + std::cout << "Enter payment status (Leave blank for Walk-In): "; + std::getline(std::cin, paymentStatus); + + controller.createReservation(customerID, date, time, tableNo, paymentStatus); break; } - } - if (!containsAllergen) { - availableMenu.push_back(item); - } - } - // Display menu - cout << "\n--- Available Menu ---\n"; - for (const auto& item : availableMenu) { - cout << item.first << ": " << item.second.first << " ($" << item.second.second << ")\n"; - } + case 5: { // Exit + std::cout << "Thank you for using the HelloThere Restaurant System. Goodbye!\n"; + return 0; + } - // Order selection - vector> selectedItems; - int itemChoice; - cout << "\nSelect items from the menu (enter 0 when done):\n"; - do { - cout << "Enter item number: "; - cin >> itemChoice; - cin.ignore(); - if (itemChoice > 0 && itemChoice <= static_cast(availableMenu.size())) { - selectedItems.push_back(availableMenu[itemChoice - 1].second); - cout << availableMenu[itemChoice - 1].second.first << " added to your order.\n"; + default: + std::cout << "Invalid choice. Please try again.\n"; } - } while (itemChoice != 0); - - // Calculate total amount - double totalAmount = 0.0; - cout << "\n--- Your Order ---\n"; - for (const auto& item : selectedItems) { - cout << "- " << item.first << " ($" << item.second << ")\n"; - totalAmount += item.second; - } - cout << "Total Amount: $" << totalAmount << "\n"; - - // Payment process - string paymentMethod; - cout << "\nEnter payment method (Cash/Credit): "; - cin >> paymentMethod; - - if (paymentMethod == "Cash" || paymentMethod == "cash") { - CashPayment cashPayment; - cashPayment.processPayment(customerCounter, totalAmount); - } else if (paymentMethod == "Credit" || paymentMethod == "credit") { - CreditCardPayment creditPayment; - creditPayment.processPayment(customerCounter, totalAmount); - } else { - cout << "Invalid payment method selected.\n"; } - - // Notification preferences - string notificationPreference; - cout << "\nWould you like to receive notifications by Email or SMS? (Email/SMS): "; - cin >> notificationPreference; - - if (notificationPreference == "Email" || notificationPreference == "email") { - EmailNotification emailNotif; - emailNotif.sendNotification(email, "Your order has been placed successfully."); - } else if (notificationPreference == "SMS" || notificationPreference == "sms") { - SMSNotification smsNotif; - smsNotif.sendNotification(phone, "Your order has been placed successfully."); - } else { - cout << "No notification preference selected.\n"; - } - - cout << "\nThank you for your order!\n"; - - return 0; } diff --git a/menu.cpp b/menu.cpp deleted file mode 100644 index 8ff057a..0000000 --- a/menu.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "menu.h" -#include -#include -using namespace std; - -Menu::Menu() {} - -void Menu::addMenuItem(int itemID, const string& itemDetails) { - items[itemID] = itemDetails; - cout << "Menu Item Added: " << itemID << " - " << itemDetails << "\n"; -} - -void Menu::updateMenuItem(int itemID, const string& updatedDetails) { - if (items.find(itemID) != items.end()) { - items[itemID] = updatedDetails; - cout << "Menu Item Updated: " << itemID << " - " << updatedDetails << "\n"; - } else { - cout << "Menu Item ID not found!\n"; - } -} - -string Menu::getMenuItemDetails(int itemID) const { - if (items.find(itemID) != items.end()) { - return items.at(itemID); - } - return "Item not found!"; -} - -vector> Menu::filterMenu(const vector& allergens) const { - vector> filteredMenu; - for (const auto& item : items) { - bool containsAllergen = false; - for (const auto& allergen : allergens) { - if (item.second.find(allergen) != string::npos) { - containsAllergen = true; - break; - } - } - if (!containsAllergen) { - filteredMenu.push_back(item); - } - } - return filteredMenu; -} - -void Menu::displayMenu(const vector>& menuToDisplay) const { - for (const auto& item : menuToDisplay) { - cout << item.first << ": " << item.second << "\n"; - } -} diff --git a/menu.h b/menu.h index 66336f6..b3211a9 100644 --- a/menu.h +++ b/menu.h @@ -1,33 +1,19 @@ +// Menu.h #ifndef MENU_HPP #define MENU_HPP -#include -#include +#include "MenuItem.h" #include -using namespace std; class Menu { private: - unordered_map items; + std::vector items; public: - // Constructor Menu(); - - // Adds a new menu item - void addMenuItem(int itemID, const string& itemDetails); - - // Updates the details of an existing menu item - void updateMenuItem(int itemID, const string& updatedDetails); - - // Retrieves the details of a menu item by ID - string getMenuItemDetails(int itemID) const; - - // Filters the menu based on allergens - vector> filterMenu(const vector& allergens) const; - - // Displays the menu - void displayMenu(const vector>& menuToDisplay) const; + void addMenuItem(const MenuItem& item); + std::vector getFilteredMenu(const std::vector& allergens) const; + const std::vector& getAllItems() const; }; #endif // MENU_HPP diff --git a/order.cpp b/order.cpp deleted file mode 100644 index ffe22a5..0000000 --- a/order.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "order.h" -#include -using namespace std; - -Order::Order(int id, const vector& orderItems) - : orderID(id), items(orderItems), status("Created") { - totalAmount = items.size() * 10.0; // Example: each item costs $10. -} - -int Order::getOrderID() const { - return orderID; -} - -vector Order::getItems() const { - return items; -} - -double Order::getTotalAmount() const { - return totalAmount; -} - -string Order::getStatus() const { - return status; -} - -void Order::updateOrder(const vector& newItems) { - items = newItems; - totalAmount = newItems.size() * 10.0; - cout << "Order Updated: " << orderID << "\n"; -} - -void Order::cancelOrder() { - status = "Cancelled"; - cout << "Order Cancelled: " << orderID << "\n"; -} - -void Order::displayOrderDetails() const { - cout << "Order ID: " << orderID << "\nStatus: " << status << "\nItems: "; - for (size_t i = 0; i < items.size(); ++i) { - cout << items[i]; - if (i != items.size() - 1) { - cout << ", "; - } - } - cout << "\nTotal Amount: $" << totalAmount << "\n"; -} - -DineInOrder::DineInOrder(int id, const vector& orderItems, int tableNo) - : Order(id, orderItems), tableNumber(tableNo) {} - -void DineInOrder::displayOrderDetails() const { - cout << "Dine-In Order Details:\n"; - Order::displayOrderDetails(); - cout << "Table Number: " << tableNumber << "\n"; -} - -DeliveryOrder::DeliveryOrder(int id, const vector& orderItems, const string& address) - : Order(id, orderItems), deliveryAddress(address) {} - -void DeliveryOrder::displayOrderDetails() const { - cout << "Delivery Order Details:\n"; - Order::displayOrderDetails(); - cout << "Delivery Address: " << deliveryAddress << "\n"; -} diff --git a/order.h b/order.h index aa53d6d..21831f2 100644 --- a/order.h +++ b/order.h @@ -1,36 +1,25 @@ +// Order.h #ifndef ORDER_HPP #define ORDER_HPP #include #include -using namespace std; +#include "MenuItem.h" class Order { protected: int orderID; - vector items; + std::vector items; double totalAmount; - string status; public: - // Constructor - Order(int id, const vector& orderItems); - - // Virtual Destructor + Order(int id); virtual ~Order() = default; - // Getters - int getOrderID() const; - vector getItems() const; - double getTotalAmount() const; - string getStatus() const; - - // Operations - void updateOrder(const vector& newItems); - void cancelOrder(); - - // Virtual function to display order details - virtual void displayOrderDetails() const; + void addItem(const MenuItem& item); + double calculateTotal(); + const std::vector& getItems() const; + virtual void displayOrderDetails() const = 0; }; class DineInOrder : public Order { @@ -38,22 +27,16 @@ class DineInOrder : public Order { int tableNumber; public: - // Constructor - DineInOrder(int id, const vector& orderItems, int tableNo); - - // Override display method + DineInOrder(int id, int tableNo); void displayOrderDetails() const override; }; class DeliveryOrder : public Order { private: - string deliveryAddress; + std::string deliveryAddress; public: - // Constructor - DeliveryOrder(int id, const vector& orderItems, const string& address); - - // Override display method + DeliveryOrder(int id, const std::string& address); void displayOrderDetails() const override; };