原贴地址:https://www.cnblogs.com/shugen/p/6863061.html

超市作为市民日常生活消费的主要场所,随着社会的发展,超市作为信息资源的集散地的现象日趋明显,各种促销方式,各种消费手段,是超市的业务量更大,收入更高,工作量更大。为了管理超市商品和会员和VIP信息以及计算商品价格和统计收入,我们根据超市收银台所需要的实际管理系统进行了全面的分析处理。通过设计合理的函数,通过C++设计出本程序。

系统针对超市收银系统和商品管理系统,面对大量纷繁复杂的管理操作,对不同商品的增加和删除和更改信息,以及消费者信息的维护,需要设计一个合理的系统,它应包括商品类,会员类,和基于会员类的VIP类和超市的收入信息,建立本超市管理系统8的目的是实现无纸化超市收管理,减轻管理员的工作量,实现收银维护和信息上架的一体化管理,并要求对管理员进行身份验证。

原系统为超市收银系统,分为收银模块,顾客模块,商品模块和账单模块,顾客又分为普通顾客,会员和VIP;会员用户可转为VIP;系统功能丰富,采用文件存储方法,而且是采用分txt的存储方式,与我之前熟悉的单txt存储方式不同,开拓了我的眼界,受益匪浅。

一,完善页面和代码

简单阅读源代码,发现其采用的是单一文件的编写方式,不便于阅读和管理,所以我将源代码按类进行了拆分。在拆分后,发现主函数文件中仍有大量为了优化UI的函数,本着主函数尽量简单的原则,我将这些函数合并为contents类。

下图是拆分后的项目:

拆分完成后,我又发现原系统很少有清屏功能,同时又有界面颜色的转换,使系统在使用时很不整洁,不便于使用(如下图)

所以我为原系统添加了清屏功能,减少了一些界面颜色的转换,使界面更加简洁(如下图)

 

原系统在指引界面漏写了商品文件夹,使系统无法读取和更改商品数据,我也进行了补充(如下图)

二,修复bug

除了界面问题,原系统还存在一些bug,我也进行了完善:

① 修改VIP用户信息时,会使文件名消失,使后续更改无法进行:

 

 经过测试,我发现这个bug是因为修改了VIP卡号,本系统是依据卡号对顾客信息进行寻找的,如果修改卡号,则会导致bug产生,所以我将这部分代码进行了修改,消除了这个bug:

 

 

 

 

 ②在添加,修改顾客电话号码时,总会出现bug,不是只能存下1位电话号码,就是出现乱码:

 

经过测试,bug是在拆分文件后出现的,因为数据类型在主函数中进行了重新定义,而我在拆分文件时忽略了,所以导致了这个bug。于是我干脆将电话号码的数据类型改为char类型,方便存储,节省空间:

 

③计算账单功能有bug,在原贴的评论区里也有人发现了这个bug:

 

 这部分的bug有两个原因:

代码使用不准确。计算特定日子总收入时使用了从VIP,会员等各个分文件中读取当日消费总额,写入总txt,最后从总txt中读取并计算,但每次读取时都使用的是ios::app,这种追加的方法,而且没有清空txt的函数。因此每次查询都会将数据留在总txt中,下次读取的数据就是两次查询的累加

代码编写错误。账单在txt中的存储形式如下图,而在代码读取时写了多余的读取,舍弃了有用的数据,使总价计算不正确。

发现上述bug,我将它们进行了修复,现在这个功能已经可以正常使用:

 三,增加功能

 除了上述修补和美化外,我还为收银员添加了一个简单的密码系统:

 四,代码

#include<iostream>                     
#include<fstream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>
#include "Product.h"
#include "Member.h"
#include "Vip.h"
#include "contents.h"
using namespace std;
 

