8.3 Design a musical jukebox using object-oriented principles.

CareerCup这书实在是太不负责任了,就写了个半调子的程序,说是完整版也可以下载到,但是我怎么找不到,谁知道在哪里下载请告诉博主,多谢啦~

class Song;

class CD {
public:
// ...
private:
long _id;
string _artist;
set<Song> _songs;
}; class Song {
public:
// ...
private:
long _id;
CD _cd;
string _title;
long _length;
}; class Playlist {
public:
Playlist() {};
Playlist(Song song, queue<Song> queue): _song(song), _queue(queue) {};
Song getNextSToPlay() {
Song next = _queue.front(); _queue.pop();
return next;
}
void queueUpSong(Song s) {
_queue.push(s);
} private:
Song _song;
queue<Song> _queue;
}; class CDPlayer {
public:
CDPlayer(CD c, Playlist p): _c(c), _p(p) {};
CDPlayer(Playlist p): _p(p) {};
CDPlayer(CD c): _c(c) {};
void playSong(Song s) {}; // ...
Playlist getPlaylist() { return _p; };
void setPlaylist(Playlist p) { _p = p; };
CD getCD() { return _c; };
void setCD(CD c) { _c = c; }; private:
Playlist _p;
CD _c;
}; class User {
public:
User(string name, long id): _name(name), _id(id) {};
string getNmae() { return _name; };
void setName(string name) { _name = name; };
long getID() { return _id; };
void setID(long id) { _id = id; };
User getUser() { return *this; };
static User addUser(string name, long id) {}; // ... private:
string _name;
long _id;
}; class SongSelector {
public:
Song getCurrentSong() {}; // ...
}; class Jukebox {
public:
Jukebox(CDPlayer cdPlayer, User user, set<CD> cdCollection, SongSelector ts): _cdPlayer(cdPlayer), _user(user), _cdCollection(cdCollection), _ts(ts) {};
Song getCurrentSong() {
return _ts.getCurrentSong();
}
void setUser(User u) {
_user = u;
} private:
CDPlayer _cdPlayer;
User _user;
set<CD> _cdCollection;
SongSelector _ts;
};

[CareerCup] 8.3 Musical Jukebox 点唱机的更多相关文章

  1. CareerCup All in One 题目汇总 (未完待续...)

    Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...

  2. CareerCup All in One 题目汇总

    Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...

  3. 《Cracking the Coding Interview》——第8章:面向对象设计——题目3

    2014-04-23 18:10 题目:设计一个点唱机. 解法:英文叫Musical Jukebox.这是点唱机么?卡拉OK么?这种题目实在是云里雾里,又没有交流的余地,我索性用一个vector来表示 ...

  4. POJ1743 Musical Theme [后缀数组]

    Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27539   Accepted: 9290 De ...

  5. [CareerCup] 18.1 Add Two Numbers 两数相加

    18.1 Write a function that adds two numbers. You should not use + or any arithmetic operators. 这道题让我 ...

  6. [CareerCup] 17.2 Tic Tac Toe 井字棋游戏

    17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...

  7. POJ 1743 Musical Theme 二分+后缀数组

    Musical Theme   Description A musical melody is represented as a sequence of N (1<=N<=20000)no ...

  8. [CareerCup] 18.12 Largest Sum Submatrix 和最大的子矩阵

    18.12 Given an NxN matrix of positive and negative integers, write code to find the submatrix with t ...

  9. [CareerCup] 18.11 Maximum Subsquare 最大子方形

    18.11 Imagine you have a square matrix, where each cell (pixel) is either black or white. Design an ...

随机推荐

  1. Objective-C之代理设计模式小实例

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  2. 做一些Spring AOP做过的事,封装 jdk动态代理成为一个黑盒子

      怎么使用eclise 抽取方法,请看  利用eclipse 抽取代码片段为方法   抽取完成之后,还需要 ① 将Collection.class换成  target.getClass(),targ ...

  3. canvas & animation

    1.using canvas using canvas to set difference property. it will showing like an animation. The true ...

  4. WP开发-Toolkit组件 列表采集器(ListPicker)的使用

    列表采集器ListPicker在作用上与html中的<select/>标签一样 都是提供多选一功能,区别在于ListPicker可以自定义下拉状态和非下拉状态的样式. 1.模板设置 Lis ...

  5. 安装node.js+express for win7的Web开发环境配置

    1.安装 node.js. 进入官网的下载地址:http://www.nodejs.org/download/ . 选择Windows Installer或者选择Windows Installer ( ...

  6. java微信接口之五—消息分组群发

    一.微信消息分组群发接口简介 1.请求:该请求是使用post提交地址为: https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_t ...

  7. Sublime Text3 C++及Java开发环境配置

    一.C++开发环境配置 1. 下载MingW 2. 环境变量配置,系统属性->高级设置->环境变量,如果Mingw装在c盘更目录,其它自己思考 (1)PATH  变量值中加入 C:\Min ...

  8. (二)我的Makefile学习冲动&&编译过程概述

    前言 一 年轻的冲动 二 学习曲线 1 Makefile基本语法 2 bash基础 3 world 三 编译过程概述 1 主机预装工具 2 编译host工具 3 编译交叉工具链 4 编译内核模块 5 ...

  9. hdu 5862 Counting Intersections

    传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...

  10. 2014 Super Training #1 C Ice-sugar Gourd 模拟,扫描线

    原题 HDU 3363 http://acm.hdu.edu.cn/showproblem.php?pid=3363 给你一个串,串中有H跟T两种字符,然后切任意刀,使得能把H跟T各自分为原来的一半. ...