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

📄 商品管理.h

📁 这个系统功能稍微简单了
💻 H
字号:
class Commodity
{
public:
	int NO;
	char name[10];
	int styleCode;
	char in_Price[10];
	char out_Price[10];
	int store;
	int linjiezhi;
	char in_Time[12];
	char baozhi[12];

	void addItem();    //增加商品
	void delItem();    //删除商品
	void checkQuantity();   //检查库存
	void totalMessage();
	void checkQuality();
	friend void in_Message();
	friend void out_Message();
};

#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>

static int m,k,t;  Commodity aa[50];
void in_Message()
{
    ifstream p;
	p.open("D:\\商品信息.txt",ios::nocreate);
	if(!p.is_open())
	{cout<<"没有任何商品信息!! 返回上级! \n"; return;}
    m=0;
	while(!p.eof())
	{  p>>aa[m].name>>aa[m].NO>>aa[m].styleCode>>aa[m].store>>aa[m].in_Price>>aa[m].out_Price
	     >>aa[m].in_Time>>aa[m].baozhi;
		m++;}
	p.close();
}
void out_Message()
{
	ofstream p;
	p.open("D:\\商品信息.txt");
    for(k=0;k<m-1;k++)
		p<<setw(8)<<aa[k].name<<setw(6)<<aa[k].NO<<setw(5)<<aa[k].styleCode<<setw(6)<<aa[k].store
		    <<setw(11)<<aa[k].in_Price<<setw(11)<<aa[k].out_Price<<setw(12)<<aa[k].in_Time<<setw(12)<<aa[k].baozhi<<endl;
	p.close();
}
class Food:public Commodity
{public:
  void checkQuality(char* date)
	{ 
	  if(strcmp(date,aa[k].baozhi)>0)
		  cout<<aa[k].name<<"已过期,请及时更换! \n"; t++;}
};
class Dress:public Commodity
{public:
   void checkQuality(char *season)
	{  
	   if(strcmp(season,aa[k].baozhi)!=0)
	   {  cout<<aa[k].name<<"已过季,请降价!  "; t++;
	      cout<<"想要现在降价请按y,其他键退出:\n";
	      char n;
		  cin>>n;
		  if(n=='y'||n=='Y')
		  {cout<<aa[k].name<<"的进价为: "<<aa[k].in_Price<<"  售价为: "<<aa[k].out_Price<<endl
			   <<"请输入降低后价钱: ";
		   cin>>aa[k].out_Price;
		   cout<<"操作成功!\n";}
   }}
};
class Appliance:public Commodity
{public:
  void checkQuality(char* date)
	{
	  if(strcmp(date,aa[k].baozhi)>0)
		  cout<<aa[k].name<<"已过更新期,请及时更换! \n"; t++;}
};  


void Commodity::addItem()
{
    fstream p;
	p.open("D:\\商品信息.txt",ios::in);
    m=0;
	while(!p.eof())
	{  p>>aa[m].name>>aa[m].NO>>aa[m].styleCode>>aa[m].store>>aa[m].in_Price
	     >>aa[m].out_Price>>aa[m].in_Time>>aa[m].baozhi;
	   m++;}
	p.close();
	
	Commodity b;
	cout<<"请输入新添商品信息:\n";
	cout<<"名称: ";
	cin>>b.name;
    for(k=0;k<m-1;k++)
		if(strcmp(b.name,aa[k].name)==0)
		{  cout<<"此商品已存在,请输入要增添数量:\n";
		   int x;
		   cin>>x;
		   aa[k].store+=x;
		   cout<<"添加成功!\n";
	       return;
		}
    cout<<"编号: ";
	cin>>b.NO; 
	cout<<"类型代码(1食品2服装3电器): ";
	cin>>b.styleCode;
	cout<<"数量: ";
	cin>>b.store;
	cout<<"进价: ";
	cin>>b.in_Price;
	cout<<"售价: ";
	cin>>b.out_Price;
	cout<<"进货时间(以0000/00/00形式写出,下同!): ";
	cin>>b.in_Time;
	cout<<"保质期(食品)/季节(服装)/更新期(电器): ";
	cin>>b.baozhi;
	p.open("D:\\商品信息.txt",ios::app|ios::out);
    p<<setw(8)<<b.name<<setw(6)<<b.NO<<setw(5)<<b.styleCode<<setw(6)<<b.store
	    <<setw(11)<<b.in_Price<<setw(11)<<b.out_Price<<setw(12)<<b.in_Time<<setw(12)<<b.baozhi<<endl;
	p.close();
}

void Commodity::delItem()
{
	in_Message();
	ofstream p;
	p.open("D:\\商品信息.txt");
	cout<<"请输入要删除商品的编号: ";
	int n=0;
    cin>>n;
	for(k=0;k<m-1;k++)
		if(n!=aa[k].NO)
		p<<setw(8)<<aa[k].name<<setw(6)<<aa[k].NO<<setw(5)<<aa[k].styleCode<<setw(6)<<aa[k].store
		    <<setw(11)<<aa[k].in_Price<<setw(11)<<aa[k].out_Price<<setw(12)<<aa[k].in_Time<<setw(12)<<aa[k].baozhi<<endl;
	p.close();
	cout<<"删除成功!!\n";
}

void Commodity::totalMessage()
{
	in_Message();
	cout<<setw(8)<<"名称"<<setw(6)<<"编号"<<setw(5)<<"类码"<<setw(6)<<"库存"
	      <<setw(11)<<"进价"<<setw(11)<<"售价"<<setw(12)<<"进货时间"<<setw(12)<<"质期"<<endl;
	for(k=0;k<m-1;k++)
	{  cout<<setw(8)<<aa[k].name<<setw(6)<<aa[k].NO<<setw(5)<<aa[k].styleCode<<setw(6)<<aa[k].store
	        <<setw(11)<<aa[k].in_Price<<setw(11)<<aa[k].out_Price<<setw(12)<<aa[k].in_Time<<setw(12)<<aa[k].baozhi<<endl;}
}

void Commodity::checkQuantity()
{
	in_Message();   
	linjiezhi=10;
	int q=0;      // q用来判断是否存在库存不足的情况
	for(k=0;k<m-1;k++)
		if(aa[k].store<linjiezhi)
		{cout<<aa[k].name<<"的库存不足! 需要进货!\n"; q++;}
	if(q==0)
		cout<<"商品数量充足!\n";
}

void Commodity::checkQuality()
{
	Food a1; Dress a2; Appliance a3; char date[10],season[10];
	in_Message();
    cout<<"请输入今天的日期(年/月/日); 季节(春/夏/秋/冬): \n";
    cin>>date>>season;
	for(k=0;k<m-1;k++)
	{if(aa[k].styleCode==1)
			a1.checkQuality(date);
		if(aa[k].styleCode==2)
			a2.checkQuality(season);
		if(aa[k].styleCode==3)
			a3.checkQuality(date);}
	if(t!=0)
		cout<<"此批商品不存在过期,过季等问题!\n";
	out_Message();
}

⌨️ 快捷键说明

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