int main()
{
    contents con;
    system("color 06f"); 
    extern string td;
    cout<<"请输入当前日期(年/月/ 日):";
    cin>>td;
    double income=0,flag1=0,flag2=0;
    int c=1,cho=1,k,p;
    cout<<"           ********************************************************"<<endl;
    cout<<"                 欢迎使用!收银员系统(!请仔细阅读使用说明!) "<<endl;
    cout<<"           ********************************************************"<<endl;
    cout<<"                            please press 1!"<<endl;
    cout<<"                                使用说明                             "<<endl;
    cout<<"                   一.请按提示输入要的选项"<<endl;
    cout<<"                   二.请先在F盘建立文件夹‘收银员系统’"<<endl;
    cout<<"                          并在其下建立五个文件夹"<<endl;
    cout<<"                    ①收银员   ②会员   ③VIP   ④收入  ⑤商品"<<endl;
    cout<<"                   三.请在收入文件夹中建立三个文件夹"<<endl;
    cout<<"                      ①会员收入   ②VIP收入   ③普通收入"<<endl;
    cout<<"                   四.如需要改变路径,请联系相关技术人员"<<endl;
    cout<<"                   五.系统还在测试阶段,谢谢使用!"<<endl;
    cin>>c;
    if(c!=1)
    { 
        cout<<"please press 1!"<<endl;
        cin>>c;
    }
    while(c!=0)
    {
                system("cls");
                cout<<"            ☆☆☆☆☆   欢   迎    使     用!  ☆☆☆☆☆"<<endl;
                cout<<"                       收银员系统-------------1"<<endl;    
                cout<<"                       退  出-----------------2"<<endl;
                cin>>c;
        if(c==1)  
        { 
            c=con.charge();
        }
        system("cls");
        if(c=='a')
        {
            cout<<"                       收银系统----------------1"<<endl;
            cout<<"                       返  回------------------2"<<endl;
            cout<<"                       退  出------------------3"<<endl;
            cin>>k;
        if(k==2)
        {c=2;continue;}
        system("cls");
        while(k==1)
        {    
            int flag3=0;
            if(flag1==0) p=con.shouying_system();
            if(p==1) {flag2=con.productpay_system(td);}
            else if(p==2) {flag2=con.member_system();}
            else if(p==3) {flag2=con.vip_system();}
            else if(p==4) {flag2=con.productmanage_system();}  
            else if(p==5) {flag3=1;flag2=con.showincome_system();}
            else if(p==6) {k=2; flag1=0; flag2=0; continue;}
            if(flag2==1)     
            {
                if(flag3==0) system("cls"); 
                p=con.shouying_system();
                flag1=1;
            }
        }
        if(k==3)
        exit(1);
        }
    if(c==2)  exit(1);
    }
    return 0;
}
#ifndef PRODUCT_H
#define PRODUCT_H
#include<iostream>                     
#include<fstream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>
using namespace std;

class Product
{
    private:                     //私有数据成员
    double price;                
    char name[30];
    long  number;
public:                             //成员函数
    double getprice()              //获取商品价格
    {return price;}
    char *getname()                //获取商品名
    {return name;}
    long getnumber()              //获取商品条形码
    {return number;}
    double setprice()              //设置价格
    {
    cout<<"请 输 入 价 格 : ";
    cin>>price;
    }
    string  setname()              //设置商品名
    {
    cout<<"请 输 入 商 品 名 : ";
    cin>>name;
    }
    void setnumber()                //设置商品条形码
    {
     cout<<"请 输 入 商 品 条 形 码 : ";
     cin>>number;
    }
    void addproduct();                  //增加商品
    void search();                        //查找商品信息
    void change();                        // 更改商品信息
    void display();                      //显示商品信息
    int del(int k=0);                     //删除商品信息
};

#endif
#include<iostream>                     
#include<fstream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>
#include "Product.h"
#include "Member.h"
#include "Vip.h"
using namespace std;

void Product::addproduct()                  //增加商品  
{
    string pnumber,nam;
    int k=0;
    cout<<"请 输 入 商 品 条 形 码 : ";
    cin>>pnumber;
    nam="F:\\收银员系统\\商品\\"+pnumber+".txt";
    ifstream infile(nam.c_str());
    if(infile)
    {
        cout<<"                    该商品已存在,请重新选择!"<<endl;
        k=1;
        infile.close();
    }
    infile.close();
    if(k==0)
    {
        ofstream outfile(nam.c_str());
        if(!outfile)
            {
                cout<<"                     系统出现错误,请重新保存!"<<endl;
            }
        if(outfile)
            {
                outfile<<setw(20)<<"商品条形码:"<<pnumber<<endl;
                cout<<"请 输 入 商 品 价 格 : ";
                cin>>price; 
                outfile<<setw(20)<<"商品价格:"<<price<<endl;
                cout<<"请 输 入 商 品 名 : ";
                cin>>name;
                outfile<<setw(20)<<"商品名:"<<name<<endl;
                outfile.close();
                cout<<"                保存商品成功!"<<endl;
            }
    }
}

