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

📄 ckgl.cpp

📁 能够实现简单的管理功能。能够输入
💻 CPP
字号:
#include<iostream>
#include<fstream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
using namespace std;
int j,p;
static int count=0;
struct Goods
{
	int bh;
	char name[20];
	int kc;
	int price;
}goods[20];
class operation
{
public:void goon();
	   void view();
	   void add();
	   void change();
	   void find();
	   void del();
	   void save();
	   void read();
	   void tc();
};
void operation::goon()
{
	extern int main();
	char a;
	int x;
	cout<<endl<<"是否继续操作(y/n):";
	do
	{
		cin>>a;
		if(a=='Y'||a=='y')
			main();
		else if(a=='N'||a=='n')
			tc();
		else
		{
			x=1;
		    cout<<"请正确选择(y/n):";
		}
	}while(x==1);

}
void operation::tc()
{
	cout<<"@@@@@@@@@@@@@@@@@@@@@@@@\n";
	cout<<" ^_^感谢您使用本系统^_^\n";
	cout<<" ^_^欢迎下次继续使用^_^\n";
	cout<<"@@@@@@@@@@@@@@@@@@@@@@@@\n";
}
void operation::view()
{
	char line[23];
	int i;
	ifstream infile("goods.txt",ios_base::in);
	for(i=0;i<count+3;i++)
	{
		infile.getline(line,100);
		cout<<line<<endl;
	}
	infile.close();
	goon();
}
void operation::add()
{
	int i,addnum;
	cout<<"你想增加多少条记录:";
	cin>>addnum;
	cout<<setiosflags(ios_base::left)<<setw(10)<<"编号"<<setw(10)<<"名称"<<setw(10)<<"库存"<<setw(10)<<"单价"<<endl;
	for(i=count;i<count+addnum;i++)
		cin>>goods[i].bh>>goods[i].name>>goods[i].kc>>goods[i].price;
	cout<<"你增添了"<<addnum<<"条记录,总共有"<<count+addnum<<"条记录"<<endl;
	count+=addnum;
	save();
	goon();
}
void operation::change()
{
	int cnum,ckc,cprice;
	int num,i;
	char cname[20];
	cout<<"请输入你要更改的货物信息的编号:";
	cin>>num;
	for(i=0;i<count;i++)
		if(num==goods[i].bh)
		{
			cout<<"你要更改的货物信息如下:"<<endl;
			cout<<setiosflags(ios_base::left)<<setw(10)<<"编号"<<setw(10)<<"名称"<<setw(10)<<"库存"<<setw(10)<<"单价"<<endl;
			cout<<setw(10)<<goods[i].bh<<setw(10)<<goods[i].name<<setw(10)<<goods[i].kc<<setw(10)<<goods[i].price<<endl;		    
		    cout<<"请更新信息:"<<endl;
		    cout<<setw(10)<<"编号"<<setw(10)<<"名称"<<setw(10)<<"库存"<<setw(10)<<"单价"<<endl;
		    cin>>cnum>>cname>>ckc>>cprice;
		    goods[i].bh=cnum;
		    strcpy(goods[i].name,cname);
		    goods[i].kc=ckc;
		    goods[i].price=cprice;
		    save();
			break;
		}
		else 
			cout<<"没有你要更新的货物信息"<<endl;
		goon();
}
void operation::find()
{
	int i,j1,j2,a,num;
	char b[20];
	cout<<"1.按编号查找"<<' '<<"2.按名称查找"<<endl;
	cin>>a;
	if(a==1)
	{
		cout<<"请输入你要查找的货物编号:";
	    cin>>num;
		for(i=0;i<count;i++)
		{
			if(goods[i].bh==num)
			{
				j1=1;
				break;
			}
			else j1=0;
		}		
		switch(j1)
		{
		case 1:	cout<<"你查找的货物信息如下:"<<endl;
			    cout<<setw(10)<<"编号"<<setw(10)<<"名称"<<setw(10)<<"库存"<<setw(10)<<"单价"<<endl;
				cout<<setw(10)<<goods[i].bh<<setw(10)<<goods[i].name<<setw(10)<<goods[i].kc<<setw(10)<<goods[i].price<<endl;
				break;
		case 2: cout<<"没有你要查找的信息!"<<endl;break;		
		}	 			
	}
	else if(a==2)
	{
		cout<<"请输入你要查找的货物的名称:";
		cin>>b;
		for(i=0;i<count;i++)
		{
			if(strcmp(b,goods[i].name)==0)
			{
				j2=1;
				break;
			}
			else j2=0;
		}
		switch(j2)
		{
		case 1:	cout<<"你查找的货物信息如下:"<<endl;
				cout<<setw(10)<<"编号"<<setw(10)<<"名称"<<setw(10)<<"库存"<<setw(10)<<"单价"<<endl;
				cout<<setw(10)<<goods[i].bh<<setw(10)<<goods[i].name<<setw(10)<<goods[i].kc<<setw(10)<<goods[i].price<<endl;
				break;			
		case 2:	cout<<"没有你要查找的信息!"<<endl;
		}
	}
	else 
		cout<<"对不起,没有你要的选择!"<<endl;
	goon();
}
void operation::del()
{
	int i=0,m=0,delnum;
	int count2=count;
	char ch1,ch2;
	do{
		cout<<"请输入你想删除的货物编号:"<<endl;
		cin>>delnum;
		for(i=0;i<count;i++)
			if(delnum==goods[i].bh)
			{
				for(m=i;m<count-1;m++)
				{
					goods[m]=goods[i];
					if(m==delnum)
						goods[m]=goods[i+1];
				}
				count--;
			    break;		
			}
			else
				cout<<"没有你要删除的信息!"<<endl;
			cout<<"还要继续删除吗?(y/n)"<<endl;
			cin>>ch1;
	}while(ch1=='Y'||ch1=='y');
	if(count!=count2)
	{
		cout<<"是否保存所做的操作?(y/n)"<<endl;
		cin>>ch2;
		if(ch2=='Y'||ch2=='y')
			save();
	}
	goon();
}
void operation::save()
{
	ofstream outfile;
	outfile.open("goods.txt");
	outfile<<"*********货物信息如下**********"<<endl<<endl;
	outfile<<setiosflags(ios_base::left)<<setw(10)<<"编号"<<setw(10)<<"名称"<<setw(10)<<"库存"<<setw(10)<<"单价"<<endl;
	for(int i=0;i<count;i++)
		outfile<<setw(10)<<goods[i].bh<<setw(10)<<goods[i].name<<setw(10)<<goods[i].kc<<setw(10)<<goods[i].price<<endl;
	outfile.close();
	cout<<"文件保存成功!"<<endl;
}
extern int main()
{
	operation g;
	int p;
	cout<<"欢迎进入仓库管理系统!"<<endl;
	cout<<"*******************************************************"<<endl;
	cout<<"1.浏览货物信息    "<<"2.添加货物信息  "<<"3.更改货物信息"<<endl;
	cout<<"4.查找货物信息    "<<"5.删除货物信息  "<<"6.退出系统    "<<endl;
	cout<<"*******************************************************"<<endl;
	cout<<"请选择要进行的操作1-6:";
	cin>>p;
	switch(p)
	{
	case 1:g.view();break;
	case 2:g.add();break;
	case 3:g.change();break;
    case 4:g.find();break;
    case 5:g.del();break;
	case 6:g.tc();
	}
	return 0;
}



⌨️ 快捷键说明

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