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

📄 5_2.cpp

📁 物品存放的管理C++源程序 用于管理物品的小软件 适合课程设计
💻 CPP
📖 第 1 页 / 共 3 页
字号:
 /*第2题	物品库存管理--源代码及关键源代码注解如下:*/
// file operations
#include<iostream.h>
#include<iomanip.h>
#include<process.h>      //exit(1)
#include<fstream.h>      //file operations
#include<string.h>
#include<dos.h>

int lgwg,num,i,flag=1;	
char pause;

void welcome();

void clear(char* p)
{
	ofstream temp(p, ios::out);
	temp.close();
	if(lgwg==1) cout<<"Cleared.\tPress Enter to continue";
	else cout<<"已清空。\t按回车继续";
	cin.ignore();cin.get(pause);
}

class Brand
{
private:		
	int Brand_code;	
	int quantity;
	float brnd_price;
	char brnd_name[20];
public:
	Brand()
	{
		brnd_name[0]=NULL;
	}
	void getdata();
	void showdata();
	char *rtnname() {return brnd_name;}
	float rtnprice() {return brnd_price;}
};

class Item
{
private:
	char Item_name[10];
	int Item_code;
	char colour[10];
	int quantity;
	Brand brnd[9];
	//Private Member functions used internally
	void getdata();
	void showdata();
public:
	void add();
	void remove();
	void search();
	void showab();
	char *rtnname() {return Item_name;}
	int rtncode() {return Item_code;}
	int rtnqtt() {return quantity;}
};

class Trade
{
    private:		
		int Trade_code;	
		int quantity;
		char item[20];
	public:
		Trade()
		{
			item[0]=NULL;
		}
		void getdata();
		void showdata();
		char *rtnname() {return item;}
};

class Guest
{
	
	private:
		char Guest_name[10];
		int Guest_code;
		char Phone_NO[10];
		int quantity;
		Trade trd[9];
		void getdata();
		void showdata();
	public:
		void add();
		void remove();
		void search();
		void showag();
};

class IE
{
private:
	char date_month[6];
	char date_day[6];
	char date_year[6];
	char item_name[10];
	int item_code;
	int item_quantity;
	int condition;
public:
	IE()
	{
		strcpy(date_year,"\0\0\0\0\0\0");
		strcpy(date_month,"\0\0\0\0\0\0");
		strcpy(date_day,"\0\0\0\0\0\0\0");
	}
	void showdata();
	void show();
	void search();
	void IEport(Item,int);
};

//   GET Brand DATA
//	 gets data about the Brand
//	 it is temperary storage

void Brand::getdata()
{
	switch(lgwg)
	{
	case 1:
		cout<<"\n\nEnter Brand Name   ";
		cin.ignore();
		cin.getline(brnd_name,20);
		cout<<"\nEnter Brand Code ";
		cin>>Brand_code;
		cout<<"\nEnter Quantity ";
		cin>>quantity;
		cout<<"\nEnter Price ";
		cin>>brnd_price;
		break;
    case 2:
		cout<<"\n\n请输入商标名称: ";
		cin.ignore();
		cin.getline(brnd_name,20);
		cout<<"\n请输入商标编号: ";
		cin>>Brand_code;
		cout<<"\n请输入物品数量: ";
		cin>>quantity;
		cout<<"\n请输入物品价格: ";
		cin>>brnd_price;
	}
}

//	SHOW Brand DATA 
//  shows the data of the Brand

void Brand::showdata()
{
	switch(lgwg)
	{
	case 1:
		cout<<"\n\nName          :  "; cout<<brnd_name;
		cout<<"\n\nCode          :  "; cout<<Brand_code;
		cout<<"\n\nQuantity      :  "; cout<<quantity;
		cout<<"\n\nPrice         :  "; cout<<brnd_price<<endl;
		break;
	case 2:
		cout<<"\n\n商标名称      :  "; cout<<brnd_name;
		cout<<"\n\n商标编号      :  "; cout<<Brand_code;
		cout<<"\n\n物品数量      :  "; cout<<quantity;
		cout<<"\n\n物品价格      :  "; cout<<brnd_price<<endl;
	}
}

