Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Allergy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Allergy.cpp
#include "allergy.h"
#include <algorithm>

void AllergyFilter::addCustomerAllergens(const std::string& customerID, const std::vector<std::string>& 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<std::string> AllergyFilter::getCustomerAllergens(const std::string& customerID) const {
auto it = customerAllergens.find(customerID);
if (it != customerAllergens.end()) {
return it->second;
}
return {};
}
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
118 changes: 118 additions & 0 deletions Controller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Controller.cpp
#include "Controller.h"
#include <iostream>
#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<MenuItem> 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<int>& itemIDs, const std::string& orderType, int tableNo, const std::string& address) {
Customer& customer = getCustomer(customerID);
std::vector<MenuItem> items;

for (int id : itemIDs) {
for (const auto& item : menu.getAllItems()) {
if (item.id == id) {
items.push_back(item);
break;
}
}
}

std::shared_ptr<Order> order;
if (orderType == "DineIn") {
order = std::make_shared<DineInOrder>(orders.size() + 1, tableNo);
} else if (orderType == "Delivery") {
order = std::make_shared<DeliveryOrder>(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> reservation;

if (!paymentStatus.empty()) {
reservation = std::make_shared<OnlineReservation>("R" + std::to_string(reservations.size() + 1), customerID, date, time, tableNo, paymentStatus);
} else {
reservation = std::make_shared<WalkInReservation>("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> notification;

if (method == "Email") {
notification = std::make_unique<EmailNotification>();
} else if (method == "SMS") {
notification = std::make_unique<SMSNotification>();
} 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> payment;

if (paymentMethod == "Cash") {
payment = std::make_unique<CashPayment>();
} else if (paymentMethod == "CreditCard") {
payment = std::make_unique<CreditCardPayment>();
} else {
throw std::runtime_error("Invalid payment method!");
}

payment->processPayment(orderID, amount);
}
46 changes: 46 additions & 0 deletions Controller.h
Original file line number Diff line number Diff line change
@@ -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 <map>
#include <memory>

class Controller {
private:
Menu menu;
AllergyFilter allergyFilter;
std::map<std::string, Customer> customers;
std::vector<std::shared_ptr<Order>> orders;
std::vector<std::shared_ptr<Reservation>> 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<int>& 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
45 changes: 9 additions & 36 deletions Customer.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,17 @@
// Customer.cpp
#include "Customer.h"
#include <iostream>
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<std::string>& 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<std::string>& Customer::getPreferences() const {
return preferences;
}
36 changes: 11 additions & 25 deletions Customer.h
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
// Customer.h
#ifndef CUSTOMER_HPP
#define CUSTOMER_HPP

#include <string>
#include <vector>
using namespace std;

class Customer {
private:
string _customerID;
string _name;
string _phoneNumber;
string _email;
string _preferences;
string _address;
vector<string> _orderHistory;
std::string customerID;
std::string name;
std::string phone;
std::string email;
std::vector<std::string> 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<std::string>& newPreferences);
const std::string& getName() const;
const std::vector<std::string>& getPreferences() const;
};

#endif // CUSTOMER_HPP
31 changes: 31 additions & 0 deletions Menu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Menu.cpp
#include "menu.h"
#include <algorithm>

Menu::Menu() {}

void Menu::addMenuItem(const MenuItem& item) {
items.push_back(item);
}

std::vector<MenuItem> Menu::getFilteredMenu(const std::vector<std::string>& allergens) const {
std::vector<MenuItem> 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<MenuItem>& Menu::getAllItems() const {
return items;
}
18 changes: 18 additions & 0 deletions MenuItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// MenuItem.h
#ifndef MENUITEM_HPP
#define MENUITEM_HPP

#include <string>
#include <vector>

struct MenuItem {
int id;
std::string name;
double price;
std::vector<std::string> allergens;

MenuItem(int id, const std::string& name, double price, const std::vector<std::string>& allergens)
: id(id), name(name), price(price), allergens(allergens) {}
};

#endif // MENUITEM_HPP
Loading