void Product::search()             //查找商品信息
{    
    string pnumber,nam;
    cout<<"请 输 入 商 品 条 形 码: ";
    cin>>pnumber;
    nam="F:\\收银员系统\\商品\\"+pnumber+".txt";
    ifstream infile(nam.c_str());
    if(!infile)
    {    
        cout<<"                                未找到该商品,请核对 !"<<endl;
    }
    else
    {    
        cout<<"                        该商品存在,详情请查询所有信息 !"<<endl;
        infile.close();
    }
}

void Product::change()            // 更改商品信息
{
    string pnumber,nam;
    int m=0;
    m=del(1);
    if(m==1)
    {
    nam="F:\\收银员系统\\商品\\"+pnumber+".txt";
    ofstream outfile(nam.c_str());
    if(outfile)
    { 
        cout<<"                         请 输 入 更 改 后 的 商 品 信 息 !";
        cout<<"                               商 品 名 : ";
        cin>>name;
        cout<<"                               商 品 条 形 码 : ";
        cin>>number;
        cout<<"                               商 品 价 格 : ";
        cin>>price;
        outfile<<setw(20)<<"商品条形码:"<<number<<endl;
        outfile<<setw(20)<<"商品价格:"<<price<<endl;
        outfile<<setw(20)<<"商品名:"<<name<<endl;
        outfile.close();
    }
    }
}

void Product::display()                      //显示商品信息
{
    string pnumber,nam;
    cout<<"请 输 入 要 查 找 商 品 条 形 码 :";
    cin>>pnumber;
    nam="F:\\收银员系统\\商品\\"+pnumber+".txt";
    ifstream infile(nam.c_str());
    if(!infile)
    {
        cout<<"                         该商品不存在,请核对!"<<endl;
    }
    else
    {    
        cout<<"                      该商品存在!商品信息如下:"<<endl;
        string s;
        while(getline(infile,s))
            {
                cout<<s<<endl;
            }
    }
    infile.close();
}

int Product::del(int k)                     //删除商品信息
{
    string pnumber,nam;
    cout<<"请 输 入 商 品 条 形 码 : ";
    cin>>pnumber;
    nam="F:\\收银员系统\\商品\\"+pnumber+".txt";
    ifstream infile(nam.c_str());
     if(!infile)
     {
         cout<<"                            该商品不存在,请核对!"<<endl;
        return 0;
     }
      else
     {
        infile.close();
        DeleteFile(nam.c_str());
        if(k==0)  cout<<"                                删除成功!"<<endl;
        return 1;
     }
}
#ifndef MEMBER_H
#define MEMBER_H
#include<iostream>                     
#include<fstream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>

class Member
{
private:
    char name[30];
    int  number;
    char pnumber[11];
public:
    void addcustomer();                      //增加会员
    int search(int k=0);                     //查找会员
    void change();                   // 更改会员信息
    void display();                                   //显示会员信息
    int del(int k=0);                     //删除会员信息

};

#endif
#include<iostream>                     
#include<fstream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>
#include "Product.h"
#include "Member.h"
#include "Vip.h"
using namespace std;

void Member::addcustomer()                      //增加会员
{
    string cnumber,nu;
    int k=0;
    cout<<"请 输 入 会 员 卡 号 : ";
    cin>>cnumber;    
    nu="F:\\收银员系统\\会员\\"+cnumber+".txt";
    ifstream infile(nu.c_str());
    if(infile)
    {
        cout<<"                   该会员已存在,请重新输入选择!"<<endl;
        k=1;
        infile.close();
    }
    infile.close();
    if(k==0)
    {
        ofstream outfile(nu.c_str());
        if(!outfile)
        {
            cout<<"                          系统出现错误,请重新保存!"<<endl;
        }
        if(outfile)
        {    cout<<"请 输 入 会 员 手 机 号 : ";
            cin>>pnumber;
            cout<<"请 输 入 会 员 姓 名 : ";
            cin>>name;
            
            outfile<<setw(20)<<"会员名:"<<name <<endl;
            outfile<<setw(20)<<"会员卡号:"<<cnumber<<endl;
            outfile<<setw(20)<<"会员手机号:"<<pnumber<<endl;
            outfile.close();
            cout<<"                       保存会员成功!"<<endl;
        }
    }
}

