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. Windows Server 2012之搭建域控制器DC

    安装域控制器,域(Domain) 1,本地管理员权限 2,设置静态IP 地址 3,至少有一个NTFS分区 4,操作系统版本(web版除外)   设置静态IP地址    dcpromo.exe命令不生效 ...

  2. MongoDB学习笔记——MongoDB 连接配置

    MongoDB连接标准格式: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[dat ...

  3. CentOS下安装MySQL

    首先通过网络链接的方式在线安装上mysql服务器端吧!(备注:我开始登录服务器的时候是用的其他用户而不是超级管理员,所以安装MySQL的时候需要切换到超级管理员才可以实现软件的正确安装.命令则是:su ...

  4. Dos

    一.简介 https://zh.wikipedia.org/wiki/DOS 二.系统下载 http://www.cn-dos.net/newdos/doswarea.htm 三.实用命令 1)查看系 ...

  5. linux文件压缩与打包

    在linux中常见的压缩命令 首先,在linux中压缩文件的扩展名大多是 *.gz gzip程序压缩的文件 *.bz2 bzip2程序压缩的文件 *.tar tar程序打包的数据,并没有压缩过 *.t ...

  6. pushd

    # MAN 手册原文:        pushd [-n] [+n] [-n]        pushd [-n] [dir]               Adds  a  directory to ...

  7. 18 多线程编程 - 《Python 核心编程》

  8. DW与DM

    DW组成部分简介 DW的组成部分有:针对数据源的分析.数据的ETL.数据的存储结构,元数据管理等. 数据源分析 主要是分析要抽取哪些数据,如何抽取(全量还是增量)?它的更新周期是怎么样的?它的数据质量 ...

  9. Android的面孔_Actiyity

    一.什么是Activity? 简单的说:Activity就是布满整个窗口或者悬浮于其他窗口上的交互界面.在一个应用程序中通常由多个Activity构成,都会在Manifest.xml中指定一个主的Ac ...

  10. 保存带有emoji的文本报错解决方案

    今天偶然遇到一个错误,就是保存文本的时候带有了emoji表情,报错了 java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8A\ ...