源码:

#include<iostream>
#include<string>
#define max 1000
using namespace std;

void desktop(){	
    cout<<"**********************"<<endl;
    cout<<"***** 1.仓库管理***** "<<endl; 
	cout<<"***** 2.人员管理***** "<<endl;
	cout<<"***** 3.退出系统***** "<<endl;
    cout<<"**********************"<<endl;
} 

//菜单界面
void showmenu(){
	cout << "**********************"<< endl;
	cout << "*** 1.添加货物信息 ***"<< endl;
	cout << "*** 2.显示货物信息 ***"<< endl;
	cout << "*** 3.删除货物信息 ***"<< endl;
	cout << "*** 4.查找货物信息 ***"<< endl;
	cout << "*** 5.修改货物信息 ***"<< endl;
	cout << "*** 6.清空货物信息 ***"<< endl; 
	cout << "***** 0.退出系统 *****"<< endl; 
	cout << "**********************"<< endl;
} 

//货物的结构体 
struct cargo{
	string m_name;
	int m_out;
	string m_time;
	string m_phone;
	string m_addr;
};
//仓库的结构体数组 
struct warehouse{
	struct cargo Array[max];
	int m_size;
};

//添加货物信息 
void add(warehouse * abs){
	if(abs->m_size==max){
		cout<<"库存已满" <<endl;
		return;
	}
	else{
		//添加具体联系人
		string name;
		cout <<"请输入货物名称 :" <<endl;
		cin>>name;
		abs->Array[abs->m_size].m_name=name; 
		
		//出库 
		cout<<"是否出库 :"<<endl;
		cout<<"1 - 出库"<<endl;
		cout<<"2 - 未出库"<<endl; 
		int out=0;
		while(true){
			//如果输入正确退出循环,如果输入有误,请重新输入; 
		cin>>out;
		if(out==1||out==2){
			abs->Array[abs->m_size].m_out=out;
			break;
		} 
		cout<<"请重新输入"<<endl; 
		}
		//时间 
		cout <<"请输入入库时间"<<endl;
		string time;
		cin>>time;
		abs->Array[abs->m_size].m_time=time;
		
		//电话
		cout <<"请输入商家电话"<<endl;
		string phone;
		cin>>phone;
		abs->Array[abs->m_size].m_phone=phone;
        //住址
		cout <<"请输入商家信息"<<endl;
		string address;
		cin>>address;
		abs->Array[abs->m_size].m_addr=address;
		abs->m_size++;
		cout<< "入库成功 "<<endl;
		system("pause");
		system("cls");		
	}
} 

//显示货物 
void show(warehouse *abs) 
{
	//判断货物个数是否为零
	//如果不为零,显示清单 
	if(abs->m_size==0) {
		cout <<"仓库为空"<<endl;
	}
	else{
		for (int i=0;i<abs->m_size;i++){
			cout<<"货物名称: "<<abs->Array[i].m_name<<"\t";
			cout<<"是否出库: "<<(abs->Array[i].m_out==1? "是":"否")<<"\t";
			cout<<"入库时间: "<<abs->Array[i].m_time<<"\t";
			cout<<"商家电话: "<<abs->Array[i].m_phone<<"\t";
			cout<<"商家信息: "<<abs->Array[i].m_addr<<endl; 
		}
	}
	system("pause");
	system("cls"); 
}


//检测存在
int isexist(warehouse *abs,string name)
{
	for (int i=0;i<abs->m_size;i++){
		if(abs->Array[i].m_name==name){
		return i;//找到返回下标编号 
	}	
	}//没有找到 
	return -1;
} 


//删除货物 
void dele(warehouse *abs){
	cout<<"请输入要删货物名称"<<endl;
	string name;
	cin>>name;
	int ret=isexist(abs,name);
	if(ret==-1){
	cout<<"没有该货物!";
	
    }
	else
	{
	for(int i=ret;i<abs->m_size;i++){
		abs->Array[i]=abs->Array[i+1];
	cout<<"删除成功"<<endl;	
	}
	abs->m_size--;
    }
	system("pause");
	system("cls");
} 


//查找货物 
void find(warehouse *abs){
	cout<<"请输入要查找的货物名称"<<endl;
	string name;
	cin>>name;
	int ret =isexist(abs,name);
	if(ret!=-1){
			cout<<"货物名称: "<<abs->Array[ret].m_name<<"\t";
			cout<<"是否出库: "<<(abs->Array[ret].m_out==1? "是":"否")<<"\t";
			cout<<"入库时间: "<<abs->Array[ret].m_time<<"\t";
			cout<<"商家电话: "<<abs->Array[ret].m_phone<<"\t";
			cout<<"商家信息: "<<abs->Array[ret].m_addr<<endl; 
        }
	else{
		cout<<"没有此货物"<<endl; 
	}	
	system("pause");
	system("cls");
}


