C++ 大作业 超市收银系统

#include<iostream>                     
#include<fstream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>
using namespace std;
string td;
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);                     //删除商品信息
};	
	
void  Product::addproduct()                  //增加商品  
{
    string pnumber,nam;
	int k=0;
	cout<<"请 输 入 商 品 条 形 码 : ";
	cin>>pnumber;
	nam="D:\\商品\\"+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="D:\\商品\\"+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="D:\\商品\\"+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="D:\\商品\\"+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="D:\\商品\\"+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;
	 }
}


class Member		                //会员类
{
private:
	char name[30];
	int  number;
	unsigned long int pnumber;

public:
	void addcustomer();                      //增加会员
	int search(int k=0);                     //查找会员
	void change();                   // 更改会员信息
	void display();                                   //显示会员信息
	int del(int k=0);                     //删除会员信息
};


void Member::addcustomer()                      //增加会员
{
	string cnumber,nu;
	int k=0;
	cout<<"请 输 入 会 员 卡 号 : ";
	cin>>cnumber;	
	nu="D:\\会员\\"+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>>name;
			outfile<<setw(20)<<"会员名:"<<name <<endl;
			outfile<<setw(20)<<"会员卡号:"<<cnumber<<endl;
			cout<<"请 输 入 会 员 手 机 号 : ";
			cin>>pnumber;
			outfile<<setw(20)<<"会员手机号:"<<pnumber<<endl;
			outfile.close();
			cout<<"                       保存会员成功!"<<endl;
		}
	}
}

int Member::search(int k)                     //查找会员
{	
	string cnumber,nu;
	cout<<"请输入会员卡号";
	cin>>cnumber;
	nu="D:\\会员\\"+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="D:\\会员\\"+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="D:\\会员\\"+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="D:\\会员\\"+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;
	}
}


class Vip:public Member			                //vip类
{
private:
	char name[30];
	int  numbervip;
	unsigned long int pnumber;

public:
	int addvip();								//增加vip
	void searchvip();							//查找vip
	void changevip();							// 更改vip信息
	void displayvip();							//显示vip信息
	int delvip(int k=0);						//删除vip信息
	void memv();								//member变成VIP
};


int Vip::addvip()						//增加vip
{
	string vnumber,vn;
	int k=0;	
	cout<<"请 输 入 VIP 卡 号: ";
	cin>>vnumber;	
	vn="D:\\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>>name;
			outfile<<setw(20)<<"VIP姓名:"<<name <<endl;
			outfile<<setw(20)<<"VIP卡号:"<<vnumber<<endl;
			cout<<"请 输 入 VIP 手 机 号:";
			cin>>pnumber;
			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="D:\\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="D:\\VIP\\"+vnumber+".txt";
		ofstream outfile(vn.c_str());
		if(outfile)
		{
			cout<<"                    请输入更改后VIP信息!";
			cout<<"vip 姓 名 : ";
			cin>>name;
			cout<<"vip 卡 号 : ";
			cin>>numbervip;
			cout<<"vip 手 机 号 码 : ";
			cin>>pnumber;
			outfile<<setw(20)<<"VIP姓名:"<<name<<endl;
			outfile<<setw(20)<<"VIP卡号:"<<numbervip<<endl;
			outfile<<setw(20)<<"VIP手机号:"<<pnumber<<endl;
			outfile.close();
		}
	}
}

void Vip::displayvip()                  //显示vip信息
{
	string vnumber,vn;
	cout<<"请 输 入 要 查 找 vip 的 vip 卡 号:";
	cin>>vnumber;
	vn="D:\\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="D:\\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);
	}	
}

