c++实现宠物商店信息管理系统csdn
时间: 2023-07-28 13:08:02 浏览: 108
为了实现宠物商店信息管理系统,需要设计以下基本功能模块:
1. 宠物信息管理模块:包括宠物的添加、删除、修改和查询等操作。
2. 客户信息管理模块:包括客户的添加、删除、修改和查询等操作。
3. 订单信息管理模块:包括订单的添加、删除、修改和查询等操作。
4. 统计报表模块:包括宠物销售统计、客户购买统计、订单金额统计等。
5. 用户登录模块:包括用户登录和注销等操作。
以下是一个简单的宠物商店信息管理系统的C++代码示例:
```
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 宠物类
class Pet {
public:
Pet(string n, string t, int a, double p) {
name = n;
type = t;
age = a;
price = p;
}
string getName() { return name; }
string getType() { return type; }
int getAge() { return age; }
double getPrice() { return price; }
private:
string name;
string type;
int age;
double price;
};
// 客户类
class Customer {
public:
Customer(string n, string p) {
name = n;
phone = p;
}
string getName() { return name; }
string getPhone() { return phone; }
private:
string name;
string phone;
};
// 订单类
class Order {
public:
Order(Pet* p, Customer* c, int q) {
pet = p;
customer = c;
quantity = q;
}
Pet* getPet() { return pet; }
Customer* getCustomer() { return customer; }
int getQuantity() { return quantity; }
double getTotalPrice() { return pet->getPrice() * quantity; }
private:
Pet* pet;
Customer* customer;
int quantity;
};
// 宠物商店类
class PetShop {
public:
// 添加宠物
void addPet(Pet* p) {
pets.push_back(p);
}
// 删除宠物
void removePet(Pet* p) {
for (vector<Pet*>::iterator it = pets.begin(); it != pets.end(); ++it) {
if (*it == p) {
pets.erase(it);
break;
}
}
}
// 修改宠物信息
void modifyPet(Pet* p, string n, string t, int a, double price) {
p->name = n;
p->type = t;
p->age = a;
p->price = price;
}
// 查询宠物信息
Pet* findPet(string name) {
for (vector<Pet*>::iterator it = pets.begin(); it != pets.end(); ++it) {
if ((*it)->getName() == name) {
return *it;
}
}
return NULL;
}
// 添加客户
void addCustomer(Customer* c) {
customers.push_back(c);
}
// 删除客户
void removeCustomer(Customer* c) {
for (vector<Customer*>::iterator it = customers.begin(); it != customers.end(); ++it) {
if (*it == c) {
customers.erase(it);
break;
}
}
}
// 修改客户信息
void modifyCustomer(Customer* c, string n, string phone) {
c->name = n;
c->phone = phone;
}
// 查询客户信息
Customer* findCustomer(string name) {
for (vector<Customer*>::iterator it = customers.begin(); it != customers.end(); ++it) {
if ((*it)->getName() == name) {
return *it;
}
}
return NULL;
}
// 添加订单
void addOrder(Order* o) {
orders.push_back(o);
}
// 删除订单
void removeOrder(Order* o) {
for (vector<Order*>::iterator it = orders.begin(); it != orders.end(); ++it) {
if (*it == o) {
orders.erase(it);
break;
}
}
}
// 查询订单信息
Order* findOrder(Pet* p, Customer* c) {
for (vector<Order*>::iterator it = orders.begin(); it != orders.end(); ++it) {
if ((*it)->getPet() == p && (*it)->getCustomer() == c) {
return *it;
}
}
return NULL;
}
// 统计宠物销售
int countPetSales(string type) {
int count = 0;
for (vector<Order*>::iterator it = orders.begin(); it != orders.end(); ++it) {
if ((*it)->getPet()->getType() == type) {
count += (*it)->getQuantity();
}
}
return count;
}
// 统计客户购买量
int countCustomerPurchases(string name) {
int count = 0;
for (vector<Order*>::iterator it = orders.begin(); it != orders.end(); ++it) {
if ((*it)->getCustomer()->getName() == name) {
count += (*it)->getQuantity();
}
}
return count;
}
// 统计订单金额
double countOrderAmount() {
double amount = 0;
for (vector<Order*>::iterator it = orders.begin(); it != orders.end(); ++it) {
amount += (*it)->getTotalPrice();
}
return amount;
}
private:
vector<Pet*> pets; // 宠物列表
vector<Customer*> customers; // 客户列表
vector<Order*> orders; // 订单列表
};
int main() {
PetShop petShop;
// 添加宠物
Pet* p1 = new Pet("Tom", "Dog", 2, 1000);
petShop.addPet(p1);
// 添加客户
Customer* c1 = new Customer("Lucy", "123456789");
petShop.addCustomer(c1);
// 添加订单
Order* o1 = new Order(p1, c1, 1);
petShop.addOrder(o1);
// 查询订单金额
cout << "Total amount: " << petShop.countOrderAmount() << endl;
return 0;
}
```
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)