以下是删除顾客的函数
bool Manager::delect_customer_by_name(const string& name)//定义delect_customer_by_name函数以配合delectcustomer删除顾客
{
bool bo = false;
list<Customer>::iterator it;//定义一个list的常迭百代器it来遍历list中的元素
for (it = lc.begin(); it != lc.end(); )
{
if (name == it->get_name())//按名字查找需删除顾客
{
bo = true;
it = lc.erase(it);//使用迭代器删除指定元素,同时返回下一位元素位置
}
else
it++;
}
return bo;
}
bool Manager::delect_customer_by_phone(const string& phone)//定义delect_customer_by_phone函数以配合delectcustomer删除顾客
{
bool bo = false;
list<Customer>::iterator it;//定义一个list的常迭百代器it来遍历list中的元素
for (it = lc.begin(); it != lc.end(); )
{
if (phone == it->get_phone())//按电话查找需删除顾客
{
bo = true;
it = lc.erase(it);//使用迭代器删除指定元素,同时返回下一位元素位置
}
else
it++;
}
return bo;
}
bool Manager::delect_customer_by_card_number(const string& cn)//定义delect_customer_by_card_number函数以配合delectcustomer删除顾客
{
bool bo = false;
list<Customer>::iterator it;//定义一个list的常迭百代器it来遍历list中的元素
for (it = lc.begin(); it != lc.end(); )
{
if (cn == it->get_card_number())//按卡号查找需删除顾客
{
bo = true;
it = lc.erase(it);//使用迭代器删除指定元素,同时返回下一位元素位置
}
else
++it;
}
return bo;
}
以下是修改顾客的函数
bool Manager::modify_customer_info(const Customer& beforecustomer, const Customer& aftercustomer)//定义顾客信息修改函数
//beforecustomer与aftercustomer分别是携带顾客信息的顾客类
{
bool bo = false;//bo用于判断是否修改成功
list<Customer>::iterator it;//定义一个list的常迭百代器it来遍历list中的元素
if (!beforecustomer.get_name().empty())//如果beforecustomer的姓名存在的话
{
for (it = lc.begin(); it != lc.end(); ++it)
{
if (beforecustomer.get_name() == it->get_name())//遍历到与beforecustomer姓名相同的话
{
it->set_name(aftercustomer.get_name());//用aftercustomer的所有信息覆盖it
it->set_gender(aftercustomer.get_gender());
it->set_phone(aftercustomer.get_phone());
it->set_card_number(aftercustomer.get_card_number());
if (aftercustomer.get_cash() > 0)
{
it->clean_cash();
it->set_cash(aftercustomer.get_cash());
}
if (aftercustomer.get_balance() > 0)
{
it->clean_balance();
it->increase_balance(aftercustomer.get_balance());
}
it->set_vip_type(aftercustomer.get_vip_type());
bo = true;
break;
}
}
}
else if (!beforecustomer.get_phone().empty())//如果beforecustomer的电话存在的话
{
for (it = lc.begin(); it != lc.end(); ++it)
{
if (beforecustomer.get_phone() == it->get_phone())//遍历到与beforecustomer电话相同的话
{
it->set_name(aftercustomer.get_name());//用aftercustomer的所有信息覆盖it
it->set_gender(aftercustomer.get_gender());
it->set_phone(aftercustomer.get_phone());
it->set_card_number(aftercustomer.get_card_number());
if (aftercustomer.get_cash() > 0)
{
it->clean_cash();
it->set_cash(aftercustomer.get_cash());
}
if (aftercustomer.get_balance() > 0)
{
it->clean_balance();
it->increase_balance(aftercustomer.get_balance());
}
it->set_vip_type(aftercustomer.get_vip_type());
bo = true;
break;
}
}
}
else if (!beforecustomer.get_card_number().empty())//如果beforecustomer的卡号存在的话
{
for (it = lc.begin(); it != lc.end(); ++it)
{
if (beforecustomer.get_card_number() == it->get_card_number())//遍历到与beforecustomer卡号相同的话
{
it->set_name(aftercustomer.get_name());//用aftercustomer的所有信息覆盖it
it->set_gender(aftercustomer.get_gender());
it->set_phone(aftercustomer.get_phone());
it->set_card_number(aftercustomer.get_card_number());
if (aftercustomer.get_cash() > 0)
{
it->clean_cash();
it->set_cash(aftercustomer.get_cash());
}
if (aftercustomer.get_balance() > 0)
{
it->clean_balance();
it->increase_balance(aftercustomer.get_balance());
}
it->set_vip_type(aftercustomer.get_vip_type());
bo = true;
break;
}
}
}
save();
return bo;
}