//修改货物信息 
void mod(warehouse *abs){
	cout<<"请输入要修改货物名称"<<endl;
	string name;
	cin>>name;
	int ret =isexist(abs,name);
	if(ret!=-1){
		//名称 
		cout<<"请输入货物名称"<<endl; 
		string name;
		cin>>name; 
		abs->Array[ret].m_name=name;
		//状态 
		cout<<"是否出库"<<endl;
		cout<<"1 - 是"<<endl;
		cout<<"2 - 否"<<endl;
		int out;
		while(true){
		cin>>out;
		if(out==1||out==2){ 
		abs->Array[ret].m_out=out;
		break;
		} 
		cout<<"请重新输入"<<endl; 
	}
		//入库时间 
		cout<<"请输入入库时间"<<endl; 
		string time;
		cin>>time; 
		abs->Array[ret].m_time=time;
		//电话 
		cout<<"请输入商家电话"<<endl; 
		string phone;
		cin>>phone; 
		abs->Array[ret].m_phone=phone;
		//商家信息 
		cout<<"请输入商家信息"<<endl; 
		string address;
		cin>>address; 
		abs->Array[ret].m_addr=address;
		
	} else{
		cout<<"没有此商品"<<endl; 
	}
	system("pause");
	system("cls");
} 


//清空货物单 
void cls(warehouse *abs){
	cout<<"是否确定清空货物单 "<<"\n"<<"1--是"<<"\t"<<"2--否"<<endl;
	int pad;
	cin>>pad;
	if(pad==1){
	abs->m_size=0;
	cout<<"账单已清空"<<endl;
	} 
	system("pause");
	system("cls");
} 
//人员管理 

void showmenu01(){
	cout << "**************************"<< endl;
	cout << "*** 1.添加工作人员信息 ***"<< endl;
	cout << "*** 2.显示工作人员信息 ***"<< endl;
	cout << "*** 3.删除工作人员信息 ***"<< endl;
	cout << "*** 4.查找工作人员信息 ***"<< endl;
	cout << "*** 5.修改工作人员信息 ***"<< endl;
	cout << "*** 6.清空人员信息系统 ***"<< endl; 
	cout << "******* 0.退出系统 *******"<< endl;
	cout << "**************************"<< endl; 
} 
struct person{
	string m_name;
	int m_sex ;
	int m_age;
	string m_phone;
	string m_work;
};
struct addressbooks{
	struct person personArray[max];
	int m_size;
};


//添加工人 
void addperson(addressbooks * abs){
	if(abs->m_size==max){
		cout<<"人员已满,没有空缺职位" <<endl;
		return;
	}
	else{
		//添加工人
		string name;
		cout <<"请输入姓名 :" <<endl;
		cin>>name;
		abs->personArray[abs->m_size].m_name=name; 
		//性别
		cout<<"请输入性别 :"<<endl;
		cout<<"1 - 男"<<endl;
		cout<<"2 - 女"<<endl; 
		int sex=0;
		while(true){
			//如果输入正确退出循环,如果输入有误,请重新输入; 
		cin>>sex;
		if(sex==1||sex==2){
			abs->personArray[abs->m_size].m_sex=sex;
			break;
		} 
		cout<<"请重新输入"<<endl; 
		}
		//年龄
		cout <<"请输入年龄"<<endl;
		int age=0;
		cin>>age;
		abs->personArray[abs->m_size].m_age=age;
		//电话
		cout <<"请输入电话"<<endl;
		string phone;
		cin>>phone;
		abs->personArray[abs->m_size].m_phone=phone;
        //住址
		cout <<"请输入担任职位"<<endl;
		string work;
		cin>>work;
		abs->personArray[abs->m_size].m_work=work;
		abs->m_size++;
		cout<< "添加成功 "<<endl;
		system("pause");
		system("cls");		
	}
} 

//显示人员 
void showperson(addressbooks *abs) 
{
	//判断人数是否为零
	//如果不为零,显示人员
	if(abs->m_size==0) {
		cout <<"当前记录为空"<<endl;
	}
	else{
		for (int i=0;i<abs->m_size;i++){
			cout<<"姓名: "<<abs->personArray[i].m_name<<"\t";
			cout<<"性别: "<<(abs->personArray[i].m_sex==1? "男":"女")<<"\t";
			cout<<"年龄: "<<abs->personArray[i].m_age<<"\t";
			cout<<"电话: "<<abs->personArray[i].m_phone<<"\t";
			cout<<"职位: "<<abs->personArray[i].m_work<<endl; 
		}
	}
	system("pause");
	system("cls"); 
}

//检测存在
int isexist(addressbooks *abs,string name)
{
	for (int i=0;i<abs->m_size;i++){
		if(abs->personArray[i].m_name==name){
		return i;//找到返回下标编号 
	}	
	}//没有找到 
	return -1;
} 

