Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
3.0 kB
7
Indexable
#include <iostream>
#include <string>

class Order {
protected:
    std::string date;
    int orderNumber;

public:
    Order(std::string date, int orderNumber) : date(date), orderNumber(orderNumber) {}

    void confirmOrder() {
        std::cout << "Order confirmed. Date: " << date << ", Order Number: " << orderNumber << std::endl;
    }

    void closeOrder() {
        std::cout << "Order closed. Date: " << date << ", Order Number: " << orderNumber << std::endl;
    }
};

class SpecialOrder : public Order {
public:
    SpecialOrder(std::string date, int orderNumber) : Order(date, orderNumber) {}

    void dispatch() {
        std::cout << "Special order dispatched. Date: " << date << ", Order Number: " << orderNumber << std::endl;
    }
};

class NormalOrder : public Order {
public:
    NormalOrder(std::string date, int orderNumber) : Order(date, orderNumber) {}

    void dispatch() {
        std::cout << "Normal order dispatched. Date: " << date << ", Order Number: " << orderNumber << std::endl;
    }

    void receive() {
        std::cout << "Normal order received. Date: " << date << ", Order Number: " << orderNumber << std::endl;
    }
};

class DiscountOrder : public SpecialOrder, public Order {
public:
    DiscountOrder(std::string date, int orderNumber) : SpecialOrder(date, orderNumber), Order(date, orderNumber) {}

    void applyDiscount() {
        std::cout << "Discount applied to Special Order. Date: " << Order::date << ", Order Number: " << Order::orderNumber << std::endl;
    }
};

class OnlineOrder : public NormalOrder, public Order {
public:
    OnlineOrder(std::string date, int orderNumber) : NormalOrder(date, orderNumber), Order(date, orderNumber) {}

    void processOnlinePayment() {
        std::cout << "Online payment processed for Normal Order. Date: " << Order::date << ", Order Number: " << Order::orderNumber << std::endl;
    }
};

class Customer {
private:
    std::string name;
    std::string location;

public:
    Customer(std::string name, std::string location) : name(name), location(location) {}

    void sendOrder(Order& order) {
        order.confirmOrder();
    }

    void receiveOrder(Order& order) {
        order.closeOrder();
    }
};

int main() {
    SpecialOrder specialOrder("2023-01-01", 101);
    NormalOrder normalOrder("2023-01-02", 102);
    DiscountOrder discountOrder("2023-01-03", 103);
    OnlineOrder onlineOrder("2023-01-04", 104);

    Customer customer("Reshala", "Tarkov St.");

    customer.sendOrder(specialOrder);
    specialOrder.dispatch();

    customer.sendOrder(normalOrder);
    normalOrder.dispatch();
    normalOrder.receive();

    customer.sendOrder(discountOrder);
    discountOrder.dispatch();
    discountOrder.applyDiscount();

    customer.sendOrder(onlineOrder);
    onlineOrder.dispatch();
    onlineOrder.receive();
    onlineOrder.processOnlinePayment();

    return 0;
}
Leave a Comment