int Member::search(int k)                     //查找会员
{    
    string cnumber,nu;
    cout<<"请输入会员卡号";
    cin>>cnumber;
    nu="F:\\收银员系统\\会员\\"+cnumber+".txt";
    ifstream infile(nu.c_str());
    if(!infile)
    {    
        cout<<"未找到该会员,请核对!"<<endl;
        return 0;
    }
    if(infile)    
    {
        if(k==0) cout<<"该会员存在,详情请查询所有信息 !"<<endl;
        infile.close();
        return 1;
    }    
}

void Member::change()                   // 更改会员信息
{
    string cnumber,nu;
    int m=1;
    m=del(1); 
    if(m==1)
    {
    cout<<"            请输入更改后的会员信息!";    
    cout<<"会 员 卡 号: ";
    cin>>cnumber;
    nu="F:\\收银员系统\\会员\\"+cnumber+".txt";
    ofstream outfile(nu.c_str());
    if(outfile)
    {
        cout<<"会 员 名 : ";
        cin>>name;
        cout<<"会 员 手 机 号 :";
        cin>>pnumber;
        outfile<<setw(20)<<"会员姓名:"<<name<<endl;
        outfile<<setw(20)<<"会员卡号:"<<cnumber<<endl;
        outfile<<setw(20)<<"会员手机号:"<<pnumber<<endl;
        outfile.close();
    }
    }
}

void Member::display()                                   //显示会员信息
{
    string cnumber,nu;
    cout<<"请 输 入 要 查 找 会 员 的 会 员 卡 号 :";
    cin>>cnumber;
    nu="F:\\收银员系统\\会员\\"+cnumber+".txt";
    ifstream infile(nu.c_str());
    if(!infile)
    {
        cout<<"                      该会员不存在,请核对!"<<endl;
    }
    else
    {    
        cout<<"                      该会员存在!会员信息如下:"<<endl;
        string s;
        while(getline(infile,s))
            {
                cout<<s<<endl;
            }
    }                                                               
}

int Member::del(int k)                     //删除会员信息
{
    string cnumber,nu;
    cout<<"请 输 入 会 员 卡 号 : ";
    cin>>cnumber;
    nu="F:\\收银员系统\\会员\\"+cnumber+".txt";
    ifstream infile(nu.c_str());
    if(!infile)
    {
        cout<<"                      该会员不存在,请核对!"<<endl;
        return 0;
    }
    if(infile)
    {  
       infile.close();
       DeleteFile(nu.c_str());
       if(k==0)   cout<<"删除成功!"<<endl;
       return 1;
    }
}
#include<iostream>                     
#include<fstream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>

#include "Product.h"
#include "Member.h"
#include "Vip.h"
using namespace std;

int Vip::addvip()                        //增加vip
{
    string vnumber,vn;
    int k=0;    
    cout<<"请 输 入 VIP 卡 号: ";
    cin>>vnumber;    
    vn="F:\\收银员系统\\VIP\\"+vnumber+".txt";
    ifstream infile(vn.c_str());
    if(infile)
    {
        cout<<"                     该VIP已存在,请重新选择!"<<endl;
        k=1;
        infile.close();
    }
    if(k==0)
    {
        ofstream outfile(vn.c_str());
        if(!outfile)
        {
            cout<<"                           系统出现错误,请重新保存!"<<endl;
        }
        if(outfile)
        {    
            cout<<"请 输 入 VIP 手 机 号:";
            cin>>pnumber;
            cout<<"请 输 入 VIP 姓 名: ";
            cin>>name;
            
            //cout<<pnumber;
            outfile<<setw(20)<<"VIP姓名:"<<name <<endl;
            outfile<<setw(20)<<"VIP卡号:"<<vnumber<<endl;
            outfile<<setw(20)<<"VIP手机号:"<<pnumber<<endl;
            outfile.close();
            cout<<"                           保存VIP成功!"<<endl;
            return 1;
        }
    }
}

void Vip::searchvip()                   //查找vip
{    
    string vnumber,vn;
    cout<<"请 输 入 vip 卡 号 : ";
    cin>>vnumber;
    vn="F:\\收银员系统\\VIP\\"+vnumber+".txt";
    ifstream infile(vn.c_str());
    if(!infile)
    {    
        cout<<"                       未找到该vip,请核对"<<endl;
    }
    else 
    {
        cout<<"                      该vip存在,详情请查询所有信息 !"<<endl;
        infile.close();
    }
}

