-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBoss.cpp
164 lines (143 loc) · 4.09 KB
/
Boss.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "Waiter.h"
#include "Boss.h"
#include "FoodMenu.h"
#include <string>
using std::string;
CBoss * CBoss::pBoss = NULL;
CBoss::CBoss(const string & strPassword,
const string & strName/* ="" */,
const string & strSex/* ="" */):CPerson(strName,strSex){
this->m_strPassword = strPassword;
}
CBoss * CBoss::GetBoss(const string & strPassword, const string & strName/* ="" */, const string & strSex/* ="" */){
if(NULL==pBoss){
pBoss = new CBoss(strPassword,strName,strSex);
}
return pBoss;
}
void CBoss::ChangePassword(const string & strPassword){
this->m_strPassword = strPassword;
}
CFoodMenu * CBoss::AddFoodMenuItem(CFoodMenu ** ppFoodMenu,
const unsigned &uFoodType,
const string &strFoodName,
const double & dPrice)const{
register CFoodMenu * current;
while((current = *ppFoodMenu)!=NULL && current->m_Food.m_uFoodType != uFoodType){
ppFoodMenu = ¤t->m_NextFood;
}
while((current = *ppFoodMenu)!=NULL && current->m_Food.m_uFoodType == uFoodType){
ppFoodMenu = ¤t->m_NextFood;
}
CBoardMenu * pNewFood = new CBoardMenu;
if(NULL == pNewFood)
return NULL;
pNewFood->m_Food.m_uFoodType = uFoodType;
pNewFood->m_Food.m_strFoodName = strFoodName;
pNewFood->m_Food.m_dPrice = dPrice;
CFoodMenu::m_unFoodCount++;
pNewFood->m_NextFood = current;
*ppFoodMenu = pNewFood;
return pNewFood;
}
bool CBoss::DelFoodMenuItem(CFoodMenu **ppFoodMenu, const string &strFoodName){
register CFoodMenu * current;
while((current = *ppFoodMenu)!=NULL && current->m_Food.m_strFoodName != strFoodName){
ppFoodMenu = ¤t->m_NextFood;
}
if(NULL == current){
return false;
}
CFoodMenu::m_unFoodCount--;
*ppFoodMenu = current->m_NextFood;
delete current;
return true;
}
bool CBoss::AddBoard(CBoard ** ppBoard)const{
register CBoard * current,*p=NULL;
while((current = *ppBoard) != NULL){
ppBoard = ¤t->pNextBoard;
p = current;
}
CBoard * pNewBoard;
if(NULL==p) pNewBoard = new CBoard(1);
else{
unsigned d;
unsigned i;
i=p->GetNumber()+1;
while(i){
d = i%10;
if(4 == d) break;
i/=10;
}
if(0==i)
pNewBoard = new CBoard(p->GetNumber()+1);
else
pNewBoard = new CBoard(p->GetNumber()+2);
}
if(NULL == pNewBoard)
return false;
*ppBoard = pNewBoard;
return true;
}
bool CBoss::DelBoard(CBoard ** ppBoard){
register CBoard * current;
while((current = *ppBoard)->pNextBoard != NULL){
ppBoard = ¤t->pNextBoard;
}
*ppBoard = NULL;
delete current; //当我将DelBoard函数设为常函数。这条语句执行不彻底.没有调用CBoard的析构函数
return true;
}
bool CBoss::AddWaiter(CWaiter ** ppWaiter,
const unsigned short &unNumber,
const double &dSalary,
const string & strName/* ="" */,
const string & strSex/* ="" */,
const double & dAchievement/* =0 */)const{
register CWaiter * current;
while((current = *ppWaiter) != NULL){
ppWaiter = ¤t->pNextWaiter;
}
CWaiter * pNewWaiter;
pNewWaiter = new CWaiter(unNumber,dSalary,strName,strSex);
if(NULL == pNewWaiter)
return false;
*ppWaiter = pNewWaiter;
return true;
}
bool CBoss::DelWaiter(CWaiter **ppWaiter,
const unsigned short &unNumber)const{
register CWaiter * current;
while((current = *ppWaiter) != NULL && current->GetNumber() != unNumber){
ppWaiter = ¤t->pNextWaiter;
}
if (NULL == current) {
return false;
}
*ppWaiter = current->pNextWaiter;
delete current;
return true;
}
bool CBoss::SetWaiterSalary(CWaiter **ppWaiter,
const unsigned short &unNumber,
const double & dSalary)const{
register CWaiter * current;
while((current = *ppWaiter) != NULL && current->GetNumber() != unNumber){
ppWaiter = ¤t->pNextWaiter;
}
if(NULL == current){
return false;
}
current->m_dSalary = dSalary;
return true;
}
bool CBoss::SetWaiterSalary(CWaiter * pWaiter, const double & dSalary)const{
if(NULL == pWaiter)
return false;
pWaiter->m_dSalary = dSalary;
return true;
}
string CBoss::GetPassword()const{
return this->m_strPassword;
}