⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 consumer.cpp

📁 个人爱好,自己编的小代码.仅供参考
💻 CPP
字号:
#include"globle.h"
#include"consumer.h"
#include"management.h"
#include"deallog.h"
void consumer::SetConsumerType()      //设置消费者类型
{
	cout<<"请选择顾客类型:\n";
	cout<<"1。会员;2。非会员;\n";
	int choice;
	cin>>choice;
	switch(choice)
	{
	case 1:
		consumerType=1;
		break;
	case 2:
        consumerType=0;
		break;
	default:
		cout<<"您输入了错误的选择!\n";
		break;
	}
}
void consumer::GetConsumerType()          //得到消费者类型
{   
	if(consumerType)
		cout<<"会员\n";
	else
		cout<<"非会员。\n";

}
void consumer::BuyAGoods(vector<goods>&g)  //购物
{
	ofstream outDealLog("DealLogStack.txt",ios::out|ios::app);
    GoodsManagementSystem gm;
	int i=0,j=0;int l=0;
	gm.readGoodsFile(g);
	if(g.empty())
	{
		cout<<"没有货物!\n";
		return;
	}
	cout<<"商品序号"<<setw(10)<<"商品名称"<<setw(10)<<"价格"
		<<setw(10)<<"现有量"<<endl;
	vector<goods>::iterator p;
	for(p=g.begin();p!=g.end();p++,l++)
	{ cout<<l;	p->printGoods();}
	cout<<"请选择要买的商品:";
	cin>>i;
	cout<<"要买几件?";
	cin>>j;
	if(g.at(i).currentInStorck-j>0)
	{
		g.at(i).currentInStorck-=j;
		if(consumerType)
			payment=g.at(i).getPrice()*j*g.at(i).discount;
		else
			payment=g.at(i).getPrice()*j;
		grade+=j;
		cout<<"购物成功!";
	    deallog deallog(g.at(i).goodsName,j,memberNumber,payment,1);
		outDealLog.write(reinterpret_cast<char *>(&deallog),
			sizeof(deallog));
		gm.putGoodsInFile(g);
	}
	else 
	{
		cout<<"该商品库存不够是否购买其它商品?(y/n)";
	    char c;
	    cin>>c;
		if(c=='y')
			BuyAGoods(g);
		else 
			return;
	}
	outDealLog.close();
	return;
}
void consumer::changeGoods(vector<goods>&g)            //用积分换商品
{
	ofstream outDealLog("DealLogStack.txt",ios::out|ios::app);
	GoodsManagementSystem gm;
	int i=0;int l=0;
	gm.readGoodsFile(g);
	if(g.empty())
	{
		cout<<"没有货物!\n";
		return;
	}
	cout<<"商品序号"<<setw(10)<<"商品名称"<<setw(10)<<"价格"
		<<setw(10)<<"现有量"<<endl;
	vector<goods>::iterator p;
	for(p=g.begin();p!=g.end();p++,l++)
	{ cout<<l;	p->printGoods();}
	cout<<"请选择要换的商品:";
	cin>>i;
	if(grade>g.at(i).changeGrade||grade==g.at(i).changeGrade)
	{
		if(g.at(i).currentInStorck>1)
		{
			g.at(i).currentInStorck-=1;
			grade-=g.at(i).changeGrade;
			cout<<"购物成功!";
	    deallog deallog(g.at(i).goodsName,1,memberNumber,payment,0);
		outDealLog.write(reinterpret_cast<char *>(&deallog),
			sizeof(deallog));
		gm.putGoodsInFile(g);
		}
		else
			cout<<"数额限度不能购物!";
	}
	else
		cout<<"积分不足!";
	outDealLog.close();
}
	
void consumer::checkDeallog(vector<deallog>&dg)       //查询交易记录
{
	GoodsManagementSystem gm;
	gm.readDeallogFile(dg);
	if(dg.empty())
	{
		cout<<"没有记录!\n";
		return;
	}
	vector<deallog>::iterator p1;
	cout<<"商品名称"<<setw(10)<<"购买数量"<<setw(13)<<"消费者号码"
        <<setw(10)<<"消费金额"<<setw(20)<<"购物日期"<<setw(15)<<"消费方式"<<endl;
	for(p1=dg.begin();p1!=dg.end();p1++)
	if(p1->getMemberNumber()==getMemberNumber())
	     p1->printDealLog();
}
	
void consumer::printAmember()                         //打印会员信息
{
	cout<<"会员号码:"<<getMemberNumber()<<"\n";
	cout<<"积分"<<grade<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -