开发一个简单的超市信息管理系统,要求实现以下基本功能: 1、系统管理员用户可以完成以下功能:(1)创建系统新员工账户,并可以查找、删除和更新员工信息(2)创建会员新账户,并可以查找、删除和更新会员信息 (3)创建、查询、删除、更新商品的信息库 (4)会员积分管理(创建、查询、兑换、更新、删除等等功能) 2、员工账户可以完成以下功能: (1)从信息库里查询商品金额,并输入金额,显示应找回的金额(2)查询会员积分,并将可以积分的商品,给用户积上相应的积分
时间: 2024-03-09 14:44:11 浏览: 154
好的,这里是一个简单的超市信息管理系统的代码实现,包含了上述要求的基本功能:
```c++
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
// 定义员工和会员的结构体
struct Employee {
string name;
string id;
string password;
};
struct Customer {
string name;
string id;
string password;
int points;
};
// 定义商品的结构体
struct Product {
string name;
double price;
int stock;
};
// 定义超市信息管理系统的类
class Supermarket {
public:
// 构造函数
Supermarket() {
// 初始化管理员账户
employees.push_back({"admin", "admin", "admin"});
}
// 系统管理员用户功能
void createEmployee(string name, string id, string password) {
employees.push_back({name, id, password});
}
void deleteEmployee(string id) {
for (auto it = employees.begin(); it != employees.end(); ++it) {
if (it->id == id) {
employees.erase(it);
break;
}
}
}
void updateEmployee(string id, string name, string password) {
for (auto& employee : employees) {
if (employee.id == id) {
employee.name = name;
employee.password = password;
break;
}
}
}
bool loginEmployee(string id, string password) {
for (auto& employee : employees) {
if (employee.id == id && employee.password == password) {
return true;
}
}
return false;
}
void createCustomer(string name, string id, string password) {
customers.push_back({name, id, password, 0});
}
void deleteCustomer(string id) {
for (auto it = customers.begin(); it != customers.end(); ++it) {
if (it->id == id) {
customers.erase(it);
break;
}
}
}
void updateCustomer(string id, string name, string password) {
for (auto& customer : customers) {
if (customer.id == id) {
customer.name = name;
customer.password = password;
break;
}
}
}
bool loginCustomer(string id, string password) {
for (auto& customer : customers) {
if (customer.id == id && customer.password == password) {
return true;
}
}
return false;
}
void createProduct(string name, double price, int stock) {
products.insert({name, {name, price, stock}});
}
void deleteProduct(string name) {
products.erase(name);
}
void updateProduct(string name, double price, int stock) {
products[name].price = price;
products[name].stock = stock;
}
void queryProduct(string name) {
cout << "Product Name: " << products[name].name << endl;
cout << "Price: " << products[name].price << endl;
cout << "Stock: " << products[name].stock << endl;
}
void addPoints(string id, int points) {
for (auto& customer : customers) {
if (customer.id == id) {
customer.points += points;
break;
}
}
}
void redeemPoints(string id, int points) {
for (auto& customer : customers) {
if (customer.id == id) {
if (customer.points >= points) {
customer.points -= points;
cout << "Redeem successful! Remaining points: " << customer.points << endl;
} else {
cout << "Not enough points!" << endl;
}
break;
}
}
}
void queryPoints(string id) {
for (auto& customer : customers) {
if (customer.id == id) {
cout << "Points: " << customer.points << endl;
break;
}
}
}
// 员工账户功能
double checkout(string name, double payment) {
double price = products[name].price;
double change = payment - price;
products[name].stock -= 1;
return change;
}
void addPoints(string id, string name) {
if (products[name].price >= 10) {
addPoints(id, 1);
}
}
private:
vector<Employee> employees; // 员工列表
vector<Customer> customers; // 会员列表
map<string, Product> products; // 商品列表
};
int main() {
Supermarket supermarket;
// 创建管理员账户
supermarket.createEmployee("Lucas", "12345", "password");
// 管理员创建员工账户
supermarket.createEmployee("Tom", "67890", "password");
// 员工登录
if (supermarket.loginEmployee("67890", "password")) {
cout << "Employee login successful!" << endl;
// 查询商品价格
supermarket.queryProduct("Apple");
// 结账并计算找零
double change = supermarket.checkout("Apple", 10.0);
cout << "Change: " << change << endl;
// 查询会员积分
supermarket.queryPoints("123");
// 购买商品并积分
supermarket.addPoints("123", "Apple");
}
// 管理员创建会员账户
supermarket.createCustomer("Bob", "123", "password");
// 会员登录
if (supermarket.loginCustomer("123", "password")) {
cout << "Customer login successful!" << endl;
// 查询会员积分
supermarket.queryPoints("123");
// 兑换积分
supermarket.redeemPoints("123", 5);
}
return 0;
}
```
在这个例子中,我们定义了一个 `Supermarket` 类,该类包含了系统管理员和员工的功能,例如创建、删除和更新员工和会员账户,管理商品信息库,以及管理会员积分等等。我们还定义了 `Employee`、`Customer` 和 `Product` 结构体,用于存储员工、会员和商品的信息。
在 `main` 函数中,我们创建了一个 `Supermarket` 对象,并使用它来执行一些示例操作,例如创建管理员账户,创建员工和会员账户,查询商品价格,结账和计算找零,查询积分,购买商品并积分,以及兑换积分等等。
阅读全文