//	GET Item DATA 
//  gets data about the Item	it is temporary storage
      
void Item::getdata()	
{
	switch(lgwg)
	{
	case 1:
		cout<<"\nEnter Item Name ";
		cin.ignore();
		cin.getline(Item_name,10);
		cout<<"\nEnter Item Code  ";
		cin>>Item_code;
		cout<<"\nEnter Colour ";
		cin.ignore();
		cin.getline(colour,10);
		cout<<"\nEnter Item Quantity ";
		cin>>quantity;
		cout<<"\nEnter Brand Quantity (Less than nine) ";
		cin>>num;
		for(i=0;i<num;i++)
		{
			cout<<"\n\nEnter Brand "<<i+1;
			brnd[i].getdata();
		}
		i=0;
		break;
	case 2:
		cout<<"\n请输入物品名称: ";
		cin.ignore();
		cin.getline(Item_name,10);
		cout<<"\n请输入物品编号: ";
		cin>>Item_code;
		cout<<"\n请输入物品颜色: ";
		cin.ignore();
		cin.getline(colour,10);
		cout<<"\n请输入物品数量: ";
		cin>>quantity;
		cout<<"\n请输入商标数量(九个以内): ";
		cin>>num;
		for(i=0;i<num;i++)
		{
			cout<<"\n\n请输入第"<<i+1<<"个商标数据: ";
			brnd[i].getdata();
		}
		i=0;
	}
}

//	SHOW Item DATA
//  shows data about the Item

void Item::showdata()	
{
	switch(lgwg)
	{
	case 1:
		cout<<"\n\n\t\tItem Data";
		cout<<"\n\nItem Name    :  ";
		cout<<Item_name;
		//Write a string to stdout
		cout<<"\n\nItem Code    :  ";
		cout<<Item_code;
		cout<<"\n\nColour       :  ";
		cout<<colour;
		cout<<"\n\nQuantity     :  ";
		cout<<quantity;
		cout<<"\n\nPress Enter to continue.";cin.get(pause);
		//clrscr();
		while(*brnd[i].rtnname())
		{
			cout<<"\n\nBrand "<<i+1<<endl; brnd[i].showdata();
			i++;
			cout<<"\n\nPress Enter to continue.";cin.get(pause);
			//clrscr();
		}
		i=0;
		break;
	case 2:
		cout<<"\n\n\t\t物品数据";
		cout<<"\n\n物品名称     :  ";
		cout<<Item_name;
		//Write a string to stdout
		cout<<"\n\n物品编码     :  ";
		cout<<Item_code;
		cout<<"\n\n物品颜色     :  ";
		cout<<colour;
		cout<<"\n\n物品数量     :  ";
		cout<<quantity;
		cout<<"\n\n按回车继续";cin.get(pause);
		//clrscr();
		while(*brnd[i].rtnname())
		{
			cout<<"\n\n第"<<i+1<<"个商标\n"; brnd[i].showdata();
			i++;
			cout<<"\n\n按回车继续";cin.get(pause);
			//clrscr();
		}
		i=0;
	}
}

//	Add Item
// this function first gets data into temp storage then saves it on the hard disk

void Item::add()	
{
	//clrscr();
	ofstream file( "TIS.DAT", ios::out |ios::ate ); //open file for input
	if(!file)   //if file could not be opened
	{
		if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
		else cout<<"错误!无法打开文件。\n\n按回车继续";
		cin.ignore();cin.get(pause);
		exit(1);
	}
	Item p1;
	p1.getdata();       //Get Data From User For Temp. Storage
	//   write data to hard disk
    file.write(reinterpret_cast <const char *> (&p1),sizeof(Item) );
	if(lgwg==1) cout<<"Do You Want to Refresh The IES ?\tYes(y)/No(n)";
	else cout<<"\n是否更新进出口统计表 ?\t是(y)/否(n)";
	char chc;
	cin>>chc;
	if(chc=='y')
	{
		IE t1;
		t1.IEport(p1,1);
		ofstream file1( "IES.DAT", ios::out |ios::ate );
		file1.write(reinterpret_cast <const char *> (&t1),sizeof(IE) );
	}
}