void Vip::changevip()                        // 更改vip信息
{
    string vnumber,vn;
    int m=0;
    m=delvip(1);
    if(m==1)
    {
        vn="F:\\收银员系统\\VIP\\"+vnumber+".txt";
        ofstream outfile(vn.c_str());
        if(outfile)
        {
            cout<<"                    请输入更改后VIP信息!\n";
            cout<<"vip 姓 名 : ";
            cin>>name;
            cout<<"vip 手 机 号 码 : ";
            cin>>pnumber;
            outfile<<setw(20)<<"VIP卡号:"<<numbervip<<endl;
            outfile<<setw(20)<<"VIP姓名:"<<name<<endl;
            outfile<<setw(20)<<"VIP手机号:"<<pnumber<<endl;
            outfile.close();
        }
    }
}

void Vip::displayvip()                  //显示vip信息
{
    string vnumber,vn;
    cout<<"请 输 入 要 查 找 vip 的 vip 卡 号:";
    cin>>vnumber;
    vn="F:\\收银员系统\\VIP\\"+vnumber+".txt";
    ifstream infile(vn.c_str());
    if(!infile)
    {
        cout<<"                     该vip不存在,请核对!"<<endl;
    }
    else
    {    
        cout<<"                    该vip存在!vip信息如下:"<<endl;
        string s;
        while(getline(infile,s))
            {
                cout<<s<<endl;
            }
        infile.close();
    }
}

int Vip::delvip(int k)                    //删除vip信息
{
    string vnumber,vn;
    cout<<"请 输 入 vip 卡 号 : ";
    cin>>vnumber;
    vn="F:\\收银员系统\\VIP\\"+vnumber+".txt";
    ifstream infile(vn.c_str());
    if(!infile)
    {
       cout<<"                      该vip不存在,请核对!";
       return 0;
    }
    if(infile)
    {   
        infile.close();
        DeleteFile(vn.c_str());
       if(k==0) cout<<"删除成功!"<<endl;
       return 1;
    }
}

void Vip::memv()                            //member变成VIP
{
    int flag=0,flag1=0;
    Member m;
    flag=m.search(1);    
    if(flag==1)
    {
        cout<<"                         该会员存在!请继续!"<<endl;
        while(flag1==0)    flag1=addvip();
        m.del(1);
    }    
}
#ifndef VIP_H
#define VIP_H

class Vip : public Member
{
private:
    char name[30];
    int  numbervip;
    char pnumber[12];
public:
    int addvip();                                //增加vip
    void searchvip();                            //查找vip
    void changevip();                            // 更改vip信息
    void displayvip();                            //显示vip信息
    int delvip(int k=0);                        //删除vip信息
    void memv();    
};
#endif
#ifndef CONTENTS_H
#define CONTENTS_H
#include<iostream>                     
#include<fstream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>
#include "Product.h"
#include "Member.h"
#include "Vip.h"
class contents
{
    public:
    int charge();
    int shouying_system();
    int productpay_system(string td);
    int member_system();
    int vip_system();
    int productmanage_system();
    int showincome_system();
//    string ReadLine(char *filename,int line);
};

#endif
#include "contents.h"
#include<iostream>                     
#include<fstream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>
#include <string>
#include<conio.h>
#include "Product.h"
#include "Member.h"
#include "Vip.h"
string td;
using namespace std;

