C++——仓库管理系统大作业

头文件代码:

#include
#include
#include
using namespace std;

class storage {
public:
	storage(string na, string id, int ad) :name(na), storageid(id), price(ad) {}
	void show()
	{
		cout << name << "      " << storageid << "      " << price << "\n";
	}
	string name;
	string storageid;
	int price;
};

class purchase {
public:
	purchase(string store, string id, string tim, int num, string ad) :name(store), date(tim), purchaseid(id), number(num), address(ad) {}
	void show()
	{
		cout << purchaseid << "      " << name << "      " << date << "      " << number << "      " << address << "\n";
	}
	string name;
	string purchaseid;
	string date;
	int number;
	string address;
};

class shipment {
public:
	shipment(string store, string id, string tim, int num, string ad) :name(store), date(tim), shipmentid(id), number(num), address(ad) {}
	void show()
	{
		cout << shipmentid << "      " << name << "      " << date << "      " << number << "      " << address << "\n";
	}
	string name;
	string shipmentid;
	string date;
	int number;
	string address;
};

class inventory {
public:
	inventory(string store,string inventid,int num) :name(store), inventoryid(inventid), number(num) {}
	void show()
	{
		cout << name << "     " << inventoryid << "     " << number << "\n";
	}
	string name;
	string inventoryid;
	int number;
};

void menu() {
	cout << "\n                  ———————  仓库管理系统界面  ———————\n" << endl;
	cout << "\n                  |     1.查看物品信息      2.管理物品信息      |\n" << endl;
	cout << "\n                  |     3.查看进货信息      4.管理进货信息      |\n" << endl;
	cout << "\n                  |     5.查看出货信息      6.管理出货信息      |\n" << endl;
	cout << "\n                  |     7.查看库存信息      8.管理库存信息      |\n" << endl;
	cout << "\n                  |               0.退出                       |\n" << endl;
	cout << "\n                   ———————————————————————\n" << endl;
}

template
void myswap(T* store1, T* store2)
{
	T* temp = store1;
	store1 = store2;
	store2 = temp;
}

void showdata(vector& purcdate)
{
	if (purcdate.size() == 0) {
		cout << "暂无进货信息!\n";
		return;
	}
	cout << "进货编号" << "    " << "物品名称" << "    " << "进货时间" << "    " << "物品数量" << "    " << "进货地址" << "\n";
	for (auto& purc : purcdate) {
		purc->show();
	}
}

void showdata(vector& shipdate)
{
	if (shipdate.size() == 0) {
		cout << "暂无出货信息!\n";
		return;
	}
	cout << "出货编号" << "    " << "物品名称" << "    " << "出货时间" << "    " << "物品数量" << "    " << "出货地址" << "\n";
	for (auto& ship : shipdate) {
		ship->show();
	}
}

void showdata(vector& storedata)
{
	if (storedata.size() == 0) {
		cout << "暂无信息!\n";
		return;
	}
	cout << "名称" << "    " << "编号" << "    " << "价格" << "\n";
	for (auto& store : storedata) {
		store->show();
	}
}
void showdata(vector& inventdata)
{
	if (inventdata.size() == 0) {
		cout << "暂无信息!\n";
		return;
	}
	cout << "物品名称" << "    " << "库存编号" << "    " << "库存数量" << "\n";
	for (auto& invent : inventdata) {
		invent->show();
	}
}

purchase* finddata(vector& purcdata, string finddate)
{
	for (auto& purc : purcdata) {
		if (purc->purchaseid == finddate)
			return purc;
	}
	return nullptr;
}

shipment* finddata(vector& shipdata, string finddate)
{
	for (auto& ship : shipdata) {
		if (ship->shipmentid == finddate)
			return ship;
	}
	return nullptr;
}

storage* finddata(vector& storedata, string finddate)
{
	for (auto& store : storedata) {
		if (store->name == finddate || store->storageid == finddate)
			return store;
	}
	return nullptr;
}