//删除联系人
void deleteperson(addressbooks *abs){
	cout<<"请输入要删人员姓名"<<endl;
	string name;
	cin>>name;
	int ret=isexist(abs,name);
	if(ret==-1){
	cout<<"没有该联系人!";
	
    }
	else
	{
	for(int i=ret;i<abs->m_size;i++){
		abs->personArray[i]=abs->personArray[i+1];
	cout<<"删除成功"<<endl;	
	}
	abs->m_size--;
    }
	system("pause");
	system("cls");
} 


//查找工人 
void findperson(addressbooks *abs){
	cout<<"请输入要查找的人员姓名"<<endl;
	string name;
	cin>>name;
	int ret =isexist(abs,name);
	if(ret!=-1){
			cout<<"姓名: "<<abs->personArray[ret].m_name<<"\t";
			cout<<"性别: "<<(abs->personArray[ret].m_sex==1? "男":"女")<<"\t";
			cout<<"年龄: "<<abs->personArray[ret].m_age<<"\t";
			cout<<"电话: "<<abs->personArray[ret].m_phone<<"\t";
			cout<<"职位: "<<abs->personArray[ret].m_work<<endl; 
        }
	else{
		cout<<"没有此联系人"<<endl; 
	}	
	system("pause");
	system("cls");
}

//修改人员信息 
void modperson(addressbooks *abs){
	cout<<"请输入要修改人员姓名"<<endl;
	string name;
	cin>>name;
	int ret =isexist(abs,name);
	if(ret!=-1){
		//姓名 
		cout<<"请输入姓名"<<endl; 
		string name;
		cin>>name; 
		abs->personArray[ret].m_name=name;
		//性别 
		cout<<"请输入姓别"<<endl;
		cout<<"1 - 男"<<endl;
		cout<<"2 - 女"<<endl;
		int sex;
		while(true){
		cin>>sex;
		if(sex==1||sex==2){ 
		abs->personArray[ret].m_sex=sex;
		break;
		} 
		cout<<"请重新输入"<<endl; 
	}
		//年龄 
		cout<<"请输入年龄"<<endl; 
		int age;
		cin>>age; 
		abs->personArray[ret].m_age=age;
		//电话 
		cout<<"请输入电话"<<endl; 
		string phone;
		cin>>phone; 
		abs->personArray[ret].m_phone=phone;
		//职位 
		cout<<"请输入职位"<<endl; 
		string work;
		cin>>work; 
		abs->personArray[ret].m_work=work;
		
	} else{
		cout<<"没有此工作人员"<<endl; 
	}
	system("pause");
	system("cls");
} 


//清空人员信息
void clsperson(addressbooks *abs){
	cout<<"是否确定清空工人信息 "<<"\n"<<"1--是"<<"\t"<<"2--否"<<endl;
	int pad;
	cin>>pad;
	if(pad==1){
	abs->m_size=0;
	cout<<"工人信息已清空"<<endl;
	} 
	system("pause");
	system("cls");
} 
//人员管理 


int main(){
	//创建结构体变量 
	
	warehouse abs;
	abs.m_size=0;
	addressbooks abs01;
	abs01.m_size=0;
while(true){
		desktop();
		int select;
		cin>>select;
    switch(select){
	case 1:{
	//初始化货物个数 
	
	int s =0;//创建用户选择输入的变量 
			//while(true){
		showmenu(); 
	cin>>s;
	switch(s){
		case 1:add(&abs);//添加货物
		    break;
		case 2:show(&abs);//显示货物 
		    break;
		case 3:dele(&abs);//删除货物 
		    break;
		case 4:find(&abs); //查找货物 
			break;
		case 5:mod(&abs);//修改货物 
			break;
		case 6:cls(&abs);//清空货物单 
			break;
		case 0://退出系统 
		    cout<<"欢迎下次使用" <<endl;
			system("pause"); 
			return 0;
			break;
		default:
			break;
	}	
		break;
	}
	
	case 2:{
	
	//初始化人员个数 
	
	int sel =0;//创建用户选择输入的变量 
		showmenu01(); 
	cin>>sel;
	switch(sel){
		case 1:addperson(&abs01);//添加
		    break;
		case 2:showperson(&abs01);//显示
		    break;
		case 3:deleteperson(&abs01);//删除
		    break;
		case 4:findperson(&abs01); //查找
			break;
		case 5:modperson(&abs01);//修改
			break;
		case 6:clsperson(&abs01);//清空
		case 0://退出
		    cout<<"欢迎下次使用" <<endl;
			system("pause"); 
			return 0;
			break;
		default:
			break;
	}	
		break;
	}
	case 3:	
	 cout<<"欢迎下次使用" <<endl;
			return 0;
			break;	
  }
}
	return 0;
} 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