zoukankan      html  css  js  c++  java
  • 简单售货机代码

    #define _CRT_SCUER_WARINGS
    #include<iostream>
    using namespace std;
    class Goods {

    public:
    Goods()
    {
    weight = 0;
    next = NULL;
    cout << "创建了一个重量为" << weight << "货物" << endl;

    }
    Goods(int w) {
    weight = w;
    next = NULL;
    total_weight += weight;
    cout << "创建了一个重量为" << weight <<"货物" <<endl;
    cout << "当前厂库量为:" << GetTotal_Weight() << endl;
    }
    ~Goods()
    {
    cout << "卖出了一箱重量是" << weight << "货物" << endl;
    total_weight -= weight;
    cout << "当前厂库量为:" << GetTotal_Weight() << endl;
    }
    static int GetTotal_Weight() {

    return total_weight;
    }
    void Sale(Goods*&head)
    {
    if (head == NULL)
    {
    cout << "库中已没有货物" << endl;
    }
    else
    {
    Goods*temp = head;
    head = head->next;
    delete temp;
    }
    }
    void buy(Goods*&head, int w) {
    Goods *new_goods = new Goods(w);
    if (head == NULL)
    {
    head = new_goods;
    }
    else
    {
    new_goods->next = head;
    head = new_goods;
    }

    }


    Goods * next;
    private:

    int weight;

    static int total_weight;

    };
    int Goods::total_weight = 0;


    int main()
    {
    int flag = 0;
    Goods *head = NULL;
    do
    {
    cout << "1 进货" << endl;
    cout << "2 出货" << endl;
    cout << "3 退出" << endl;
    cin >> flag;
    switch (flag)
    {
    case 1:cout << "请输入要创建货物的重量" << endl;
    cin >> flag;
    head->buy(head, flag);
    break;
    case 2:head->Sale(head);
    break;
    case 3:
    return 0;

    default:
    break;
    }


    } while (true);

    //system("pause");
    return 0;
    }

  • 相关阅读:
    hdu5886Tower Defence(树形dp)
    hdu5893 List wants to travel(树链剖分+线段树)
    hdu5884 Sort(二分)
    hdu3559 Frost Chain (概率dp+记忆化搜索)
    hdu5790 Prefix(Trie树+主席树)
    tp5 cache 子文件夹名称
    resize 计算尺寸不正确
    Destoon Global 全局函数对应表
    MySQL语法大全
    myslq 表与表之前的数据转移
  • 原文地址:https://www.cnblogs.com/sw520/p/9418893.html
Copyright © 2011-2022 走看看