请用C++编写下面这个程序设计完成对美发店的简单管理。 功能需求: (1) 定义顾客类,属性有:会员卡号、姓名、性别、电话等信息和相关的对属性做操作的行为。 (2) 定义员工类:属性有:编号、姓名、性别、电话、美发项目(理发、烫发、洗发)等信息和相关的对属性做操作的行为。 (3) 定义美发类:属性有各种美发项目的收费标准和相关的对属性做操作的行为。 (4) 定义一个管理类。 (5) 添加、删除、修改、查询顾客信息和雇员信息,要求编号要唯一,如果添加了重复编号的记录时,则提示数据添加重复并取消添加;删除、修改、查询时,如果没有对应人员记录,则提示“记录为空!”并返回操作。
时间: 2024-03-18 09:42:59 浏览: 116
好的,以下是一个简单的美发店管理系统的C++代码实现:
```c++
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
// 定义顾客类
class Customer {
public:
Customer(string cardId, string name, char sex, string phone)
: m_cardId(cardId), m_name(name), m_sex(sex), m_phone(phone) {}
// 获取和设置会员卡号
string getCardId() { return m_cardId; }
void setCardId(string cardId) { m_cardId = cardId; }
// 获取和设置姓名
string getName() { return m_name; }
void setName(string name) { m_name = name; }
// 获取和设置性别
char getSex() { return m_sex; }
void setSex(char sex) { m_sex = sex; }
// 获取和设置电话
string getPhone() { return m_phone; }
void setPhone(string phone) { m_phone = phone; }
private:
string m_cardId;
string m_name;
char m_sex;
string m_phone;
};
// 定义员工类
class Employee {
public:
Employee(int number, string name, char sex, string phone, string project)
: m_number(number), m_name(name), m_sex(sex), m_phone(phone), m_project(project) {}
// 获取和设置编号
int getNumber() { return m_number; }
void setNumber(int number) { m_number = number; }
// 获取和设置姓名
string getName() { return m_name; }
void setName(string name) { m_name = name; }
// 获取和设置性别
char getSex() { return m_sex; }
void setSex(char sex) { m_sex = sex; }
// 获取和设置电话
string getPhone() { return m_phone; }
void setPhone(string phone) { m_phone = phone; }
// 获取和设置美发项目
string getProject() { return m_project; }
void setProject(string project) { m_project = project; }
private:
int m_number;
string m_name;
char m_sex;
string m_phone;
string m_project;
};
// 定义美发类
class Hairdressing {
public:
Hairdressing() {
m_price["haircut"] = 50;
m_price["perm"] = 100;
m_price["wash"] = 20;
}
// 获取美发项目的收费标准
int getPrice(string project) {
return m_price[project];
}
private:
// 美发项目的收费标准
map<string, int> m_price;
};
// 定义管理类
class Management {
public:
// 添加顾客信息
void addCustomer(Customer& customer) {
// 检查会员卡号是否唯一
for (auto& c : m_customers) {
if (c.getCardId() == customer.getCardId()) {
cout << "添加失败,会员卡号重复!" << endl;
return;
}
}
m_customers.push_back(customer);
cout << "添加成功!" << endl;
}
// 删除顾客信息
void removeCustomer(string cardId) {
auto it = find_if(m_customers.begin(), m_customers.end(), [cardId](Customer& c) { return c.getCardId() == cardId; });
if (it == m_customers.end()) {
cout << "记录为空!" << endl;
return;
}
m_customers.erase(it);
cout << "删除成功!" << endl;
}
// 修改顾客信息
void updateCustomer(Customer& customer) {
auto it = find_if(m_customers.begin(), m_customers.end(), [cardId = customer.getCardId()](Customer& c) { return c.getCardId() == cardId; });
if (it == m_customers.end()) {
cout << "记录为空!" << endl;
return;
}
*it = customer;
cout << "修改成功!" << endl;
}
// 查询顾客信息
void queryCustomer(string cardId) {
auto it = find_if(m_customers.begin(), m_customers.end(), [cardId](Customer& c) { return c.getCardId() == cardId; });
if (it == m_customers.end()) {
cout << "记录为空!" << endl;
return;
}
cout << "会员卡号:" << it->getCardId() << endl;
cout << "姓名:" << it->getName() << endl;
cout << "性别:" << it->getSex() << endl;
cout << "电话:" << it->getPhone() << endl;
}
// 添加员工信息
void addEmployee(Employee& employee) {
// 检查编号是否唯一
for (auto& e : m_employees) {
if (e.getNumber() == employee.getNumber()) {
cout << "添加失败,编号重复!" << endl;
return;
}
}
m_employees.push_back(employee);
cout << "添加成功!" << endl;
}
// 删除员工信息
void removeEmployee(int number) {
auto it = find_if(m_employees.begin(), m_employees.end(), [number](Employee& e) { return e.getNumber() == number; });
if (it == m_employees.end()) {
cout << "记录为空!" << endl;
return;
}
m_employees.erase(it);
cout << "删除成功!" << endl;
}
// 修改员工信息
void updateEmployee(Employee& employee) {
auto it = find_if(m_employees.begin(), m_employees.end(), [number = employee.getNumber()](Employee& e) { return e.getNumber() == number; });
if (it == m_employees.end()) {
cout << "记录为空!" << endl;
return;
}
*it = employee;
cout << "修改成功!" << endl;
}
// 查询员工信息
void queryEmployee(int number) {
auto it = find_if(m_employees.begin(), m_employees.end(), [number](Employee& e) { return e.getNumber() == number; });
if (it == m_employees.end()) {
cout << "记录为空!" << endl;
return;
}
cout << "编号:" << it->getNumber() << endl;
cout << "姓名:" << it->getName() << endl;
cout << "性别:" << it->getSex() << endl;
cout << "电话:" << it->getPhone() << endl;
cout << "美发项目:" << it->getProject() << endl;
}
private:
vector<Customer> m_customers; // 顾客列表
vector<Employee> m_employees; // 员工列表
};
int main() {
// 创建一个美发店管理对象
Management management;
// 添加顾客信息
Customer customer1("001", "Tom", 'M', "13800000001");
management.addCustomer(customer1);
// 添加员工信息
Employee employee1(1001, "Lucy", 'F', "13800000002", "haircut");
management.addEmployee(employee1);
// 查询顾客信息
management.queryCustomer("001");
// 查询员工信息
management.queryEmployee(1001);
// 修改顾客信息
Customer customer2("001", "Tony", 'M', "13800000003");
management.updateCustomer(customer2);
// 修改员工信息
Employee employee2(1001, "Lily", 'F', "13800000004", "perm");
management.updateEmployee(employee2);
// 删除顾客信息
management.removeCustomer("001");
// 删除员工信息
management.removeEmployee(1001);
return 0;
}
```
以上代码实现了添加、删除、修改、查询顾客信息和员工信息的功能,并且实现了编号和会员卡号的唯一性检查。当添加重复记录时,会提示“添加失败,编号或者会员卡号重复!”;当删除、修改、查询不存在的记录时,会提示“记录为空!”
阅读全文