写一段c++代码销售管理系统
时间: 2023-10-20 16:16:56 浏览: 40
好的,这里给您一个简单的C++销售管理系统的代码示例,实现了添加商品、删除商品、查询商品、修改商品信息等基本功能。
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 商品信息结构体
struct GoodsInfo {
string name; // 商品名称
double price; // 商品价格
int count; // 商品数量
};
// 商品管理类
class GoodsManager {
private:
vector<GoodsInfo> goodsList; // 商品列表
public:
// 添加商品
void addGoods(const string& name, double price, int count) {
GoodsInfo goods;
goods.name = name;
goods.price = price;
goods.count = count;
goodsList.push_back(goods);
cout << "添加商品成功!" << endl;
}
// 删除商品
void deleteGoods(int index) {
if (index < 0 || index >= goodsList.size()) {
cout << "删除失败,索引越界!" << endl;
return;
}
goodsList.erase(goodsList.begin() + index);
cout << "删除商品成功!" << endl;
}
// 查询商品
void searchGoods(const string& name) {
for (int i = 0; i < goodsList.size(); ++i) {
if (goodsList[i].name == name) {
cout << "商品名称:" << goodsList[i].name << endl;
cout << "商品价格:" << goodsList[i].price << endl;
cout << "商品数量:" << goodsList[i].count << endl;
return;
}
}
cout << "查询失败,未找到该商品!" << endl;
}
// 修改商品信息
void modifyGoods(int index, double price, int count) {
if (index < 0 || index >= goodsList.size()) {
cout << "修改失败,索引越界!" << endl;
return;
}
goodsList[index].price = price;
goodsList[index].count = count;
cout << "修改商品信息成功!" << endl;
}
};
int main() {
GoodsManager goodsManager;
int choice;
string name;
double price;
int count;
int index;
while (true) {
cout << "欢迎使用商品管理系统!" << endl;
cout << "1. 添加商品" << endl;
cout << "2. 删除商品" << endl;
cout << "3. 查询商品" << endl;
cout << "4. 修改商品信息" << endl;
cout << "5. 退出系统" << endl;
cout << "请选择操作:";
cin >> choice;
switch (choice) {
case 1:
cout << "请输入商品名称:";
cin >> name;
cout << "请输入商品价格:";
cin >> price;
cout << "请输入商品数量:";
cin >> count;
goodsManager.addGoods(name, price, count);
break;
case 2:
cout << "请输入要删除的商品索引:";
cin >> index;
goodsManager.deleteGoods(index);
break;
case 3:
cout << "请输入要查询的商品名称:";
cin >> name;
goodsManager.searchGoods(name);
break;
case 4:
cout << "请输入要修改的商品索引:";
cin >> index;
cout << "请输入新的商品价格:";
cin >> price;
cout << "请输入新的商品数量:";
cin >> count;
goodsManager.modifyGoods(index, price, count);
break;
case 5:
cout << "感谢使用商品管理系统,再见!" << endl;
return 0;
default:
cout << "输入有误,请重新输入!" << endl;
break;
}
}
return 0;
}
```
以上是一个简单的C++销售管理系统的代码示例,仅供参考。实际开发中可能还需要增加其他功能,例如统计销售额、生成销售报表等,需要根据实际需求进行开发。