inventory* finddata(vector& inventdata, string finddate)
{
	for (auto& invent : inventdata) {
		if (invent->name == finddate || invent->inventoryid == finddate)
			return invent;
	}
	return nullptr;
}


void adddata(vector& purcdate, vector& inventdata)
{
	string name, id, date, address;
	int num;
	cout << "请输入进货物品名称:";
	cin >> name;
	cout << "请输入进货编号:";
	cin >> id;
	cout << "请输入进货时间:";
	cin >> date;
	cout << "请输入进货物品数量:";
	cin >> num;
	cout << "请输入进货地址:";
	cin >> address;
	purcdate.push_back(new purchase(name, id, date, num, address));
	inventory* inventindex = finddata(inventdata, name);
	if (inventindex)
		inventindex->number += num;
	else
		inventdata.push_back(new inventory(name,id, num));
	cout << "添加成功!\n";
}

void adddata(vector& shipdata, vector& inventdata)
{
	string name, id, date, address;
	int num;
	cout << "请输入出货物品名称:";
	cin >> name;
	cout << "请输入出货编号:";
	cin >> id;
	cout << "请输入出货时间:";
	cin >> date;
	cout << "请输入出货物品数量:";
	cin >> num;
	cout << "请输入出货地址:";
	cin >> address;
	inventory* inventindex = finddata(inventdata, name);
	if (inventindex) {
		if(inventindex->number>=num)
			inventindex->number -= num;
		else {
			cout << "库存不足,无法出货!\n";
			return;
		}
	}
	else {
		cout << "库存内无该物品,无法出货!\n";
		return;
	}
	shipdata.push_back(new shipment(name, id, date, num, address));
	cout << "添加成功!\n";
}

void adddata(vector& storagedata)
{
	string name, storeid;
	int num;
	cout << "请输入物品名称:";
	cin >> name;
	cout << "请输入物品编号:";
	cin >> storeid;
	cout << "请输入物品价格:";
	cin >> num;
	storagedata.push_back(new storage(name, storeid, num));
	cout << "添加成功!\n";
}

void adddata(vector& inventdata)
{
	string name, id;
	int num;
	cout << "请输入添加到库存的物品名称或编号:";
	cin >> name;
	cout << "请输入编号:";
	cin >> id;
	cout << "请输入添加的物品数量:";
	cin >> num;
	inventory* inventindex = finddata(inventdata, name);
	if (inventindex)
		inventindex->number += num;
	else
		inventdata.push_back(new inventory(name,id, num));
	cout << "添加成功!\n";
}

void deletedata(vector& purcdate)
{
	string date;
	cout << "请输入删除的进货编号:\n";
	cin >> date;
	purchase* index = finddata(purcdate, date);
	if (index) {
		delete(index);
		index = nullptr;
		myswap(index, purcdate[purcdate.size() - 1]);
		purcdate.pop_back();
		cout << "删除成功!\n";
	}
	else
		cout << "没找到该订单!\n";
}

void deletedata(vector& shipdata)
{
	string date;
	cout << "请输入删除的出货编号:\n";
	cin >> date;
	shipment* index = finddata(shipdata, date);
	if (index) {
		delete(index);
		index = nullptr;
		myswap(index, shipdata[shipdata.size() - 1]);
		shipdata.pop_back();
		cout << "删除成功!\n";
	}
	else
		cout << "没找到该订单!\n";
}

void deletedata(vector& storedata)
{
	string date;
	cout << "请输入删除的物品名称或编号:\n";
	cin >> date;
	storage* index = finddata(storedata, date);
	if (index) {
		delete(index);
		index = nullptr;
		myswap(index, storedata[storedata.size() - 1]);
		storedata.pop_back();
		cout << "删除成功!\n";
	}
	else
		cout << "没找到该物品!\n";
}

void deletedata(vector& inventdata)
{
	string date;
	cout << "请输入删除的库存物品名称或编号:\n";
	cin >> date;
	inventory* index = finddata(inventdata, date);
	if (index) {
		delete(index);
		index = nullptr;
		myswap(index, inventdata[inventdata.size() - 1]);
		inventdata.pop_back();
		cout << "删除成功!\n";
	}
	else
		cout << "没找到该物品!\n";
}

