超市管理系统包括货物管理入库出库会员管理

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

货物管理功能:

#include <stdio.h>
#include <string.h>

#define MAX_PRODUCTS 100

// 定义货物信息的结构体
typedef struct
{
    char name[32];
    char id[32];
    float price;
    int quantity;
} Product;

// 定义货物信息的数组和货物数量的变量
Product products[MAX_PRODUCTS];
int numProducts = 0;

// 实现货物入库的函数
void addProduct(Product product)
{
    // 如果货物数量已经达到了最大值,则无法添加新的货物
    if (numProducts >= MAX_PRODUCTS)
    {
        printf("无法添加新的货物,货物已满!\n");
        return;
    }

    // 将新的货物添加到数组中
    products[numProducts] = product;
    numProducts++;

    printf("成功添加货物:%s\n", product.name);
}

// 实现查找货物信息的函数
Product *findProduct(char *nameOrId)
{
    // 遍历所有货物信息,查找匹配的货物
    for (int i = 0; i < numProducts; i++)
    {
        Product *product = &products[i];
        if (strcmp(product->name, nameOrId) == 0 || strcmp(product->id, nameOrId) == 0)
        {
            // 如果找到了匹配的货物,则返回指针
            return product;
        }
    }

    // 如果没有找到匹配的货物,则返回空指针
    return NULL;
}

// 实现货物出库的函数
void updateProduct(char *nameOrId, int quantity)
{
    Product *product = findProduct(nameOrId);
    if (product == NULL)
    {
        printf("找不到匹配的货物!\n");
        return;
    }

    // 如果出库数量大于当前货物数量,则无法出库
    if (quantity > product->quantity)
    {
        printf("出库数量超过了当前货物数量!\n");
        return;
    }

    // 否则,修改货物数量
    product->quantity -= quantity;
    printf("成功出库货物:%s,出库数量:%d\n", product->name, quantity);
}

// 实现打印所有货物信息的函数
void printProducts()
{
    printf("当前货物信息如下:\n");
    for (int i = 0; i < numProducts; i++)
    {
        Product *product = &products[i];
        printf("货物名称:%s,编号:%s,价格:%.2f,数量:%d\n", product->name, product->id, product->price, product->quantity);
    }
}

// 实现货物管理的函数
void manageProduct()
{
    printf("进入货物管理\n");

    while (1)
    {
        printf("请选择操作:1.入库 2.出库 3.查找 4.打印所有 5.退出\n");
        int choice;
        scanf("%d", &choice);

        if (choice == 1)
        {
            // 入库
            char name[32];
            char id[32];
            float price;
            int quantity;

            printf("请输入货物名称:\n");
            scanf("%s", name);
            printf("请输入货物编号:\n");
            scanf("%s", id);
            printf("请输入货物价格:\n");
            scanf("%f", &price);
            printf("请输入货物数量:\n");
            scanf("%d", &quantity);

            Product product = {name, id, price, quantity};
            addProduct(product);
        }
        else if (choice == 2)
        {
            // 出库
            char nameOrId[32];
            int quantity;

            printf("请输入货物名称或编号:\n");
            scanf("%s", nameOrId);
            printf("请输入出库数量:\n");
            scanf("%d", &quantity);
            updateProduct(nameOrId, quantity);
        }
        else if (choice == 3)
        {
            // 查找
            char nameOrId[32];

            printf("请输入货物名称或编号:\n");
            scanf("%s", nameOrId);

            Product *product = findProduct(nameOrId);
            if (product == NULL)
            {
                printf("找不到匹配的货物!\n");
            }
            else
            {
                printf("货物名称:%s,编号:%s,价格:%.2f,数量:%d\n", product->name, product->id, product->price, product->quantity);
            }
        }
        else if (choice == 4)
        {
            // 打印所有
            printProducts();
        }
        else if (choice == 5)
        {
            // 退出
            break;
        }
        else
        {
            printf("无效的选项!\n");
        }
    }
}

int main()
{
    manageProduct();
    return 0;
}
 MIB.h