int contents::charge()                            //收银员系统
{  
    system("cls");
    system("color 5f");
    int cchoice;
    char name[20];
    while(cchoice!=0)
    {
        if(cchoice!=3)
        {
            cout<<"                  ╭------------< 收银员 >-----------╮"<<endl;
            cout<<"                 ∣                                  ∣"<<endl; 
            cout<<"                 ├-----------------------------------┤"<<endl; 
            cout<<"                 ∣            1.收银员注册           ∣"<<endl;
            cout<<"                 ∣            2.收银员登陆           ∣"<<endl;
            cout<<"                 ∣            3.返   回              ∣"<<endl;
            cout<<"                 ╰-----------------------------------╯"<<endl;
            cout<<"                           请选择您要服务的类别:";
            cin>>cchoice;
            system("cls");
            if((cchoice!=1)&&(cchoice!=2)&&(cchoice!=3))
                {
                    cout<<"                          输入有误,请重新输入!"<<endl;
                    continue;
                }        
        }
        if(cchoice==1)
        {
            string ad,wn,pw,rpw;
            int key=1;
            cout<<"请 输 入 工 号 : ";
            cin>>ad;
            wn="F:\\收银员系统\\收银员\\"+ad+".txt";
            ifstream infile(wn.c_str());
            if(infile)
            {
                cout<<"                                  已注册!"<<endl;
                continue;
            }
            ofstream outfile(wn.c_str());
            if(!outfile)
            {
                cout<<"                               有错误,请重试!"<<endl;
                continue;
            } 
            cout<<"请 输 入 姓 名 : ";
            cin>>name;
            while(key){
            cout<<"请 输 入 密 码 (不超过10位) :";
//            char ch;
//            while ((ch=_getch())!=13)
//            {
//            pw+=ch;//string对象重载了+=
//            cout<<"*";
//            }
            cin>>pw;
        //    char cho;
            cout<<"请 再 次 输 入 密 码,确 保 无 误:";
//            while ((cho=_getch())!=13)
//            {
//            rpw+=cho;//string对象重载了+=
//            cout<<"*";
//            }
            cin>>rpw;
            if(pw==rpw){
            key=0;
            outfile<<setw(10)<<"姓名: "<<name<<endl;
            outfile<<setw(10)<<"工号: "<<ad<<endl; 
            outfile<<pw<<endl;
            outfile.close();
            }
            else{
                key=1;
                cout<<"                            两次输入密码不同,请检查后再次输入"<<endl; 
            }
            }
            
            
            cout<<"                            欢迎!注册成功!"<<endl;
        }
        if(cchoice==2)
        {
            string wn,ad,pw,cpw;
            int i=0;
            cout<<"请 输 入 你 的 工 号 : ";
            cin>>ad;
            wn="F:\\收银员系统\\收银员\\"+ad+".txt";
            ifstream infile(wn.c_str());
            {
            if(infile)
                {
                    cout<<"请输入密码:";
                    cin>>pw;
                    while(getline(infile,cpw)&&i<2){i++;}
                    if(cpw==pw){
                    cout<<"              ☆☆☆☆☆   欢   迎   光   临    ☆☆☆☆☆"<<endl;
                    return 'a';
                    }
                    else{
                        cout<<"                            密码错误!"<<endl;
                    }
                }
            if(!infile)
                {
                    cout<<"                  您的输入有误,请您核对!"<<endl;
                }
            }
        continue;
        } 
        if(cchoice==3)
        return 2;  
    }
    return 0;
}

int contents::shouying_system()
{  system("cls");
    system("color 3b");
    int cho=1;
    while(cho!=0)
        {    
            cout<<"          ☆☆☆☆☆☆☆☆      超市收银系统      ☆☆☆☆☆☆☆☆"<<endl;
            cout<<"          ********************************************************"<<endl;
            cout<<"          *       商品支付系统---------------------------1       *"<<endl;
            cout<<"          *       会员管理系统---------------------------2       *"<<endl;
            cout<<"          *       VIP 管理系统---------------------------3       *"<<endl;
            cout<<"          *       商品管理系统---------------------------4       *"<<endl;
            cout<<"          *       查看超市收入情况-----------------------5       *"<<endl;
            cout<<"          *       返 回----------------------------------6       *"<<endl;
            cout<<"          ********************************************************"<<endl;
            cout<<"                           请输入您的指令!"<<endl;
            cin>>cho;
            system("cls");
            if(cho==1){return 1;}
            if(cho==2){return 2;} 
            if(cho==3){return 3;} 
            if(cho==4){return 4;} 
            if(cho==5){return 5;} 
            if(cho==6){return 6;} 
        }
}

