C++写出一个关于美妆产品购买的管理系统,主界面为登录系统和退出系统,登录账号为admit,密码为123456,登录后显示会员管理 产品管理 购物结算 注销
时间: 2024-03-17 07:47:34 浏览: 23
好的,下面是一个简单的C++代码示例:
```c++
#include <iostream>
#include <string>
using namespace std;
// 商品结构体
struct Product {
string name; // 商品名称
double price; // 商品价格
int stock; // 商品库存
};
// 商品管理类
class ProductManager {
private:
Product products[100]; // 最多存储100个商品
int count; // 商品数量
public:
ProductManager() {
count = 0;
}
// 添加商品
void addProduct(string name, double price, int stock) {
products[count].name = name;
products[count].price = price;
products[count].stock = stock;
count++;
}
// 显示商品列表
void showProductList() {
cout << "商品列表:" << endl;
for (int i = 0; i < count; i++) {
cout << i + 1 << ". " << products[i].name << " 价格:" << products[i].price << " 库存:" << products[i].stock << endl;
}
}
// 根据编号获取商品
Product getProduct(int index) {
return products[index - 1];
}
// 减少库存
void reduceStock(int index, int num) {
products[index - 1].stock -= num;
}
};
// 购物车类
class ShoppingCart {
private:
ProductManager* productManager; // 商品管理器
int productIndex[100]; // 商品编号
int count; // 商品数量
public:
ShoppingCart(ProductManager* pm) {
productManager = pm;
count = 0;
}
// 添加商品到购物车
void addProduct(int index) {
productIndex[count] = index;
count++;
}
// 显示购物车列表
void showProductList() {
cout << "购物车列表:" << endl;
double totalPrice = 0;
for (int i = 0; i < count; i++) {
Product product = productManager->getProduct(productIndex[i]);
cout << i + 1 << ". " << product.name << " 价格:" << product.price << endl;
totalPrice += product.price;
}
cout << "总价:" << totalPrice << endl;
}
// 结算购物车
void checkout() {
for (int i = 0; i < count; i++) {
Product product = productManager->getProduct(productIndex[i]);
productManager->reduceStock(productIndex[i], 1);
}
cout << "结算成功!" << endl;
count = 0;
}
};
// 会员管理类
class MemberManager {
private:
string members[100]; // 最多存储100个会员
int count; // 会员数量
public:
MemberManager() {
count = 0;
}
// 添加会员
void addMember(string name) {
members[count] = name;
count++;
}
// 显示会员列表
void showMemberList() {
cout << "会员列表:" << endl;
for (int i = 0; i < count; i++) {
cout << i + 1 << ". " << members[i] << endl;
}
}
};
int main() {
// 初始化商品管理器、购物车和会员管理器
ProductManager pm;
pm.addProduct("口红", 99.9, 10);
pm.addProduct("粉底", 199.9, 5);
pm.addProduct("眉笔", 29.9, 20);
ShoppingCart sc(&pm);
MemberManager mm;
// 登录系统
string username;
string password;
cout << "请输入账号:";
cin >> username;
cout << "请输入密码:";
cin >> password;
if (username == "admin" && password == "123456") {
// 登录成功,显示主界面
bool quit = false;
while (!quit) {
cout << "请选择功能:" << endl;
cout << "1. 会员管理" << endl;
cout << "2. 商品管理" << endl;
cout << "3. 购物结算" << endl;
cout << "4. 退出" << endl;
int choice;
cin >> choice;
switch (choice) {
case 1:
// 会员管理
cout << "请选择操作:" << endl;
cout << "1. 添加会员" << endl;
cout << "2. 显示会员列表" << endl;
int memberChoice;
cin >> memberChoice;
switch (memberChoice) {
case 1:
// 添加会员
string memberName;
cout << "请输入会员名称:";
cin >> memberName;
mm.addMember(memberName);
cout << "添加成功!" << endl;
break;
case 2:
// 显示会员列表
mm.showMemberList();
break;
default:
cout << "无效操作!" << endl;
break;
}
break;
case 2:
// 商品管理
cout << "请选择操作:" << endl;
cout << "1. 添加商品" << endl;
cout << "2. 显示商品列表" << endl;
int productChoice;
cin >> productChoice;
switch (productChoice) {
case 1:
// 添加商品
string productName;
double productPrice;
int productStock;
cout << "请输入商品名称:";
cin >> productName;
cout << "请输入商品价格:";
cin >> productPrice;
cout << "请输入商品库存:";
cin >> productStock;
pm.addProduct(productName, productPrice, productStock);
cout << "添加成功!" << endl;
break;
case 2:
// 显示商品列表
pm.showProductList();
break;
default:
cout << "无效操作!" << endl;
break;
}
break;
case 3:
// 购物结算
sc.showProductList();
sc.checkout();
break;
case 4:
// 退出
quit = true;
break;
default:
cout << "无效操作!" << endl;
break;
}
}
}
else {
// 登录失败
cout << "账号或密码错误!" << endl;
}
return 0;
}
```
这个代码中包含了商品管理、购物车和会员管理三个类,每个类都有对应的方法。在登录成功后,可以选择进入会员管理、商品管理、购物结算和退出功能。具体的操作可以根据提示进行。
相关推荐
![](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)
![](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)