帮我用c++写一个客户消费积分管理系统,要求:(1)采用一定的存储结构进行客户信息的存储; (2)对客户的信息可以进行修改、删除、添加; (3)能够根据消费情况进行客户积分的计算; (4)根据积分情况实行不同程度的打折优惠;
时间: 2024-02-05 12:11:12 浏览: 21
好的,以下是一个简单的客户消费积分管理系统的 C++ 代码示例,其中使用了结构体和动态数组来实现客户信息的存储和修改、删除、添加等操作,同时也包括了根据消费情况进行积分计算和打折优惠的功能。
```c++
#include <iostream>
#include <cstring>
using namespace std;
// 客户信息结构体
struct Customer {
char name[50]; // 姓名
int age; // 年龄
char phone[20]; // 电话
double balance; // 余额
int points; // 积分
};
// 动态数组
Customer* customers;
int customerCount = 0;
// 添加新客户
void addCustomer() {
Customer customer;
cout << "请输入客户姓名:";
cin >> customer.name;
cout << "请输入客户年龄:";
cin >> customer.age;
cout << "请输入客户电话:";
cin >> customer.phone;
cout << "请输入客户余额:";
cin >> customer.balance;
// 计算积分
if (customer.balance >= 1000) {
customer.points = customer.balance / 10;
} else if (customer.balance >= 500) {
customer.points = customer.balance / 20;
} else {
customer.points = 0;
}
// 将客户信息添加到动态数组中
customers = (Customer*)realloc(customers, sizeof(Customer) * (customerCount + 1));
customers[customerCount++] = customer;
cout << "客户添加成功!" << endl;
}
// 修改客户信息
void modifyCustomer() {
char name[50];
bool found = false;
cout << "请输入要修改客户的姓名:";
cin >> name;
// 查找客户
for (int i = 0; i < customerCount; i++) {
if (strcmp(customers[i].name, name) == 0) {
found = true;
cout << "请输入新的年龄:";
cin >> customers[i].age;
cout << "请输入新的电话:";
cin >> customers[i].phone;
cout << "请输入新的余额:";
cin >> customers[i].balance;
// 更新积分
if (customers[i].balance >= 1000) {
customers[i].points = customers[i].balance / 10;
} else if (customers[i].balance >= 500) {
customers[i].points = customers[i].balance / 20;
} else {
customers[i].points = 0;
}
cout << "客户信息修改成功!" << endl;
break;
}
}
if (!found) {
cout << "未找到该客户,请重新输入!" << endl;
}
}
// 删除客户信息
void deleteCustomer() {
char name[50];
bool found = false;
cout << "请输入要删除客户的姓名:";
cin >> name;
// 查找客户
for (int i = 0; i < customerCount; i++) {
if (strcmp(customers[i].name, name) == 0) {
found = true;
// 将该客户后面的信息往前移动一个位置
for (int j = i + 1; j < customerCount; j++) {
customers[j - 1] = customers[j];
}
// 动态数组大小减一
customers = (Customer*)realloc(customers, sizeof(Customer) * (customerCount - 1));
customerCount--;
cout << "客户信息删除成功!" << endl;
break;
}
}
if (!found) {
cout << "未找到该客户,请重新输入!" << endl;
}
}
// 显示客户信息
void showCustomers() {
for (int i = 0; i < customerCount; i++) {
cout << "客户姓名:" << customers[i].name << endl;
cout << "客户年龄:" << customers[i].age << endl;
cout << "客户电话:" << customers[i].phone << endl;
cout << "客户余额:" << customers[i].balance << endl;
cout << "客户积分:" << customers[i].points << endl;
// 根据积分情况实行不同程度的打折优惠
if (customers[i].points >= 100) {
cout << "打九折!" << endl;
} else if (customers[i].points >= 50) {
cout << "打八折!" << endl;
} else if (customers[i].points >= 10) {
cout << "打九五折!" << endl;
}
cout << endl;
}
}
int main() {
int choice;
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:
addCustomer();
break;
case 2:
modifyCustomer();
break;
case 3:
deleteCustomer();
break;
case 4:
showCustomers();
break;
case 5:
cout << "程序已退出!" << endl;
return 0;
default:
cout << "操作编号输入错误,请重新输入!" << endl;
break;
}
cout << endl;
}
}
```
以上代码仅供参考,实际情况中可能需要根据具体需求进行修改和完善。