int contents::productpay_system(string td)
{   system("cls");
    SYSTEMTIME sys;
    GetLocalTime(&sys); 
    system("color 0F" );
    double income=0,total,price,quantity;
    string pn,pm,mov,s;
    int f,k,flag=0,flag1=1,flag2=1;
    while(flag==0)
    {
        if(flag1==2)
        {
            cout<<"             1.继续支付商品          2.返回收银系统";
            cin>>flag2;
        }
        if(flag2==2) return 1;
        if(flag2==1)
        {
        cout<<"请 输 入 商 品 条 形 码 :";
        cin>>pn;
        pm="F:\\收银员系统\\商品\\"+pn+".txt";
        ifstream infile(pm.c_str());
        if(!infile)
            {
                cout<<"                              未找到该商品!"<<endl;
                cout<<"1.重 新 输 入     2.返 回";
                cin>>k;
                if(k==1)
                {    
                    k=0;
                    continue;
                }
                if(k==2) {f=0,flag=0;flag1=2;}
        }
        if(infile)
        {
            while(getline(infile,s))
            {
                cout<<s<<endl;
            }
            cout<<"请输入商品单价:";
            cin>>price;
            cout<<"请输入重量或质量:";
            cin>>quantity;
            cout<<"1:会员 2:VIP 3:普通顾客"<<endl;       
            cout<<"(请询问,若是会员或VIP请输入相应数字进入系统)";
            cin>>f;
        }
        while(f==1)
        {
            string a,mn;
            cout<<"请 会 员 卡 号 :";
            cin>>a;
            mn="F:\\收银员系统\\会员\\"+a+".txt";
            ifstream infile(mn.c_str());
            if(!infile)
                {
                    cout<<"                  未找到该会员!"<<endl;
                    cout<<"1.重 新 输 入     2.返 回";
                    cin>>k;
                    if(k==1)
                    {
                        k=0;
                        continue;
                    }
                    if(k==2) {f=0,flag=0;flag1=2;}
                }
            if(infile)
            {            
                string in;
                string date;
                total=price*quantity*0.9;
                income=income+total;
                cout<<"应 付 金 额 :"<<total<<endl;
                in="F:\\收银员系统\\收入\\会员收入\\"+td+".txt";
                ofstream outfile(in.c_str());
                outfile<<income<<'\t'<<sys.wSecond<<'/'<<sys.wMinute<<'/'<<sys.wHour<<endl;
                f=0,flag=0;flag1=2;
            }    
        }
        while(f==2)
        {
            string b,vn;
            cout<<"请 输 入 VIP 卡 号 :";
            cin>>b;
            vn="F:\\收银员系统\\VIP\\"+b+".txt";
            ifstream infile(vn.c_str());
            if(!infile)
            {
                cout<<"                              未找到该vip!"<<endl;
                cout<<"1.重 新 输 入     2.返 回";
                cin>>k;
                if(k==1)
                {    
                    k=0;
                    continue;
                }
                if(k==2) {f=0,flag=0;flag1=2;}
        }
            if(infile)
            {
                infile.close();
                total=price*quantity*0.8;
                income=income+total;
                string in;
                string date; 
                cout<<"应 付 金 额:"<<total<<endl;
                in="F:\\收银员系统\\收入\\VIP收入\\"+td+".txt";
                ofstream outfile(in.c_str());
                outfile<<income<<'\t'<<sys.wSecond<<'/'<<sys.wMinute<<'/'<<sys.wHour<<endl;
                f=0,flag=0;flag1=2;
            }
        }
        while(f==3)
        {
            total=price*quantity;
            cout<<"应付金额:"<<total<<endl;
            income=income+total;
            string in;
            string date;
            in="F:\\收银员系统\\收入\\普通收入\\"+td+".txt";
            ofstream outfile(in.c_str());
            outfile<<income<<'\t'<<sys.wSecond<<'/'<<sys.wMinute<<'/'<<sys.wHour<<endl;
            f=0,flag=0;flag1=2;
        }
    }
    }
    return 1;
}

int contents::member_system()
{system("cls");
    system("color 0F");
    Member m;
    int choic; 
    while(choic!=0)
    { 
        { 
            cout<<"                 1.增加               2.查找           "<<endl;
            cout<<"                 3.更改               4.显示           "<<endl;
            cout<<"                 5.删除               6.返回           "<<endl;
            cout<<"请输入您的指令:";
            cin>>choic;
        }system("cls");
        if(choic==1)
        {m.addcustomer();continue;}
        if(choic==2)
        {m.search();continue;}
        if(choic==3)
        {m.change();continue;}
        if(choic==4)
        {m.display();continue;}
        if(choic==5)
        {m.del(0);continue;}
        if(choic==6)
        {return 1;}
    }
}

int contents::vip_system()
{system("cls");
    system("color 0F");
    Vip v;
    int choic;
    while(choic!=0)
    { 
        { 
            cout<<"                 1.增加               2.查找           "<<endl;
            cout<<"                 3.更改               4.显示           "<<endl;
            cout<<"                 5.删除               6.返回           "<<endl;
            cout<<"                 7.会员变成VIP                         "<<endl;
            cout<<"请输入您的指令:";
            cin>>choic;
        }system("cls");
        if(choic==1)
        {v.addvip();continue;}
        if(choic==2)
        {v.searchvip();continue;}
        if(choic==3)
        {v.changevip();continue;}
        if(choic==4)
        {v.displayvip();continue;}
        if(choic==5)
        {v.delvip(0);continue;}
        if(choic==6)
        {return 1;}
        if(choic==7)
        {v.memv();continue;}
    }
}

