商店管理系统代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
//void welcome();//欢迎界面
void display(int);//输出信息
int size=0;
class Product
{
public:
    void addProduct();
    void queryById();
    void queryByName();
    void queryByBrand();
    void queryByMode();
    void queryAll();
    void welcome();
    void find();
    void show();
    double setId()
    {
        return Id;
    }
    string setName()
    {
        return Name;
    }
    string setBrand()
    {
        return Brand;
    }
    string setMode()
    {
        return Mode;
    }
    double setprice()
    {
        return price;
    }
private:

    int Id;
    string Name;
    string Brand;
    string Mode;
    double price;
};
Product product[10000];
void Product::welcome()
{
    int n,a;
    cout<<"*---------------------------*"<<endl;
    cout<<"|--------商品管理系统-------|"<<endl;
    cout<<"|---------------------------|"<<endl;
    cout<<endl;
    cout<<"|---------------------------|"<<endl;
    cout<<"|--------1.增加商品---------|"<<endl;
    cout<<"|--------2.查找商品---------|"<<endl;
    cout<<"|--------3.查找全部商品-----|"<<endl;
    cout<<"|--------4.退出系统---------|"<<endl;
    cout<<"*---------------------------*"<<endl;
    cout<<"请输入指令:"<<endl;
    cin>>n;
    switch(n)
    {
    case 1:
        Product::addProduct();
        Product::welcome();
        break;
    case 2:
        while(1)
        {
            Product::find();
            cin>>a;

            if(a==1)
                Product::queryById();
            else if(a==2)
                Product::queryByName();
            else if(a==3)
                Product::queryByBrand();
            else if(a==4)
                Product::queryByMode();
            else
                Product::welcome();
        }
        break;
    case 3:
        Product::show();
        break;
    case 4:
        break;
    default:
        break;
    }
}
void Product::find()
{
    cout<<"*---------------------------------*"<<endl;
    cout<<"|--------1.以图书编号查找---------|"<<endl;
    cout<<"|--------2.以图书名查找-----------|"<<endl;
    cout<<"|--------3.以作者名查找-----------|"<<endl;
    cout<<"|--------4.以出版社查找-----------|"<<endl;
    cout<<"|--------5.回到主菜单-------------|"<<endl;
    cout<<"*---------------------------------*"<<endl;
    cout<<"请输入指令:";

}
void Product::addProduct()
{
    char m;
    cout<<"输入商品编号:";
    cin>>product[size].Id;
    cout<<"输入商品名称:";
    cin>>product[size].Name;
    cout<<"输入商品品牌:";
    cin>>product[size].Brand;
    cout<<"输入商品型号:";
    cin>>product[size].Mode;
    cout<<"输入价格:";
    cin>>product[size].price;
    cout<<"添加成功!"<<endl;
    display(size);
    size++;
    cout<<"是否继续添加图书(是y,否n)"<<endl;
    cin>>m;
    if(m=='y')
        Product::addProduct();
    if(m=='n')
        Product::welcome();
}
void display(int i)
{
    cout<<"+-----------------------------------------------------------------------+"<<endl;
    cout<<setiosflags(ios::left)<<"+"<<setw(10)<<"商品编号"<<setw(10)<<"商品名称"<<setw(10)<<"品牌"<<setw(10)<<"型号"<<setw(10)<<"价格"<<setw(3)<<"|"<<endl;
    cout<<"|-----------------------------------------------------------------------|"<<endl;
    cout<<setiosflags(ios::left)<<"|"<<setw(10)<<product[i].setId()<<setw(10)<<product[i].setName()<<setw(10)<<product[i].setBrand()<<setw(10)<<product[i].setBrand()<<setw(10)<<product[i].setprice()<<setw(3)<<"|"<<endl;
    cout<<"+-----------------------------------------------------------------------+"<<endl;
}
void Product::queryById()
{
    int id;
    cout<<"输入要查询的商品编号:"<<endl;
    cin>>id;
    bool flag=false;
    int n;
    for(n=0; n<=size; n++)
        if(id==product[n].Id)
        {
            flag=true;
            break;
        }
    if(flag)
        display(n);
    else
        cout<<"无查询结果!"<<endl;
}
void Product::queryByName()
{
    string name;
    cout<<"输入要查询的商品名称:"<<endl;
    cin>>name;
    bool flag=false;
    int n;
    for(n=0; n<=size; n++)
        if(name==product[n].Name)
        {
            flag=true;
            break;
        }
    if(flag)
        display(n);
    else
        cout<<"查无此商品!"<<endl;
}
void Product::queryByBrand()
{
    string brand;
    cout<<"输入要查询的商品品牌:"<<endl;
    cin>>brand;
    int n;
    bool flag=false;
    for(n=0; n<=size; n++)
        if(brand==product[n].Brand)
        {
            flag=true;
            break;
        }
    if(flag)
        display(n);
    else
        cout<<"查无此商品!"<<endl;
}
void Product::queryByMode()
{
    string mode;
    cout<<"输入要查询的商品型号:"<<endl;
    cin>>mode;
    int n;
    bool flag=false;
    for(n=0; n<=size; n++)
        if(mode==product[n].Mode)
        {
            flag=true;
            break;
        }
    if(flag)
        display(n);
    else
        cout<<"查无此商品!"<<endl;
}
void Product::show()
{
    for(int n=0; n<size; n++)
    {
        display(n);
    }
}
int main()
{
    Product p;
    p.welcome();
    return 0;
}

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值