diff --git a/校园餐厅系统.cpp b/校园餐厅系统.cpp new file mode 100644 index 0000000..c0de7b1 --- /dev/null +++ b/校园餐厅系统.cpp @@ -0,0 +1,328 @@ +#include +#include +#include +using namespace std; +// 食堂工作人员类 +class Staff { + private: + int id; // 工作人员的编号 + string name; // 工作人员的姓名 + double salary; // 工作人员的工资 + public: + // 构造函数 + Staff(int id, string name, double salary) { + this->id = id; + this->name = name; + this->salary = salary; + } + // 获取工作人员的编号 + int get_id() { + return id; + } + // 获取工作人员的姓名 + string get_name() { + return name; + } + // 获取工作人员的工资 + double get_salary() { + return salary; + } + // 设置工作人员的工资 + void set_salary(double salary) { + this->salary = salary; + } + // 处理顾客的消费与结算 + void handle_payment(Customer* customer, double amount) { + // 从顾客的账户扣除金额 + customer->deduct_balance(amount); + // 打印收据 + cout << "收据:" << endl; + cout << "顾客编号:" << customer->get_id() << endl; + cout << "顾客姓名:" << customer->get_name() << endl; + cout << "消费金额:" << amount << endl; + cout << "账户余额:" << customer->get_balance() << endl; + } + // 餐厅清洁 + void clean_restaurant() { + // 清理桌子和椅子 + cout << "清理桌子和椅子" << endl; + // 清理地板和窗户 + cout << "清理地板和窗户" << endl; + // 清理厕所和垃圾桶 + cout << "清理厕所和垃圾桶" << endl; + } + // 厨余回收 + void recycle_food() { + // 收集剩余的餐品 + cout << "收集剩余的餐品" << endl; + // 分类处理 + cout << "分类处理" << endl; + // 转交给回收机构 + cout << "转交给回收机构" << endl; + } +}; + +// 厨师类 +class Chef { + private: + int id; // 厨师的编号 + string name; // 厨师的姓名 + double salary; // 厨师的工资 + queue tasks; // 厨师的任务队列 + public: + // 构造函数 + Chef(int id, string name, double salary) { + this->id = id; + this->name = name; + this->salary = salary; + } + // 获取厨师的编号 + int get_id() { + return id; + } + // 获取厨师的姓名 + string get_name() { + return name; + } + // 获取厨师的工资 + double get_salary() { + return salary; + } + // 设置厨师的工资 + void set_salary(double salary) { + this->salary = salary; + } + // 添加一个任务到任务队列 + void add_task(string task) { + tasks.push(task); + } + // 完成当前任务 + void finish_task() { + // 如果任务队列不为空 + if (!tasks.empty()) { + // 取出队首的任务 + string task = tasks.front(); + // 弹出队首的任务 + tasks.pop(); + // 完成任务 + cout << "完成任务:" << task << endl; + } + // 如果任务队列为空 + else { + // 提示没有任务 + cout << "没有任务" << endl; + } + } + // 及时察觉剩余餐品和食材购买 + void check_food() { + // 假设有一个餐品和食材的库存表 + map inventory; + // 遍历库存表 + for (auto it = inventory.begin(); it != inventory.end(); it++) { + // 获取餐品或食材的名称和数量 + string name = it->first; + int quantity = it->second; + // 如果数量低于阈值 + if (quantity < 10) { + // 提示需要购买 + cout << "需要购买:" << name << endl; + } + } + } +}; + +// 软件管理人员类 +class Manager { + private: + int id; // 管理人员的编号 + string name; // 管理人员的姓名 + double salary; // 管理人员的工资 + public: + // 构造函数 + Manager(int id, string name, double salary) { + this->id = id; + this->name = name; + this->salary = salary; + } + // 获取管理人员的编号 + int get_id() { + return id; + } + // 获取管理人员的姓名 + string get_name() { + return name; + } + // 获取管理人员的工资 + double get_salary() { + return salary; + } + // 设置管理人员的工资 + void set_salary(double salary) { + this->salary = salary; + } + // 维护结算系统运行 + void maintain_system() { + // 检查系统是否正常运行 + cout << "检查系统是否正常运行" << endl; + // 如果发现故障,修复故障 + cout << "如果发现故障,修复故障" << endl; + // 如果没有故障,更新系统 + cout << "如果没有故障,更新系统" << endl; + } + // 操控食堂屏幕正常运行 + void control_screen() { + // 检查屏幕是否正常显示 + cout << "检查屏幕是否正常显示" << endl; + // 如果发现故障,修复故障 + cout << "如果发现故障,修复故障" << endl; + // 如果没有故障,更换屏幕内容 + cout << "如果没有故障,更换屏幕内容" << endl; + } + // 充值服务 + void recharge_service(Customer* customer, double amount) { + // 为顾客的账户充值 + customer->add_balance(amount); + // 打印充值信息 + cout << "充值信息:" << endl; + cout << "顾客编号:" << customer->get_id() << endl; + cout << "顾客姓名:" << customer->get_name() << endl; + cout << "充值金额:" << amount << endl; + cout << "账户余额:" << customer->get_balance() << endl; + } + // 撤销异常订单 + void cancel_order(Order* order) { + // 获取订单的编号和金额 + int order_id = order->get_id(); + double order_amount = order->get_amount(); + // 获取订单的顾客 + Customer* customer = order->get_customer(); + // 为顾客的账户退款 + customer->add_balance(order_amount); + // 删除订单 + delete order; + // 打印撤销信息 + cout << "撤销信息:" << endl; + cout << "订单编号:" << order_id << endl; + cout << "订单金额:" << order_amount << endl; + cout << "顾客编号:" << customer->get_id() << endl; + cout << "顾客姓名:" << customer->get_name() << endl; + cout << "账户余额:" << customer->get_balance() << endl; + } +}; + +// 顾客类 +class Customer { + private: + int id; // 顾客的编号,是一个整数,用于唯一标识每个顾客 + string name; // 顾客的姓名,是一个字符串,用于显示顾客的名字 + double balance; // 顾客的账户余额,是一个双精度浮点数,用于记录顾客的消费和充值情况 + public: + // 构造函数,用于创建顾客对象,需要传入顾客的编号、姓名和账户余额作为参数 + Customer(int id, string name, double balance) { + this->id = id; // 将参数id赋值给私有成员变量id + this->name = name; // 将参数name赋值给私有成员变量name + this->balance = balance; // 将参数balance赋值给私有成员变量balance + } + // 获取顾客的编号,返回一个整数 + int get_id() { + return id; // 返回私有成员变量id的值 + } + // 获取顾客的姓名,返回一个字符串 + string get_name() { + return name; // 返回私有成员变量name的值 + } + // 获取顾客的账户余额,返回一个双精度浮点数 + double get_balance() { + return balance; // 返回私有成员变量balance的值 + } + // 为顾客的账户增加余额,需要传入一个双精度浮点数作为参数,表示增加的金额 + void add_balance(double amount) { + balance += amount; // 将参数amount加到私有成员变量balance上 + } + // 为顾客的账户扣除余额,需要传入一个双精度浮点数作为参数,表示扣除的金额 + void deduct_balance(double amount) { + balance -= amount; // 将参数amount从私有成员变量balance上减去 + } +}; + +// 主函数 +int main() { + // 创建一些食堂工作人员对象 + Staff* staff1 = new Staff(1, "张三", 3000); + Staff* staff2 = new Staff(2, "李四", 3000); + Staff* staff3 = new Staff(3, "王五", 3000); + // 创建一些厨师对象 + Chef* chef1 = new Chef(4, "赵六", 5000); + Chef* chef2 = new Chef(5, "孙七", 5000); + Chef* chef3 = new Chef(6, "周八", 5000); + // 创建一些软件管理人员对象 + Manager* manager1 = new Manager(7, "吴九", 8000); + Manager* manager2 = new Manager(8, "郑十", 8000); + // 创建一些顾客对象 + Customer* customer1 = new Customer(100, "小明", 100); + Customer* customer2 = new Customer(101, "小红", 200); + Customer* customer3 = new Customer(102, "小刚", 300); + // 创建一些订单对象 + Order* order1 = new Order(1000, customer1, 20); + Order* order2 = new Order(1001, customer2, 30); + Order* order3 = new Order(1002, customer3, 40); + // 添加一些任务到厨师的任务队列 + chef1->add_task("炒饭"); + chef1->add_task("炒面"); + chef2->add_task("汤"); + chef2->add_task("沙拉"); + chef3->add_task("饼"); + chef3->add_task("果汁"); + // 输出一些结果 + cout << "食堂工作人员的信息:" << endl; + cout << staff1->get_id() << " " << staff1->get_name() << " " << staff1->get_salary() << endl; + cout << staff2->get_id() << " " << staff2->get_name() << " " << staff2->get_salary() << endl; + cout << staff3->get_id() << " " << staff3->get_name() << " " << staff3->get_salary() << endl; + cout << "厨师的信息:" << endl; + cout << chef1->get_id() << " " << chef1->get_name() << " " << chef1->get_salary() << endl; + cout << chef2->get_id() << " " << chef2->get_name() << " " << chef2->get_salary() << endl; + cout << chef3->get_id() << " " << chef3->get_name() << " " << chef3->get_salary() << endl; + cout << "软件管理人员的信息:" << endl; + cout << manager1->get_id() << " " << manager1->get_name() << " " << manager1->get_salary() << endl; + cout << manager2->get_id() << " " << manager2->get_name() << " " << manager2->get_salary() << endl; + cout << "顾客的信息:" << endl; + cout << customer1->get_id() << " " << customer1->get_name() << " " << customer1->get_balance() << endl; + cout << customer2->get_id() << " " << customer2->get_name() << " " << customer2->get_balance() << endl; + cout << customer3->get_id() << " " << customer3->get_name() << " " << customer3->get_balance() << endl; + cout << "订单的信息:" << endl; + cout << order1->get_id() << " " << order1->get_amount() << " " << order1->get_customer()->get_id() << endl; + cout << order2->get_id() << " " << order2->get_amount() << " " << order2->get_customer()->get_id() << endl; + cout << order3->get_id() << " " << order3->get_amount() << " " << order3->get_customer()->get_id() << endl; + // 调用一些方法 + staff1->handle_payment(customer1, order1->get_amount()); + staff2->handle_payment(customer2, order2->get_amount()); + staff3->handle_payment(customer3, order3->get_amount()); + staff1->clean_restaurant(); + staff2->recycle_food(); + chef1->finish_task(); + chef2->finish_task(); + chef3->finish_task(); + chef1->check_food(); + chef2->check_food(); + chef3->check_food(); + manager1->maintain_system(); + manager2->control_screen(); + manager1->recharge_service(customer1, 50); + manager2->cancel_order(order3); + // 释放内存 + delete staff1; + delete staff2; + delete staff3; + delete chef1; + delete chef2; + delete chef3; + delete manager1; + delete manager2; + delete customer1; + delete customer2; + delete customer3; + delete order1; + delete order2; + // 返回0 + return 0; +}