怎么用C++写一个健身房管理系统
时间: 2023-07-15 12:11:03 浏览: 149
C++ 控制台编写 运动会管理系统
4星 · 用户满意度95%
一个简单的健身房管理系统可能需要以下功能:
1. 会员信息管理:包括会员姓名、性别、年龄、电话、会员卡号、会员类型等信息;
2. 器材管理:包括器材名称、型号、数量、使用状态等信息;
3. 健身房员工管理:包括员工姓名、职位、联系方式等信息;
4. 会员和员工的登录和注册功能;
5. 会员和员工的权限管理;
6. 销售管理:包括会员卡的销售、续费等功能;
7. 消费管理:记录会员的消费记录;
8. 财务统计:统计健身房的收入和支出情况。
以下是一个简单的健身房管理系统的代码示例:
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 声明会员结构体
struct Member {
string name;
string gender;
int age;
string phone;
int id;
string type;
};
// 声明器材结构体
struct Equipment {
string name;
string model;
int quantity;
bool in_use;
};
// 声明员工结构体
struct Employee {
string name;
string position;
string phone;
};
// 声明会员卡结构体
struct Membership {
int id;
string type;
int price;
};
// 声明消费记录结构体
struct Consumption {
int member_id;
string date;
int amount;
};
// 声明健身房类
class Gym {
public:
// 构造函数
Gym() {}
// 添加会员信息
void add_member(string name, string gender, int age, string phone, int id, string type) {
Member member = {name, gender, age, phone, id, type};
members.push_back(member);
}
// 删除会员信息
void delete_member(int id) {
for (int i = 0; i < members.size(); i++) {
if (members[i].id == id) {
members.erase(members.begin() + i);
break;
}
}
}
// 查找会员信息
Member find_member(int id) {
for (int i = 0; i < members.size(); i++) {
if (members[i].id == id) {
return members[i];
}
}
Member empty_member = {"", "", 0, "", 0, ""};
return empty_member;
}
// 添加器材信息
void add_equipment(string name, string model, int quantity) {
Equipment equipment = {name, model, quantity, false};
equipments.push_back(equipment);
}
// 删除器材信息
void delete_equipment(string name, string model) {
for (int i = 0; i < equipments.size(); i++) {
if (equipments[i].name == name && equipments[i].model == model) {
equipments.erase(equipments.begin() + i);
break;
}
}
}
// 查找器材信息
Equipment find_equipment(string name, string model) {
for (int i = 0; i < equipments.size(); i++) {
if (equipments[i].name == name && equipments[i].model == model) {
return equipments[i];
}
}
Equipment empty_equipment = {"", "", 0, false};
return empty_equipment;
}
// 添加员工信息
void add_employee(string name, string position, string phone) {
Employee employee = {name, position, phone};
employees.push_back(employee);
}
// 删除员工信息
void delete_employee(string name) {
for (int i = 0; i < employees.size(); i++) {
if (employees[i].name == name) {
employees.erase(employees.begin() + i);
break;
}
}
}
// 查找员工信息
Employee find_employee(string name) {
for (int i = 0; i < employees.size(); i++) {
if (employees[i].name == name) {
return employees[i];
}
}
Employee empty_employee = {"", "", ""};
return empty_employee;
}
// 添加会员卡信息
void add_membership(int id, string type, int price) {
Membership membership = {id, type, price};
memberships.push_back(membership);
}
// 删除会员卡信息
void delete_membership(int id) {
for (int i = 0; i < memberships.size(); i++) {
if (memberships[i].id == id) {
memberships.erase(memberships.begin() + i);
break;
}
}
}
// 查找会员卡信息
Membership find_membership(int id) {
for (int i = 0; i < memberships.size(); i++) {
if (memberships[i].id == id) {
return memberships[i];
}
}
Membership empty_membership = {0, "", 0};
return empty_membership;
}
// 添加消费记录
void add_consumption(int member_id, string date, int amount) {
Consumption consumption = {member_id, date, amount};
consumptions.push_back(consumption);
}
// 删除消费记录
void delete_consumption(int member_id, string date, int amount) {
for (int i = 0; i < consumptions.size(); i++) {
if (consumptions[i].member_id == member_id && consumptions[i].date == date && consumptions[i].amount == amount) {
consumptions.erase(consumptions.begin() + i);
break;
}
}
}
// 查找消费记录
vector<Consumption> find_consumption(int member_id) {
vector<Consumption> result;
for (int i = 0; i < consumptions.size(); i++) {
if (consumptions[i].member_id == member_id) {
result.push_back(consumptions[i]);
}
}
return result;
}
private:
vector<Member> members; // 会员信息
vector<Equipment> equipments; // 器材信息
vector<Employee> employees; // 员工信息
vector<Membership> memberships; // 会员卡信息
vector<Consumption> consumptions; // 消费记录
};
int main() {
// 创建健身房对象
Gym gym;
// 添加会员信息
gym.add_member("Tom", "Male", 25, "1234567890", 1, "Regular");
gym.add_member("Kate", "Female", 30, "0987654321", 2, "VIP");
// 删除会员信息
gym.delete_member(1);
// 查找会员信息
Member member = gym.find_member(2);
if (member.name != "") {
cout << "Name: " << member.name << endl;
cout << "Gender: " << member.gender << endl;
cout << "Age: " << member.age << endl;
cout << "Phone: " << member.phone << endl;
cout << "ID: " << member.id << endl;
cout << "Type: " << member.type << endl;
} else {
cout << "Member not found." << endl;
}
// 添加器材信息
gym.add_equipment("Treadmill", "Model A", 10);
gym.add_equipment("Bench Press", "Model B", 5);
// 删除器材信息
gym.delete_equipment("Treadmill", "Model A");
// 查找器材信息
Equipment equipment = gym.find_equipment("Bench Press", "Model B");
if (equipment.name != "") {
cout << "Name: " << equipment.name << endl;
cout << "Model: " << equipment.model << endl;
cout << "Quantity: " << equipment.quantity << endl;
cout << "In use: " << (equipment.in_use ? "Yes" : "No") << endl;
} else {
cout << "Equipment not found." << endl;
}
// 添加员工信息
gym.add_employee("John", "Trainer", "1357924680");
gym.add_employee("Mary", "Receptionist", "2468135790");
// 删除员工信息
gym.delete_employee("John");
// 查找员工信息
Employee employee = gym.find_employee("Mary");
if (employee.name != "") {
cout << "Name: " << employee.name << endl;
cout << "Position: " << employee.position << endl;
cout << "Phone: " << employee.phone << endl;
} else {
cout << "Employee not found." << endl;
}
// 添加会员卡信息
gym.add_membership(1, "Regular", 100);
gym.add_membership(2, "VIP", 200);
// 删除会员卡信息
gym.delete_membership(1);
// 查找会员卡信息
Membership membership = gym.find_membership(2);
if (membership.id != 0) {
cout << "ID: " << membership.id << endl;
cout << "Type: " << membership.type << endl;
cout << "Price: " << membership.price << endl;
} else {
cout << "Membership not found." << endl;
}
// 添加消费记录
gym.add_consumption(2, "2022-01-01", 50);
gym.add_consumption(2, "2022-01-02", 100);
// 删除消费记录
gym.delete_consumption(2, "2022-01-01", 50);
// 查找消费记录
vector<Consumption> consumptions = gym.find_consumption(2);
if (consumptions.size() > 0) {
for (int i = 0; i < consumptions.size(); i++) {
cout << "Member ID: " << consumptions[i].member_id << endl;
cout << "Date: " << consumptions[i].date << endl;
cout << "Amount: " << consumptions[i].amount << endl;
}
} else {
cout << "Consumption not found." << endl;
}
return 0;
}
```
请注意,这只是一个简单的示例,实际的健身房管理系统可能需要更多的功能和复杂的设计。
阅读全文