商店货物管理系统

    技术2022-05-11  6

          商店经销一种货物,货物成箱购进,成箱卖出,购进和卖出时以重量为单位,各箱的重量不一样,单价不一样,因此商店需要记录下目前库存的货物的总重量和总价值。编写一个程序,通过定义类Carlo来模拟商店货物购进和卖出的情况。

    //Menu.h

    #ifndef MENU_H

    #define MENU_H

    class Menu

    {public:

    int show();

    };

    #endif;

    // Carlo.h

    class Carlo

    {public:

     Carlo(double Weight = 0,double Price = 0);

    virtual         ~Carlo();

      void            SetCarlo(double = 0,double = 0);

    const double    &GetCurrentTotalWeight() const;

    const double    &GetCurrentTotalPrice() const; 

    void            BuyBox();

    void            SellBox();

    void            ShowBoxInfor() const;

    protected:            

    static  double  TotalWeight;

    static  double  TotalPrice;      

    private:

    double  BoxWeight;

    double  BoxPrice;

    };

    //Carlo.cpp

    #include <iostream>

    #include "Carlo.h"

    using namespace std;

    double Carlo::TotalPrice=0.0;

    double Carlo::TotalWeight=0.0;

    Carlo::Carlo(double Weight, double Price)

    {    BoxWeight = Weight;

         BoxPrice  = Price;

         TotalPrice += Weight * Price;

         TotalWeight += Weight;

    }

    void Carlo::BuyBox()

    {    system("cls");

         Carlo carlo;

         double Weight , Price;

         cout<<"请输入进货的重量和价格:";

         cin>>Weight>>Price;

         carlo.SetCarlo(Weight,Price); 

    }

    const double &Carlo::GetCurrentTotalPrice() const

    {       return TotalPrice;         

    }

    const double &Carlo::GetCurrentTotalWeight() const

    {        return TotalWeight;

    }

    void Carlo::SetCarlo(double Weight, double Price)

    {    BoxWeight = Weight;

         BoxPrice  = Price;

         TotalPrice += Weight * Price;

         TotalWeight += Weight;

    }

    void Carlo::SellBox()

    { system("cls");

      double Weight,Price;

      cout<<"输入出货的重量和单价:";

      cin>>Weight>>Price;

     while (Weight < 0 || Price < 0)

      {  cout<<"参数不对,请重新输入:";

         cin>>Weight>>Price;

     }

     if ((Weight * Price > TotalPrice) || Weight > TotalWeight

    || TotalPrice < 0)

     {cout<<"存货不够!";

      cin.get();

      cin.get();

     }

        else

     { TotalPrice -= Weight * Price;

       TotalWeight -= Weight;

       cout<<"出货完成!";

       cin.get();

       cin.get();

     }

    }

    void Carlo::ShowBoxInfor() const

    {system("cls");

     cout<<"库中的存货总重量为:";

     cout.precision(6);

     cout.setf(ios_base::showpoint);

     cout<<GetCurrentTotalWeight()<<endl;

     cout<<"库中的存货总价钱为:";

     cout.precision(6);

     cout<<GetCurrentTotalPrice();

     cin.get();

     cin.get();

    }

    Carlo::~Carlo()

    {

    }

    //Menu.cpp

    #include <iostream>

    #include <windows.h>

    #include "Menu.h"

    using namespace std;

    int Menu::show()

    {       system("cls");

    int chioce;

    cout<<"/n/n/n/n/n/t/t/t"<<"/>/>/>";

    cout<<"进出货演示"<<"/</</<"<<endl<<endl;

    cout<<"/t/t/t"<<"1.进货登记."<<endl<<endl;

    cout<<"/t/t/t"<<"2.出货登记."<<endl<<endl;

    cout<<"/t/t/t"<<"3.获取库存信息."<<endl<<endl;

    cout<<"/t/t/t"<<"4.退出."<<endl<<endl;

    cout<<"/t/t/t"<<"请选择操作:";

    cin>>chioce;

    return (chioce);

    }

    //CarloDemo.cpp

    #include <iostream>

    #include "Menu.h"

    #include "Carlo.h"

    using namespace std;

    void main()

    {   Menu menu;

    Carlo carlo;

        int chioce;

        while( (chioce = menu.show()) - 4)

    {   switch(chioce)

    {    case 1: carlo.BuyBox();

    break;

    case 2: carlo.SellBox();

                 break;

    case 3: carlo.ShowBoxInfor();

    break;

    }

    }

    }    

      运行结果:

    1.进货登记.

       2.出货登记.

       3.获取库存信息."

    4.退出.

    请选择操作: 1

    请输入进货的重量和价格:20 1

    1.进货登记.

       2.出货登记.

       3.获取库存信息."

    4.退出.

    请选择操作: 2

    请输入出货的重量和价格:10 1

    出货成功!

    1.进货登记.

       2.出货登记.

       3.获取库存信息."

    4.退出.

    请选择操作: 3

    库中的存货总重量为:10,0000

    库中的存货总价钱为:10,0000

     

     

     

     

     

    最新回复(0)