void views(vector& purcdate)
{
	string date;
	cout << "请输入查找的进货编号:\n";
	cin >> date;
	purchase* index = finddata(purcdate, date);
	if (index) {
		index->show();
	}
	else
		cout << "没找到该信息!\n";
}

void views(vector& shipdate)
{
	string date;
	cout << "请输入查找的出货编号:\n";
	cin >> date;
	shipment* index = finddata(shipdate, date);
	if (index) {
		index->show();
	}
	else
		cout << "没找到该信息!\n";
}

void views(vector& storedata)
{
	string date;
	cout << "请输入查找的物品名称或编号:\n";
	cin >> date;
	storage* index = finddata(storedata, date);
	if (index) {
		index->show();
	}
	else
		cout << "没找到该信息!\n";
}

void views(vector& inventdata)
{
	string date;
	cout << "请输入查找的物品名称或编号:\n";
	cin >> date;
	inventory* index = finddata(inventdata, date);
	if (index) {
		index->show();
	}
	else
		cout << "没找到该信息!\n";
}

void changedata(vector& purcdata)
{
	string date;
	cout << "请输入修改的进货编号:\n";
	cin >> date;
	purchase* index = finddata(purcdata, date);
	bool flag = false;
	if (index) {
		int choice;
		string changedate;
		cout << "1.修改编号   2.修改物品名称   3.修改时间   4.修改物品数量   5.修改地址\n";
		cout << "请选择:\n";
		cin >> choice;
		cout << "输入修改后的:\n";
		cin >> changedate;
		if (choice == 1)
			index->purchaseid = changedate;
		else if (choice == 2)
			index->name = changedate;
		else if (choice == 3)
			index->date = changedate;
		else if (choice == 3)
			index->number = stoi(changedate);
		else if (choice == 5)
			index->address = changedate;
		else
			cout << "请输入正确选项!\n", flag = true;
		if (!flag)
			cout << "修改成功!\n";
	}
	else
		cout << "没找到该信息!\n";
}

void changedata(vector& shipdata)
{
	string date;
	cout << "请输入修改的出货编号:\n";
	cin >> date;
	shipment* index = finddata(shipdata, date);
	bool flag = false;
	if (index) {
		int choice;
		string changedate;
		cout << "1.修改编号   2.修改物品名称   3.修改时间   4.修改物品数量   5.修改地址\n";
		cout << "请选择:\n";
		cin >> choice;
		cout << "输入修改后的:\n";
		cin >> changedate;
		if (choice == 1)
			index->shipmentid = changedate;
		else if (choice == 2)
			index->name = changedate;
		else if (choice == 3)
			index->date = changedate;
		else if (choice == 3)
			index->number = stoi(changedate);
		else if (choice == 5)
			index->address = changedate;
		else
			cout << "请输入正确选项!\n", flag = true;
		if (!flag)
			cout << "修改成功!\n";
	}
	else
		cout << "没找到该信息!\n";
}

void changedata(vector& storedata)
{
	string date;
	cout << "请输入修改的物品名称或编号:\n";
	cin >> date;
	storage* index = finddata(storedata, date);
	bool flag = false;
	if (index) {
		int choice;
		string changedate;
		cout << "1.修改名称   2.修改编号   3.修改价格\n";
		cout << "请选择:\n";
		cin >> choice;
		cout << "输入修改后的:\n";
		cin >> changedate;
		if (choice == 1)
			index->name = changedate;
		else if (choice == 2)
			index->storageid = changedate;
		else if (choice == 3)
			index->price = stoi(changedate);
		else
			cout << "请输入正确选项!\n", flag = true;
		if (!flag)
			cout << "修改成功!\n";
	}
	else
		cout << "没找到该物品信息!\n";
}