int contents::productmanage_system()
{  system("cls");
    system("color 0F");
    Product p;
    int ch;
    while(ch!=0)
    {
        cout<<"                 1.增加               2.更改           "<<endl;
        cout<<"                 3.查找               4.删除           "<<endl;
        cout<<"                 5.显示               6.返回           "<<endl;
        cout<<"请输入您的指令: ";
        cin>>ch;
        system("cls");
        if(ch==1)
        {p.addproduct();continue;}
        if(ch==2)
        {p.change();continue;}
        if(ch==3)
        {p.search();continue;}
        if(ch==4)
        {p.del(0);continue;}
        if(ch==5)
        {p.display();continue;}
        if(ch==6)
        return 1;
    }
}

int contents::showincome_system()
{   system("cls");
    SYSTEMTIME sys;
    GetLocalTime(&sys);
    system("color 2e");
    double tincome=0,number;  
    string s,in,dat;
    cout<<"请输入要查询的日期:";
    cin>>dat;
     in="F:\\收银员系统\\收入\\会员收入\\"+dat+".txt";
    ifstream infile(in.c_str());
    if(!infile)
    {
        cout<<"                    -会员当日未消费-" <<endl;
    }
    else
    {    
        cout<<"当日会员消费如下:"<<endl;
        while(getline(infile,s))
            {
                cout<<s<<endl;
                ofstream outfile("F:\\收银员系统\\收入\\totalincome.txt",ios::out);
                outfile<<s<<endl;
            }
        infile.close();
    }
    string vn;
    vn="F:\\收银员系统\\收入\\VIP收入\\"+dat+".txt";
    ifstream fin(vn.c_str());
    if(!fin)
    {
        cout<<"                    -VIP当日未消费-" <<endl;
    }
    else
    {    
        cout<<"当日VIP消费如下:"<<endl;
        while(getline(fin,s))
            {
                cout<<s<<endl;
                ofstream outfile("F:\\收银员系统\\收入\\totalincome.txt",ios::app);
        outfile<<s<<endl;
            }
        infile.close();
    }

    ifstream input_data;
    string pt;
    pt="F:\\收银员系统\\收入\\普通收入\\"+dat+".txt";
    input_data.open(pt.c_str());
    if(!input_data)
    {
        cout<<"                 -普通用户当日未消费-"<<endl;
    }
    else
    {    
        cout<<"当日普通顾客消费如下:"<<endl;
        while(getline(input_data,s))
            {
                cout<<s<<endl;
                ofstream outfile("F:\\收银员系统\\收入\\totalincome.txt",ios::app);
        outfile<<s<<endl;
            }
        infile.close();
    }

    ifstream datafile("F:\\收银员系统\\收入\\totalincome.txt",ios::in);
    if(!datafile)
    {
        cout<<"该文件未能正确打开!"<<endl;
    }
    while(datafile>>number)
    {
        int se,m,h;
        char d1,d2;
        datafile>>se>>d1>>m>>d2>>h;
        tincome=tincome+number;
    }
    datafile.clear();
    cout<<"总收入:"<<tincome<<endl;
    system("pause");
    return 1;
}

 

五,反思总结

经过这次对他人系统的开发和改进,我受益匪浅。

逆向开发锻炼了我阅读代码的能力,使我懂得了如何厘清大量代码的逻辑,先从主函数开始看起,再根据主函数用到的类,去看那个类的定义,最后看类中函数的定义,功能,明白了这一顺序,使我面对代码时有了豁然开朗,庖丁解牛之感,也不再畏惧多行代码。

同时逆向开发还锻炼了我的编程开发能力,自己写代码时,总是“身在庐山中”,不能看得全貌,容易出现各种各样的问题,通过对他人代码的二次开发,我在修复bug的同时也在反思自己是否存在这样的问题,用与平时不同的视角,便能发现自己平时编程时的思维有很多漏洞,有很多值得改进的地方。

 

 posted on 2023-03-05 16:34  任枍  阅读(171)  评论(0编辑  收藏  举报