大二实习 最好有思路解惑

4、超市管理系统
参考功能:
1)货物管理:商品信息的入库、出库;按不同的项进行商品、顾客信息等的查找;商品数量管理;
2)会员管理:会员卡的登记、会员消费汇总、分析、积分管理等
3)促销管理:支持多种促销方式:折扣、活动、VIP卡优惠、赠送等
4)其他管理:退货管理、员工管理等

货物管理,员工管理、会员管理就是一般的数据增删改查操作,基本的进销存、库管等系统都具备这些功能,至于促销管理,就是对商品价格的二次计算,无外乎打折、满减、积分、抽奖、兑换等,只要算法确定了,就几个函数的事

可以考虑使用数据库来管理你的商品

https://blog.csdn.net/weixin_44556968/article/details/108405189?ops_request_misc=&request_id=&biz_id=102&utm_term=C++%E8%B6%85%E5%B8%82%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-108405189.nonecase&spm=1018.2226.3001.4187%E8%BF%99%E4%B8%AA%E7%9C%8B%E4%B8%80%E4%B8%8B

超市管理系统是一个为超市管理人员提供方便的工具,用于帮助他们管理超市的货物、会员、促销和其他相关事项。

货物管理功能可以帮助超市管理人员管理商品的信息,包括商品的入库和出库,按不同的项进行商品、顾客信息的查找,商品数量的管理等。

会员管理功能则可以帮助超市管理人员管理会员卡的登记,会员消费的汇总、分析,积分管理等。

促销管理功能可以帮助超市管理人员支持多种促销方式,包括折扣、活动、VIP卡优惠、赠送等。

其他管理功能则可以帮助超市管理人员管理退货和员工等相关事项。

建立超市管理系统的目的是帮助超市管理人员更好地管理超市,并帮助超市提高效率、提升服务质量。

超市管理系统:http://t.csdn.cn/s0MoY

全部源代码链接:https://pan.baidu.com/s/1FCRJq4Ae2RoTzXRCelIF2A?pwd=d6v3

提取码:d6v3

#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

// 商品信息类
class Product {
    public:
        string name; // 商品名称
        double price; // 商品价格
        int quantity; // 商品数量
        Product(string name, double price, int quantity) : name(name), price(price), quantity(quantity) {}
};

// 顾客信息类
class Customer {
    public:
        string name; // 顾客名称
        string id; // 顾客ID
        double consumption; // 顾客消费总额
        int points; // 顾客积分
        Customer(string name, string id, double consumption, int points) : name(name), id(id), consumption(consumption), points(points) {}
};

// 会员卡信息类
class VIPCard {
    public:
        string id; // 会员卡ID
        string type; // 会员卡类型
        double discount; // 会员卡折扣
        VIPCard(string id, string type, double discount) : id(id), type(type), discount(discount) {}
};

// 退货信息类
class ReturnGoods {
    public:
        string name; // 商品名称
        int quantity; // 退货数量
        double price; // 退货价格
        string reason; // 退货原因
        ReturnGoods(string name, int quantity, double price, string reason) : name(name), quantity(quantity), price(price), reason(reason) {}
};

// 员工信息类
class Employee {
    public:
        string name; // 员工姓名
        string id; // 员工ID
        string position; // 员工职位
        Employee(string name, string id, string position) : name(name), id(id), position(position) {}
};

// 超市管理系统类
class SupermarketManagementSystem {
    private:
        vector<Product> products; // 商品信息列表
        vector<Customer> customers; // 顾客信息列表
        unordered_map<string, VIPCard> vipCards; // 会员卡信息列表
        vector<ReturnGoods> returnGoods; // 退货信息列表
        vector<Employee> employees; // 员工信息列表
    
    public:
        // 商品入库
        void productIn(Product product) {
            // 先查找商品是否已经存在
            for (auto& p : products) {
                if (p.name == product.name) {
                    // 如果存在,则增加数量
                    p.quantity += product.quantity;
                    return;
                }
            }
            // 如果不存在,则新建商品信息
            products.push_back(product);
        }

        // 商品出库
        void productOut(string name, int quantity) {
            // 查找商品是否存在
            for (auto& p : products) {
                if (p.name == name) {
                    // 如果商品存在,则减少数量
                    p.quantity -= quantity;
                    return;
                }
            }
            // 如果商品不存在,则输出错误信息
            cout << "商品不存在!" << endl;
        }

