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

 struct Call {
string phoneNumber;
string content;
};
enum RANK {
RESPONDENT, MANAGER, DIRECTOR
};
class Employee {
public:
Employee(int level) : level(level) {}
int getLevel() const { return level; }
bool isFree() const { return calls.empty(); }
virtual bool handleCall(Call call) = ;
protected:
queue<Call> calls;
private:
int level;
}; class Respondent : public Employee {
public:
Respondent() : Employee(RANK::RESPONDENT) {}
bool handleCall(Call call) { /*...*/ return true;}
}; class Manager: public Employee {
public:
Manager() : Employee(RANK::MANAGER) {}
bool handleCall(Call call) { /*...*/ return true;}
}; class Director : public Employee {
public:
Director(): Employee(RANK::DIRECTOR) {}
bool handleCall(Call call) {/*...*/ return true; }
}; class CallCenter {
public:
bool dispatchCall(Call call) {
for (map<int, vector<Employee> >::iterator it = employees.begin();
it != employees.end(); it++) {
for (int i = ; i < it->second.size(); ++i) {
if (it->second[i].isFree() && it->second[i].handleCall(call)) {
return true;
}
}
}
return false;
} void addEmployee(Employee &employee) {
employees[employee.getLevel()].push_back(employee);
}
private:
map<int, vector<Employee> > employees;
};

Careercup | Chapter 8的更多相关文章

  1. Careercup | Chapter 1

    1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot us ...

  2. Careercup | Chapter 3

    3.1 Describe how you could use a single array to implement three stacks. Flexible Divisions的方案,当某个栈满 ...

  3. Careercup | Chapter 2

    链表的题里面,快慢指针.双指针用得很多. 2.1 Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow w ...

  4. Careercup | Chapter 7

    7.4 Write methods to implement the multiply, subtract, and divide operations for integers. Use only ...

  5. CareerCup Chapter 9 Sorting and Searching

    9.1 You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. ...

  6. CareerCup chapter 1 Arrays and Strings

    1.Implement an algorithm to determine if a string has all unique characters What if you can not use ...

  7. CareerCup Chapter 4 Trees and Graphs

    struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),rig ...

  8. Careercup | Chapter 6

    6.2 There is an 8x8 chess board in which two diagonally opposite corners have been cut off. You are ...

  9. Careercup | Chapter 5

    5.1 You are given two 32-bit numbers, N andM, and two bit positions, i and j. Write a method to inse ...

随机推荐

  1. js-原型以及继承小案例

    function human(name,tall){ this.name=name; this.tall=tall; this.toSleep=function(){ alert('no sleep' ...

  2. http://blog.csdn.net/lipeng32768/article/details/50845547

    http://blog.csdn.net/lipeng32768/article/details/50845547

  3. [转]走向视网膜(Retina)的Web时代

    转载出处:http://www.w3cplus.com/css/towards-retina-web.html 维基百科将Retina译为“视网膜”."Retina"一词,原意是“ ...

  4. details和summary

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. java基础-数组

    浏览以下内容前,请点击并阅读 声明 定义:数组是一个能容纳固定数量,类型单一的若干个值的容器.注意,数组是一个对象. 数组一旦创建,则其长度固定不变,数组中的所有值叫元素(Element),获取元素要 ...

  6. 使用CSS/JS代码修改博客模板plus

    之前对CSS/JavaScript了解还不深,只是把模板的CSS胡乱修改了几个属性.最近正好也在做一个网站的前端,学习了不少东西,再来改一改~ 上次最后之所以铩羽而归,是因为从CSS里找不到那些#和. ...

  7. Extjs 属性控件[转载]

    Ext.form.TimeField: 配置项:            maxValue:列表中允许的最大时间            maxText:当时间大于最大值时的错误提示信息          ...

  8. BZOJ 2733 & splay的合并

    题意: 带权联通块,添边与查询联通块中第k大. SOL: splay合并+并查集. 我以为splay可以用奇技淫巧来简单合并...调了一下午终于幡然醒悟...于是就只好一个一个慢慢插...什么启发式合 ...

  9. Spoj 10628. Count on a tree 题解

    题目大意: 给定一棵n个点的树,每个点有一个权值,m个询问,每次询问树上点x到点y的路径上的第k小数. 思路: dfs后给每个节点一个dfs序,以每个点在他父亲的基础上建立主席树,询问时用(点x+点y ...

  10. Codeforces Round #250 (Div. 2) A. The Child and Homework

    注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C. #include <iost ...