c++ 写一个仓库管理系统
时间: 2023-07-29 13:13:14 浏览: 123
当然可以!以下是一个简单的仓库管理系统的示例代码:
```cpp
#include <iostream>
#include <vector>
using namespace std;
struct Item {
string name;
int quantity;
Item(string n, int q) : name(n), quantity(q) {}
};
class Warehouse {
private:
vector<Item> items;
public:
void addItem(string name, int quantity) {
items.push_back(Item(name, quantity));
}
void removeItem(string name) {
for (int i = 0; i < items.size(); i++) {
if (items[i].name == name) {
items.erase(items.begin() + i);
break;
}
}
}
void displayItems() {
for (const auto& item : items) {
cout << "Name: " << item.name << ", Quantity: " << item.quantity << endl;
}
}
};
int main() {
Warehouse warehouse;
warehouse.addItem("Item 1", 10);
warehouse.addItem("Item 2", 5);
warehouse.addItem("Item 3", 15);
cout << "Initial Items:" << endl;
warehouse.displayItems();
warehouse.removeItem("Item 2");
cout << "Items after removal:" << endl;
warehouse.displayItems();
return 0;
}
```
这个仓库管理系统使用了`Item`结构体来表示每个物品的名称和数量。`Warehouse`类中包含了一些基本的功能,如添加物品、删除物品和显示所有物品。在`main`函数中,我们创建一个`Warehouse`对象并进行一些简单的操作来测试系统。
请注意,这只是一个简单的示例,实际的仓库管理系统可能需要更复杂的功能和数据结构来处理更多的细节。希望这个示例能帮助你开始编写仓库管理系统!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)