int 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;
			if((cchoice!=1)&&(cchoice!=2)&&(cchoice!=3))
				{
					cout<<"                          输入有误,请重新输入!"<<endl;
					continue;
				}		
		}
		if(cchoice==1)
		{
			string ad,wn;
			cout<<"请 输 入 工 号 : ";
			cin>>ad;
			wn="D:\\收银员\\"+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;
			outfile<<setw(10)<<"姓名: "<<name<<endl;
			outfile<<setw(10)<<"工号: "<<ad<<endl; 
			cout<<"                            欢迎!注册成功!"<<endl;
		}
		if(cchoice==2)
		{
			string wn,ad;
			cout<<"请 输 入 你 的 工 号 : ";
			cin>>ad;
			wn="D:\\收银员\\"+ad+".txt";
			ifstream infile(wn.c_str());
			{
			if(infile)
				{
					cout<<"              ☆☆☆☆☆   欢   迎   光   临    ☆☆☆☆☆"<<endl;
					return 'a';
				}
			if(!infile)
				{
					cout<<"                  您的输入有误,请您核对!"<<endl;
				}
			}
		continue;
		} 
		if(cchoice==3)
		return 2;  
	}
	return 0;
}

int shouying_system()
{  
	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;
			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 productpay_system()
{   
	SYSTEMTIME sys;
	GetLocalTime(&sys); 
	system("color 3c" );
	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="D:\\商品\\"+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="D:\\会员\\"+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="D:\\收入\\会员收入\\"+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="D:\\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="D:\\收入\\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="D:\\收入\\普通收入\\"+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 member_system()
{
	system("color 1d");
	Member m;
	int choic; 
	while(choic!=0)
	{ 
		{ 
			cout<<"                 1.增加               2.查找           "<<endl;
			cout<<"                 3.更改               4.显示           "<<endl;
			cout<<"                 5.删除               6.返回           "<<endl;
			cout<<"请输入您的指令:";
			cin>>choic;
		}
		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 vip_system()
{
	system("color 4a");
	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;
		}
		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 productmanage_system()
{  
	system("color 5e");
    Product p;
	int ch;
	while(ch!=0)
	{
		cout<<"                 1.增加               2.更改           "<<endl;
		cout<<"                 3.查找               4.删除           "<<endl;
		cout<<"                 5.显示               6.返回           "<<endl;
		cout<<"请输入您的指令: ";
		cin>>ch;
		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 showincome_system()
{   
	SYSTEMTIME sys;
	GetLocalTime(&sys);
	system("color 2e");
	double tincome=0,number;  
	string s,in,date;
    cout<<"请输入要查询的日期:";
	cin>>date;
    in="D:\\收入\\会员收入\\"+date+".txt";
	ifstream infile(in.c_str());
	if(!infile)
	{
		cout<<"未能统计会员收入" <<endl;
	}
	while(getline(infile,s))
	{
		ofstream outfile("d:\\收入\\totalincome.txt",ios::app);
		outfile<<s<<endl;
		infile.close();
	}
	string vn;
    vn="D:\\收入\\VIP收入\\"+date+".txt";
	ifstream fin(vn.c_str());
	if(!fin)
	{
		cout<<"未能统计VIP收入" <<endl;
	}
    while(getline(fin,s))
	{ 
		ofstream outfile("d:\\收入\\totalincome.txt",ios::app);
		outfile<<s<<endl;
		fin.close();
	}
    ifstream input_data;
	string pt;
    pt="D:\\收入\\普通收入\\"+date+".txt";
	input_data.open(pt.c_str());
	if(!input_data)
	{
		cout<<"未能统计普通顾客收入"<<endl;
	}
	while(getline(input_data,s))
	{
		ofstream outfile("d:\\收入\\totalincome.txt",ios::app);
		outfile<<s<<endl;
		input_data.close();
	}
	ifstream datafile("d:\\收入\\totalincome.txt",ios::in);
	if(!datafile)
	{
		cout<<"该文件未能正确打开!"<<endl;
	}
	while(datafile>>number)
	{
		int se,m,h,d,m1,y;
		char d1,d2,d3,d4,d5;
		datafile>>se>>d1>>m>>d2>>h>>d3>>d>>d4>>m1>>d5>>y;
		tincome=tincome+number;
	}
	datafile.clear();
	cout<<"总收入:"<<tincome<<endl;
	return 1;
}

int main()
{
	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<<"                   二.请先在D盘建立四个文件夹"<<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=charge();
		}
		if(c=='a')
		{
			cout<<"                       收银系统----------------1"<<endl;
			cout<<"                       返  回------------------2"<<endl;
			cout<<"                       退  出------------------3"<<endl;
			cin>>k;
		if(k==2)
		{c=2;continue;}
		while(k==1)
		{    
			int flag3=0;
			if(flag1==0) p=shouying_system();
			if(p==1) {flag2=productpay_system();}
			if(p==2) {flag2=member_system();}
			if(p==3) {flag2=vip_system();}
			if(p==4) {flag2=productmanage_system();}  
			if(p==5) {flag3=1;flag2=showincome_system();}
			if(p==6) {k=2; flag1=0; flag2=0; continue;}
			if(flag2==1)     
			{
				if(flag3==0) system("cls"); 
				p=shouying_system();
				flag1=1;
			}
		}
		if(k==3)
		exit(1);
		}
	if(c==2)  exit(1);
	}
	return 0;
}

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

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



  • 29
    点赞
  • 196
    收藏
    觉得还不错? 一键收藏
  • 16
    评论
以下是一个简单的Python超市收银系统的例子: ```python # 导入必要的库 import tkinter as tk import tkinter.messagebox as msgbox import sqlite3 # 连接数据库 conn = sqlite3.connect('market.db') c = conn.cursor() # 创建商品表 c.execute('''CREATE TABLE IF NOT EXISTS products (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, barcode TEXT NOT NULL, price REAL NOT NULL, quantity INTEGER NOT NULL)''') # 创建用户表 c.execute('''CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL, password TEXT NOT NULL, is_admin INTEGER NOT NULL)''') # 插入管理员用户 c.execute("INSERT OR IGNORE INTO users (username, password, is_admin) VALUES (?, ?, ?)", ('admin', 'admin', 1)) # 提交更改 conn.commit() # 创建主窗口 root = tk.Tk() root.title('超市收银系统') # 创建登录窗口 class LoginWindow: def __init__(self, master): self.master = master self.master.title('登录') self.master.geometry('300x200') self.master.resizable(False, False) # 创建用户名和密码标签和输入框 tk.Label(self.master, text='用户名:').grid(row=0, column=0, padx=10, pady=10) self.username_entry = tk.Entry(self.master) self.username_entry.grid(row=0, column=1, padx=10, pady=10) tk.Label(self.master, text='密码:').grid(row=1, column=0, padx=10, pady=10) self.password_entry = tk.Entry(self.master, show='*') self.password_entry.grid(row=1, column=1, padx=10, pady=10) # 创建登录和退出按钮 tk.Button(self.master, text='登录', command=self.login).grid(row=2, column=0, padx=10, pady=10) tk.Button(self.master, text='退出', command=self.master.destroy).grid(row=2, column=1, padx=10, pady=10) # 登录函数 def login(self): # 获取用户名和密码 username = self.username_entry.get() password = self.password_entry.get() # 查询用户 c.execute("SELECT * FROM users WHERE username=? AND password=?", (username, password)) user = c.fetchone() # 判断用户是否存在 if user is None: msgbox.showerror('错误', '用户名或密码错误!') else: # 判断用户是否为管理员 if user[3] == 1: AdminWindow(self.master) else: UserWindow(self.master) # 创建管理员窗口 class AdminWindow: def __init__(self, master): self.master = master self.master.title('管理员界面') self.master.geometry('500x400') self.master.resizable(False, False) # 创建商品列表 self.product_list = tk.Listbox(self.master, width=50) self.product_list.grid(row=0, column=0, columnspan=2, padx=10, pady=10) # 查询商品 c.execute("SELECT * FROM products") products = c.fetchall() # 显示商品 for product in products: self.product_list.insert(tk.END, f'{product[1]} - {product[2]} - ¥{product[3]} - 库存:{product[4]}') # 创建添加商品按钮 tk.Button(self.master, text='添加商品', command=self.add_product).grid(row=1, column=0, padx=10, pady=10) # 创建修改商品按钮 tk.Button(self.master, text='修改商品', command=self.edit_product).grid(row=1, column=1, padx=10, pady=10) # 创建查询商品按钮 tk.Button(self.master, text='查询商品', command=self.search_product).grid(row=2, column=0, padx=10, pady=10) # 创建退出按钮 tk.Button(self.master, text='退出', command=self.master.destroy).grid(row=2, column=1, padx=10, pady=10) # 添加商品函数 def add_product(self): # 创建添加商品窗口 add_product_window = tk.Toplevel(self.master) add_product_window.title('添加商品') add_product_window.geometry('300x200') add_product_window.resizable(False, False) # 创建商品名称、条码、价格和数量标签和输入框 tk.Label(add_product_window, text='商品名称:').grid(row=0, column=0, padx=10, pady=10) name_entry = tk.Entry(add_product_window) name_entry.grid(row=0, column=1, padx=10, pady=10) tk.Label(add_product_window, text='商品条码:').grid(row=1, column=0, padx=10, pady=10) barcode_entry = tk.Entry(add_product_window) barcode_entry.grid(row=1, column=1, padx=10, pady=10) tk.Label(add_product_window, text='商品价格:').grid(row=2, column=0, padx=10, pady=10) price_entry = tk.Entry(add_product_window) price_entry.grid(row=2, column=1, padx=10, pady=10) tk.Label(add_product_window, text='商品数量:').grid(row=3, column=0, padx=10, pady=10) quantity_entry = tk.Entry(add_product_window) quantity_entry.grid(row=3, column=1, padx=10, pady=10) # 创建添加按钮 tk.Button(add_product_window, text='添加', command=lambda: self.add_product_to_database(name_entry.get(), barcode_entry.get(), price_entry.get(), quantity_entry.get(), add_product_window)).grid(row=4, column=0, padx=10, pady=10) # 添加商品到数据库函数 def add_product_to_database(self, name, barcode, price, quantity, window): # 判断商品是否已存在 c.execute("SELECT * FROM products WHERE barcode=?", (barcode,)) product = c.fetchone() if product is None: # 插入商品 c.execute("INSERT INTO products (name, barcode, price, quantity) VALUES (?, ?, ?, ?)", (name, barcode, price, quantity)) conn.commit() # 更新商品列表 self.product_list.insert(tk.END, f'{name} - {barcode} - ¥{price} - 库存:{quantity}') # 关闭添加商品窗口 window.destroy() else: msgbox.showerror('错误', '商品已存在!') # 修改商品函数 def edit_product(self): # 获取选中的商品 selected_product = self.product_list.curselection() if len(selected_product) == 0: msgbox.showerror('错误', '请选择要修改的商品!') else: # 获取选中的商品信息 product_info = self.product_list.get(selected_product[0]) product_name, product_barcode, product_price, product_quantity = product_info.split(' - ') # 创建修改商品窗口 edit_product_window = tk.Toplevel(self.master) edit_product_window.title('修改商品') edit_product_window.geometry('300x200') edit_product_window.resizable(False, False) # 创建商品名称、条码、价格和数量标签和输入框 tk.Label(edit_product_window, text='商品名称:').grid(row=0, column=0, padx=10, pady=10) name_entry = tk.Entry(edit_product_window) name_entry.insert(tk.END, product_name) name_entry.grid(row=0, column=1, padx=10, pady=10) tk.Label(edit_product_window, text='商品条码:').grid(row=1, column=0, padx=10, pady=10) barcode_entry = tk.Entry(edit_product_window) barcode_entry.insert(tk.END, product_barcode) barcode_entry.grid(row=1, column=1, padx=10, pady=10) tk.Label(edit_product_window, text='商品价格:').grid(row=2, column=0, padx=10, pady=10) price_entry = tk.Entry(edit_product_window) price_entry.insert(tk.END, product_price[1:]) price_entry.grid(row=2, column=1, padx=10, pady=10) tk.Label(edit_product_window, text='商品数量:').grid(row=3, column=0, padx=10, pady=10) quantity_entry = tk.Entry(edit_product_window) quantity_entry.insert(tk.END, product_quantity.split(':')[1]) quantity_entry.grid(row=3, column=1, padx=10, pady=10) # 创建修改按钮 tk.Button(edit_product_window, text='修改', command=lambda: self.edit_product_in_database(selected_product[0], name_entry.get(), barcode_entry.get(), price_entry.get(), quantity_entry.get(), edit_product_window)).grid(row=4, column=0, padx=10, pady=10) # 修改商品在数据库中的信息函数 def edit_product_in_database(self, index, name, barcode, price, quantity, window): # 更新商品 c.execute("UPDATE products SET name=?, barcode=?, price=?, quantity=? WHERE id=?", (name, barcode, price, quantity, index + 1)) conn.commit() # 更新商品列表 self.product_list.delete(index) self.product_list.insert(index, f'{name} - {barcode} - ¥{price} - 库存:{quantity}') # 关闭修改商品窗口 window.destroy() # 查询商品函数 def search_product(self): # 创建查询商品窗口 search_product_window = tk.Toplevel(self.master) search_product_window.title('查询商品') search_product_window.geometry('300x200') search_product_window.resizable(False, False) # 创建查询标签和输入框 tk.Label(search_product_window, text='查询:').grid(row=0, column=0, padx=10, pady=10) search_entry = tk.Entry(search_product_window) search_entry.grid(row=0, column=1, padx=10, pady=10) # 创建查询按钮 tk.Button(search_product_window, text='查询', command=lambda: self.search_product_in_database(search_entry.get(), search_product_window)).grid(row=1, column=0, padx=10, pady=10) # 在数据库中查询商品函数 def search_product_in_database(self, keyword, window): # 查询商品 c.execute("SELECT * FROM products WHERE name LIKE ? OR barcode LIKE ?", (f'%{keyword}%', f'%{keyword}%')) products = c.fetchall() # 显示商品 self.product_list.delete(0, tk.END) for product in products: self.product_list.insert(tk.END, f'{product[1]} - {product[2]} - ¥{product[3]} - 库存:{product[4]}') # 关闭查询商品窗口 window.destroy() # 创建普通用户窗口 class UserWindow: def __init__(self, master): self.master = master self.master.title('用户界面') self.master.geometry('500x400') self.master.resizable(False, False) # 创建商品列表 self.product_list = tk.Listbox(self.master, width=50) self.product_list.grid(row=0, column=0, columnspan=2, padx=10, pady=10) # 查询商品 c.execute("SELECT * FROM products") products = c.fetchall() # 显示商品 for product in products: self.product_list.insert(tk.END, f'{product[1]} - {product[2]} - ¥{product[3]} - 库存:{product[4]}') # 创建查询商品按钮 tk.Button(self.master, text='查询商品', command=self.search_product).grid(row=1, column=0, padx=10, pady=10) # 创建退出按钮 tk.Button(self.master, text='退出', command=self.master.destroy).grid(row=1, column=1, padx=10, pady=10) # 查询商品函数 def search_product(self): # 创建查询商品窗口 search_product_window = tk.Toplevel(self.master) search_product_window.title('查询商品') search_product_window.geometry('300x200') search_product_window.resizable(False, False) # 创建查询标签和输入框 tk.Label(search_product_window, text='查询:').grid(row=0, column=0, padx=10, pady=10) search_entry = tk.Entry(search_product_window) search_entry.grid(row=0, column=1, padx=10, pady=10) # 创建查询按钮 tk.Button(search_product_window, text='查询', command=lambda: self.search_product_in_database(search_entry.get(), search_product_window)).grid(row=1, column=0, padx=10, pady=10) # 在数据库中查询商品函数 def search_product_in_database(self, keyword, window): # 查询商品 c.execute("SELECT * FROM products WHERE name LIKE ? OR barcode LIKE ?", (f'%{keyword}%', f'%{keyword}%')) products = c.fetchall() # 显示商品 self.product_list.delete(0, tk.END) for product in products: self.product_list.insert(tk.END, f'{product[1]} - {product[2]} - ¥{product[3]} - 库存:{product[4]}') # 关闭查询商品窗口 window.destroy() # 创建登录窗口 LoginWindow(root) # 运行主循环 root.mainloop() ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值