void changedata(vector& inventdata)
{
	string date;
	cout << "请输入修改的库存物品名称或编号:\n";
	cin >> date;
	inventory* index = finddata(inventdata, date);
	if (index) {
		int choice;
		int changedate;
		cout << "输入修改后的库存数量:\n";
		cin >> changedate;
		index->number = changedate;
		cout << "修改成功!\n";
	}
	else
		cout << "没找到该物品信息!\n";
}

源文件代码:

#include
#include
#include
#include"Head.h"
using namespace std;
int main()
{
    vector purcdata;
    vector shipdata;
    vector storedata;
    vector inventdata;
    while (true) {
        menu();
        string choice;
        cout << "请选择:\n";
        cin >> choice;
        if (choice == "1") {
            cout << "1.展示所有信息   2.查询详细信息  \n";
            cout << "请选择:\n";
            cin >> choice;
            if (choice == "1")
                showdata(storedata);
            else if (choice == "2")
                views(storedata);
            else
                cout << "请输入正确选项!\n";
        }
        else if (choice == "2") {
            cout << "1.添加物品信息  2.删除物品  3.修改信息\n";
            cout << "请选择:\n";
            cin >> choice;
            if (choice == "1")
                adddata(storedata);
            else if (choice == "2")
                deletedata(storedata);
            else if (choice == "3")
                changedata(storedata);
            else
                cout << "请输入正确选项!\n";
        }
        else if (choice == "3") {
            cout << "1.展示所有信息   2.查询详细信息  \n";
            cout << "请选择:\n";
            cin >> choice;
            if (choice == "1")
                showdata(purcdata);
            else if (choice == "2")
                views(purcdata);
            else
                cout << "请输入正确选项!\n";
        }
        else if (choice == "4") {
            cout << "1.添加进货信息  2.删除进货信息  3.修改进货信息\n";
            cout << "请选择:\n";
            cin >> choice;
            if (choice == "1")
                adddata(purcdata, inventdata);
            else if (choice == "2")
                deletedata(purcdata);
            else if (choice == "3")
                changedata(purcdata);
            else
                cout << "请输入正确选项!\n";
        }
        else if (choice == "5") {
            cout << "1.展示所有信息   2.查询详细信息  \n";
            cout << "请选择:\n";
            cin >> choice;
            if (choice == "1")
                showdata(shipdata);
            else if (choice == "2")
                views(shipdata);
            else
                cout << "请输入正确选项!\n";
        }
        else if (choice == "6") {
            cout << "1.添加出货信息  2.删除出货信息  3.修改出货信息\n";
            cout << "请选择:\n";
            cin >> choice;
            if (choice == "1")
                adddata(shipdata,inventdata);
            else if (choice == "2")
                deletedata(shipdata);
            else if (choice == "3")
                changedata(shipdata);
            else
                cout << "请输入正确选项!\n";
        }
        else if (choice == "7") {
            cout << "1.展示所有信息   2.查询详细信息  \n";
            cout << "请选择:\n";
            cin >> choice;
            if (choice == "1")
                showdata(inventdata);
            else if (choice == "2")
                views(inventdata);
            else
                cout << "请输入正确选项!\n";
        }
        else if (choice == "8") {
            cout << "1.添加库存信息  2.删除库存信息  3.修改库存数量\n";
            cout << "请选择:\n";
            cin >> choice;
            if (choice == "1")
                adddata(inventdata);
            else if (choice == "2")
                deletedata(storedata);
            else if (choice == "3")
                changedata(inventdata);
            else
                cout << "请输入正确选项!\n";
        }
        else if (choice == "0")
            break;
        else
            cout << "请输入正确选项!\n";
        system("pause");
        system("cls");
    }
    return 0;
}

运行结果(由于测试数据太多,仅此展示几个运行结果):

C++——仓库管理系统大作业_第1张图片

C++——仓库管理系统大作业_第2张图片 

C++——仓库管理系统大作业_第3张图片

 

C++——仓库管理系统大作业_第4张图片 

C++——仓库管理系统大作业_第5张图片

C++——仓库管理系统大作业_第6张图片 

 

 

你可能感兴趣的:(C++,c++)