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. psql-05数据库,模式

    数据的组织结构 数据库:表,索引:数据行 PostgreSQL中一个服务(实例)可以有多个数据库:而一个数据库不能属于多个实例; 数据库 创建数据库 create database name [own ...

  2. Ubuntu12.04安装搜狗输入法失败后,出现登录界面循环

    前些天,因为复现别人实验就准备重新启用实验室的集群上的系统,上去安装了几个插件,之后又觉得需要中文输入法就试着装一下,结果安装失败,看到报错信息,也没放在心上,第二天启动时发现再也登录不进去. 现象描 ...

  3. JS_ECMA基本语法中的几种封装的小函数

      先来回顾一下我们的字符串: 字符串方法: str.length str.charAt(i):取字符串中的某一个; str.indexOf('e');找第一个出现的位置;找不到返回-1; str.l ...

  4. Shell 编程基础之 Case 练习

    一.语法 case $变量 in "第一个变量内容") # 每个变量内容建议用双引号括起来,关键字则为小括号 ) # 执行内容 ;; # 每个类别结尾使用两个连续的分号来处理! & ...

  5. JQuery EasyUI window 用法

    var $win; $win = $('#test-window').window({ title: '添加课程设置信息', width: 820, height: 450, top: ($(wind ...

  6. topcoder SRM 625 DIV2 IncrementingSequence

    由于题目数据量比较小,故可以开辟一个数组存储每个index出现的次数 然后遍历即可 string canItBeDone(int k, vector<int> A){ vector< ...

  7. QtCreator下运行opencv出现realloc():pointer invalid

    解决办法是将qmake换成4.8的,qmake5.2的支持opencv支持的不是很好

  8. HDU 4749 Parade Show(贪心+kmp)

    题目链接 题目都看不懂,做毛线...看懂了之后就是kmp出,所有的匹配区间,然后DP可以写,贪心也可以做把,DP应该需要优化一下,直接贪,也应该对的,经典贪心问题. #include<iostr ...

  9. POI Word 模板 文字 图片 替换

    实验环境:POI3.7+Word2007 Word模板: 替换后效果: 代码: 1.入口文件 public class Test { public static void main(String[] ...

  10. Optimizely:在线网站A/B测试平台

    Optimizely:在线网站A/B测试平台是一家提供 A/B 测试服务的公司.A/B 测试能够对比不同版本的设计,选取更吸引用户眼球的那一款,从而带来更为优化的个人体验.让网站所有者易于对不同版本的 ...