首页 > 代码库 > Careercup | Chapter 8
Careercup | Chapter 8
8.2 Imagine you have a call center with three levels of employees: respondent, manager, and director. An incoming telephone call must be first allocated to a respondent who is free. If the respondent can‘t handle the call, he or she must escalate the call to a manager. If the manager is not free or notable to handle it, then the call should be escalated to a director. Design the classes and data structures for this problem. Implement a method dispatchCaL L () which assigns a call to the first available employee
1 struct Call { 2 string phoneNumber; 3 string content; 4 }; 5 enum RANK { 6 RESPONDENT, MANAGER, DIRECTOR 7 }; 8 class Employee { 9 public:10 Employee(int level) : level(level) {}11 int getLevel() const { return level; }12 bool isFree() const { return calls.empty(); }13 virtual bool handleCall(Call call) = 0;14 protected:15 queue<Call> calls;16 private:17 int level;18 };19 20 class Respondent : public Employee {21 public:22 Respondent() : Employee(RANK::RESPONDENT) {}23 bool handleCall(Call call) { /*...*/ return true;}24 };25 26 class Manager: public Employee {27 public:28 Manager() : Employee(RANK::MANAGER) {}29 bool handleCall(Call call) { /*...*/ return true;}30 };31 32 class Director : public Employee {33 public:34 Director(): Employee(RANK::DIRECTOR) {}35 bool handleCall(Call call) {/*...*/ return true; } 36 };37 38 class CallCenter {39 public:40 bool dispatchCall(Call call) {41 for (map<int, vector<Employee> >::iterator it = employees.begin();42 it != employees.end(); it++) {43 for (int i = 0; i < it->second.size(); ++i) {44 if (it->second[i].isFree() && it->second[i].handleCall(call)) {45 return true;46 }47 }48 }49 return false;50 }51 52 void addEmployee(Employee &employee) {53 employees[employee.getLevel()].push_back(employee);54 }55 private:56 map<int, vector<Employee> > employees;57 };
Careercup | Chapter 8
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。