        // 查找商品信息
        Product findProduct(string name) {
            for (auto& p : products) {
                if (p.name == name) {
                    return p;
                }
            }
            // 如果商品不存在,则输出错误信息
            cout << "商品不存在!" << endl;
        }

        // 查找顾客信息
        Customer findCustomer(string name) {
            for (auto& c : customers) {
                if (c.name == name) {
                    return c;
                }
            }
            // 如果顾客不存在,则输出错误信息
            cout << "顾客不存在!" << endl;
        }

        // 登记会员卡
        void registerVIPCard(VIPCard card) {
            // 先查找会员卡是否已经存在
            if (vipCards.count(card.id) > 0) {
                // 如果存在,则更新信息
                vipCards[card.id] = card;
            } else {
                // 如果不存在,则新建会员卡信息
                vipCards[card.id] = card;
            }
        }

        // 查找会员卡信息
        VIPCard findVIPCard(string id) {
            if (vipCards.count(id) > 0) {
                return vipCards[id];
            }
            // 如果会员卡不存在,则输出错误信息
            cout << "会员卡不存在!" << endl;
        }

        // 会员消费汇总
        void customerConsumptionSummary() {
            // 统计所有顾客的消费总额
            double totalConsumption = 0;
            for (auto c : customers) {
                totalConsumption += c.consumption;
            }
            cout << "所有顾客的消费总额为:" << totalConsumption << endl;
        }

        // 会员消费分析
        void customerConsumptionAnalysis() {
            // 统计所有顾客的平均消费
            double totalConsumption = 0;
            for (auto c : customers) {
                totalConsumption += c.consumption;
            }
            double averageConsumption = totalConsumption / customers.size();
            cout << "所有顾客的平均消费为:" << averageConsumption << endl;
        }

        // 会员积分管理
        void customerPointsManagement(string id, int points) {
            // 查找会员卡是否存在
            if (vipCards.count(id) > 0) {
                // 如果存在,则增加积分
                vipCards[id].points += points;
            } else {
                // 如果会员卡不存在,则输出错误信息
                cout << "会员卡不存在!" << endl;
            }
        }

        // 退货管理
        void returnGoodsManagement(ReturnGoods goods) {
            returnGoods.push_back(goods);
        }

        // 员工管理
        void employeeManagement(Employee employee) {
            employees.push_back(employee);
        }
};

int main() {
    SupermarketManagementSystem sms;
    // 入库商品
    sms.productIn(Product("牛奶", 5.0, 10));
    sms.productIn(Product("面包", 3.0, 20));
    sms.productIn(Product("橙汁", 4.0, 15));
    
    // 查找商品信息
    Product milk = sms.findProduct("牛奶");
    cout << "商品名称:" << milk.name << ", 价格:" << milk.price << ", 数量:" << milk.quantity << endl;
    
    // 出库商品
    sms.productOut("面包", 5);
    sms.productOut("汽水", 5); // 此商品不存在,输出错误信息
    
    // 登记会员卡
    sms.registerVIPCard(VIPCard("123456", "普卡", 0.9));
    sms.registerVIPCard(VIPCard("123457", "金卡", 0.8));
    
    // 查找会员卡信息
    VIPCard card = sms.findVIPCard("123456");
    cout << "会员卡ID:" << card.id << ", 类型:" << card.type << ", 折扣:" << card.discount << endl;
    
    // 会员消费汇总
    sms.customerConsumptionSummary();
    
    // 会员消费分析
    sms.customerConsumptionAnalysis();
    
    // 会员积分管理
    sms.customerPointsManagement("123456", 100);
    
    // 退货管理
    sms.returnGoodsManagement(ReturnGoods("牛奶", 2, 5.0, "过期"));
    
    // 员工管理
    sms.employeeManagement(Employee("张三", "001", "经理"));
    
    return 0;
}


首先,我们定义了五个类来存储超市管理系统的信息:商品信息类、顾客信息类、会员卡信息类、退货信息类、员工信息类。

然后,我们定义了超市管理系统类来实现功能,这些功能包括:商品入库、商品出库、查找商品信息、查找顾客信息、登记会员卡、查找会员卡信息、会员消费汇总、会员消费分析、会员积分管理、退货管理、员工管理。

在实现这些功能时,我们使用了一些容器来存储信息,比如用 vector 存储商品信息、顾客信息、退货信息、员工信息;用 unordered_map 存储会员卡信息,这样可以方便我们进行信息的查找、修改、添加等操作。

最后,我们在 main 函数中创建了超市管理系统对象,并调用了各个功能来模拟超市管理系统的使用过程。