# pragma once
# include <iostream>
# include <vector>
# include <map>
using namespace std;
class goods
{
public:
    long G_id;
    string G_name;
    string G_type;
    goods(string name, string type, long id)
    {
        G_id = id;
        G_type = type;
        G_name = name;
    }
};
class wareHouseMIB
{
private:
    map<string, string> Findgoods_type()//搜索货品类型
    {
        map<string, string> typ;
        int a = 0;
        for (vector<goods>::iterator i = goods_.begin(); i != goods_.end(); i++)
        {
            typ[i->G_type] = i->G_type;
            a++;
        }
        return typ;
    }
public:
    vector<goods> goods_;
    int Input(string name, string type, long id)
    {
        if (Findgoods(id) == -1)
            goods_.push_back(goods(name, type, id));
        else
            cout << "输入失败" << endl << "ID所指向的货物已在架,请检查ID输入" << endl;
        return 0;
    }
    int Findgoods(string name, string type)
    {
        int count_ = 0;
        for (int i = 0; i < goods_.size(); i++)
        {
            if (goods_[i].G_name == name && goods_[i].G_type == type)
            {
                cout <<"   "<< goods_[i].G_id<<endl;
                count_++;
            }
        }
        cout << "所寻货品在架" << count_ << "件" << endl;
        return count_;
    }
    int Findgoods()
    {
        return goods_.size();
    }
    int Findgoods(long id)
    {
        for (int i = 0; i < goods_.size(); i++)
        {
            if (goods_[i].G_id == id)
                return i;
        }
        return -1;
    }
    int outWare(long id)
    {
        int i = Findgoods(id);
        if (i >= 0)
        {
            goods_.erase(goods_.begin() + i);
            return 1;
        }
        return 0;
    }
    void OutgoodsList()
    {
        map<string, string> typ = Findgoods_type();
        for (map<string, string>::iterator i = typ.begin()++; i != typ.end(); i++)
        {
            cout << i->first << endl;
            for (vector<goods>::iterator j = goods_.begin(); j != goods_.end(); j++)
            {
                if (i->first == j->G_type)
                {
                    cout << "    " << j->G_name << "   " << j->G_id << endl;
                }
            }
        }
    }
};


#include <bits/stdc++.h>
#include <windows.h>
#include <time.h>
#include <conio.h>//包含getch();

using namespace std;


string getTime()
{
    time_t timep;
    time (&timep);
    char tmp[64];
    strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S",localtime(&timep) );
    return tmp;
}


//普通员工类
class LogUser
{
protected:
    string name;                            //员工姓名
    string userId;                          //员工唯一ID(账号)
    string userPassword;                    //登录密码
    string userLevel;                       //权限(管理员、售货员)
public:
    LogUser(string n,string ui,string up,string ul);
    friend ostream& operator<<(ostream& out,LogUser& obj);
    friend istream& operator>>(istream& in,LogUser& obj);
    // void readFile(istream & in);
    string getName();
    string getUserId();
    string getUserPassword();
    string getUserLevel();
};

LogUser::LogUser(string n,string ui,string up,string ul):name(n),userId(ui),userPassword(up),userLevel(ul)
{

}

ostream& operator<<(ostream& out,LogUser& obj)
{
    out<<obj.getName()<<obj.getUserId()<<obj.getUserPassword()<<obj.getUserLevel();
}

istream& operator>>(istream& in,LogUser& obj)
{
    in>>obj.name>>obj.userId>>obj.userPassword>>obj.userLevel;
}

//void LogUser::readFile(istream & in)
//{
//    in>>namename>>userId>>userPassword;
//}

//void LogUser::writeFile(ostream & out)
//{
//    out<<this->name<<"\t"<<this->userId<<"\t"<<this->userPassword<<'\n';
//}
string LogUser::getName()
{
    return name;
}

string LogUser::getUserId()
{
    return userId;
}

string LogUser::getUserPassword()
{
    return userPassword;
}

string LogUser::getUserLevel()
{
    return userLevel;
}

//管理员类
class LogAdministrator : public LogUser
{
protected:

public:
    LogAdministrator(string n,string ui,string up,string ul);
    void addUser();                                          //管理员特有的创建员工账号功能
};


LogAdministrator::LogAdministrator(string n,string ui,string up,string ul):LogUser( n, ui,up, ul)
{

}