// TRAVERSE
//  this function shows the list of all the Brands 

void Item::showab()  	
{
	system("cls");//clrscr();
	ifstream file( "TIS.DAT" ,ios::in);  //open file for output
	if(!file)   //if file could not be opened
	{
		if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
		else cout<<"错误!无法打开文件。\n\n按回车继续";
		cin.ignore();cin.get(pause);
		exit(1);
	}
	Item p1;
	file.read(reinterpret_cast<char *>(&p1),sizeof(Item));
	//Store Data In Object
	cin.ignore();
	while(!file.eof()) //Untill Contacts Present
	{
		//clrscr();
		p1.showdata() ;  //Display on Screen
		file.read(reinterpret_cast<char *> (&p1),sizeof(Item)); //Read Next Contact
	}
}

//   SEARCH 

void Item::search()   	
{
node1:	
	//clrscr();
	char name1[10]={NULL};
	int code=-1;
	int option;
	float prc=-1;
	system("cls");
	if(lgwg==1) cout<<"\n(1)Search By Name\n(2)Search By Code\n(3)Search By Price\n(4)Back  ";
	else cout<<"\n(1)按名称搜索\n(2)按编码搜索\n(3)按价格搜索\n(4)返回   ";
	cin>>option;
	cin.ignore();
	switch(option)
	{
	case 1:
		if(lgwg==1) cout<<"\nEnter Item name ";
		else cout<<"\n请输入物品名称 :";
		cin.getline(name1,10);
		break;
	case 2:
		if(lgwg==1) cout<<"\nEnter Item Code ";
		else cout<<"\n请输入物品编码 : ";
		cin>>code;
		cin.ignore();
		break;
	case 3:
		if(lgwg==1) cout<<"\nEnter The Price ";
		else cout<<"\n请输入物品价格 : ";
		cin>>prc;
		cin.ignore();
		break;
	case 4:
		system("cls");
		return;
	default:
		goto node1;

	}
	fstream file( "TIS.DAT" ,ios::in);  //Open File For Output/Read
	if(!file)  //If File Could Not Be Opened
	{
		if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
		else cout<<"错误!无法打开文件。\n\n按回车继续";
		cin.ignore();cin.get(pause);
		exit(1);
	}
	char flag='a';  //Flag To Check If Found
	Item p1;
	file.read(reinterpret_cast<char *>(&p1),sizeof(Item));
	//Read Data To Object
	while(!file.eof())  //Untill There Are Contacts
	{
		if((strcmp(p1.Item_name,name1)==0)||(p1.Item_code==code))  //Compare
		{
			//clrscr();
			p1.showdata();
			flag='z';   //Set Flag
			break; //Break Loop
		}
		for(i=0;*p1.brnd[i].rtnname()&&i<9;i++)
		{
			if(p1.brnd[i].rtnprice()==prc)
			{
				cout<<"\n\n"<<p1.Item_name<<endl;
				p1.brnd[i].showdata();
				if(lgwg==1) cout<<"\n\nPress Enter to continue.";
				else cout<<"\n\n按回车继续";
 				cin.get(pause);
				flag='z';
			}
		}
		i=0;
		file.read(reinterpret_cast<char *> (&p1),sizeof(Item));
		//Read Next Contact
	}
	if(flag !='z')  //If Not Found
	{
		if(lgwg==1) cout<<"Item Not Found.\n\nPress Enter to continue.";
		else cout<<"未找到匹配档案。\n\n按回车继续";
		cin.get(pause);
	}
	goto node1;
}

// REMOVE Item 
// remove is a bit different first all the data except the Item to be deleted is saved in an other file called delete...
// then the original file is washed and all the data is copied back again
      
void Item::remove()
{
node2:
	//clrscr();
	char name1[10]={NULL};
	int code;
	int option;
	char dlt;
	system("cls");
	if(lgwg==1) cout<<"\n(1)Delete By Name\n(2)Delete By Code\n(3)Delete All the Data\n(4)Back  ";
	else cout<<"\n(1)按名称删除\n(2)按编码删除\n(3)删除所有记录\n(4)返回  ";
	cin>>option;

⌨️ 快捷键说明

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