写一个c++酒水订单库存统计并维护管理系统
时间: 2023-07-30 11:05:21 浏览: 139
好的,下面是一个更完整的酒水订单库存统计维护管理系统的 C++ 代码:
```cpp
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
// 定义酒类商品结构体
struct Goods {
string name; // 酒名
string brand; // 品牌
int volume; // 容量(单位:ml)
int price; // 单价(单位:分)
int count; // 库存数量
};
// 定义订单结构体
struct Order {
string name; // 酒名
int volume; // 容量(单位:ml)
int count; // 订单数量
};
// 定义酒水管理系统类
class LiquorManager {
private:
vector<Goods> goodsList; // 商品列表
vector<Order> orderList; // 订单列表
public:
// 添加商品
void addGoods(string name, string brand, int volume, int price, int count) {
Goods goods = {name, brand, volume, price, count};
goodsList.push_back(goods);
}
// 显示商品列表
void showGoodsList() {
cout << "商品列表:" << endl;
for (int i = 0; i < goodsList.size(); i++) {
Goods goods = goodsList[i];
cout << "酒名:" << goods.name << " 品牌:" << goods.brand << " 容量:" << goods.volume << "ml 单价:" << goods.price << "分 库存数量:" << goods.count << endl;
}
}
// 添加订单
void addOrder(Order order) {
for (int i = 0; i < goodsList.size(); i++) {
Goods goods = goodsList[i];
if (goods.name == order.name && goods.volume == order.volume) {
if (goods.count >= order.count) {
goodsList[i].count -= order.count;
orderList.push_back(order);
cout << "订单添加成功!" << endl;
return;
} else {
cout << "库存不足!" << endl;
return;
}
}
}
cout << "无法找到对应的商品!" << endl;
}
// 统计销售额
int calculateSales() {
int totalSales = 0;
for (int i = 0; i < orderList.size(); i++) {
Order order = orderList[i];
for (int j = 0; j < goodsList.size(); j++) {
Goods goods = goodsList[j];
if (goods.name == order.name && goods.volume == order.volume) {
totalSales += order.count * goods.price;
break;
}
}
}
return totalSales;
}
// 统计销售量
int calculateSalesVolume() {
int totalSalesVolume = 0;
for (int i = 0; i < orderList.size(); i++) {
Order order = orderList[i];
totalSalesVolume += order.count;
}
return totalSalesVolume;
}
// 统计库存量
int calculateInventory() {
int totalInventory = 0;
for (int i = 0; i < goodsList.size(); i++) {
Goods goods = goodsList[i];
totalInventory += goods.count;
}
return totalInventory;
}
// 按销售额排序并显示商品列表
void showGoodsListOrderBySales() {
sort(goodsList.begin(), goodsList.end(), [](Goods a, Goods b) {
int totalSalesA = 0, totalSalesB = 0;
for (int i = 0; i < orderList.size(); i++) {
Order order = orderList[i];
if (order.name == a.name && order.volume == a.volume) {
totalSalesA += order.count * a.price;
}
if (order.name == b.name && order.volume == b.volume) {
totalSalesB += order.count * b.price;
}
}
return totalSalesA > totalSalesB;
});
cout << "按销售额排序的商品列表:" << endl;
for (int i = 0; i < goodsList.size(); i++) {
Goods goods = goodsList[i];
cout << "酒名:" << goods.name << " 品牌:" << goods.brand << " 容量:" << goods.volume << "ml 单价:" << goods.price << "分 库存数量:" << goods.count << endl;
}
}
};
int main() {
LiquorManager manager;
// 添加商品
manager.addGoods("茅台", "贵州茅台", 500, 1999, 100);
manager.addGoods("五粮液", "五粮液集团", 500, 1399, 200);
manager.addGoods("洋河蓝色经典", "江苏洋河酒厂", 500, 699, 300);
// 显示商品列表
manager.showGoodsList();
// 添加订单
Order order1 = {"茅台", 500, 5};
manager.addOrder(order1);
Order order2 = {"五粮液", 500, 15};
manager.addOrder(order2);
Order order3 = {"洋河蓝色经典", 500, 35};
manager.addOrder(order3);
Order order4 = {"茅台", 500, 10};
manager.addOrder(order4);
// 统计销售额、销售量和库存量
int totalSales = manager.calculateSales();
int totalSalesVolume = manager.calculateSalesVolume();
int totalInventory = manager.calculateInventory();
cout << "销售额:" << totalSales << "分,销售量:" << totalSalesVolume << ",库存量:" << totalInventory << endl;
// 按销售额排序并显示商品列表
manager.showGoodsListOrderBySales();
return 0;
}
```
该程序在原有的基础上新增了统计销售额、销售量和库存量的功能,并且可以按销售额排序并显示商品列表。可以根据需要进行扩展和修改。
阅读全文