void LogAdministrator::addUser()
{
    ofstream out("Users.txt",ios::app);
    if(!out)
    {
        cout<<"Users.txt error!"<<endl;
        abort();
    }
    else
    {
        system("cls");
        string name,userId,userPassword,userLevel;
        cout<<"输入员工信息:"<<endl;
        cout<<"姓名:";
        cin>>name;
        cout<<"ID:";
        cin>>userId;
        cout<<"密码:";
        cin>>userPassword;
        cout<<"权限:";
        cin>>userLevel;
        out<<name<<"\t"<<userId<<"\t"<<userPassword<<"\t"<<userLevel<<"\n";
        out.close();
    }
}

//商品基类
class Goods
{
protected:
    int id;                         //商品唯一编号
    string name;                    //商品名称
    double purchasingPrice;         //进货价格
    double price;                   //售价
    int repertory;                  //库存
    string producer;                //生厂商
    string brand;                   //品牌
    string type;                    //类型
public:
    Goods(int i,string n,double pP,double p,int r,string pr,string b,string t);
    virtual void introduce();       //产品说明
    void show();
    int getId();
    string getName();
    double getPurchasingPrice();
    double getPrice();
    int getRepertory();
    string getProducer();
    string getBrand();
    string getType();
    void setRepertory(int r);
};

Goods::Goods(int i,string n,double pP,double p,int r,string pr,string b,string t):name(n),producer(pr),brand(b),type(t)
{
    id=i;
    purchasingPrice = pP;
    price = p;
    repertory = r;
}

void Goods ::introduce()
{
    cout<<"商品基类!"<<endl;
}

void Goods :: show()
{
    cout<<"商品名称:"<<name<<endl<<"进货价格:"<<purchasingPrice<<"\t\t"<<"售价:"<<price<<endl<<"库存:"<<"\t"<<repertory<<"生厂商:"<<endl<<producer<<"品牌:"<<"\t"<<brand<<"类型:"<<type<<endl;
}

int Goods :: getId()
{
    return id;
}

string Goods :: getName()
{
    return name;
}

double Goods :: getPurchasingPrice()
{
    return purchasingPrice;
}

double Goods :: getPrice()
{
    return price;
}

int Goods :: getRepertory()
{
    return repertory;
}

string Goods :: getProducer()
{
    return producer;
}

string Goods :: getBrand()
{
    return brand;
}

string Goods :: getType()
{
    return type;
}


void Goods :: setRepertory(int r)
{
    repertory = r;
}

//食品类
class Food: public Goods
{
protected:
public:
    Food(int i,string n,double pP,double p,int r,string pr,string b,string t);
    void introduce();
};

Food::Food(int i,string n,double pP,double p,int r,string pr,string b,string t):Goods(i,n,pP,p,r,pr,b,t)
{

}

void Food::introduce()
{
    cout<<"食品类!"<<endl;
}

//饮料类
class Drink: public Goods
{
protected:
public:
    Drink(int i,string n,double pP,double p,int r,string pr,string b,string t);
    void introduce();
};

Drink::Drink(int i,string n,double pP,double p,int r,string pr,string b,string t):Goods(i,n,pP,p,r,pr,b,t)
{

}

void Drink::introduce()
{
    cout<<"饮料类!"<<endl;
}

//化妆品类
class Cosmetics: public Goods
{
protected:
public:
    Cosmetics(int i,string n,double pP,double p,int r,string pr,string b,string t);
    void introduce();
};

Cosmetics::Cosmetics(int i,string n,double pP,double p,int r,string pr,string b,string t):Goods(i,n,pP,p,r,pr,b,t)
{

}

void Cosmetics::introduce()
{
    cout<<"化妆品类!"<<endl;
}

//商品管理类(售货员)
class GoodsManage_Employee
{
protected:
    vector<Goods*> goods_Vector;
    vector<Goods*> shopping_Cart;
    vector<int> shopping_Cart_Sums;
public:
    GoodsManage_Employee();
    ~GoodsManage_Employee();
    void showAll();                                     //显示全部商品信息
    void showByIndex(int index);                        //显示单个产品信息
    void sell(LogUser* log);                            //出售
    virtual int showMenu(LogUser* log);                 //售货员视角菜单
};