[CareerCup] 8.3 Musical Jukebox 点唱机
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 点唱机的更多相关文章
- CareerCup All in One 题目汇总 (未完待续...)
Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...
- CareerCup All in One 题目汇总
Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目3
2014-04-23 18:10 题目:设计一个点唱机. 解法:英文叫Musical Jukebox.这是点唱机么?卡拉OK么?这种题目实在是云里雾里,又没有交流的余地,我索性用一个vector来表示 ...
- POJ1743 Musical Theme [后缀数组]
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27539 Accepted: 9290 De ...
- [CareerCup] 18.1 Add Two Numbers 两数相加
18.1 Write a function that adds two numbers. You should not use + or any arithmetic operators. 这道题让我 ...
- [CareerCup] 17.2 Tic Tac Toe 井字棋游戏
17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...
- POJ 1743 Musical Theme 二分+后缀数组
Musical Theme Description A musical melody is represented as a sequence of N (1<=N<=20000)no ...
- [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 ...
- [CareerCup] 18.11 Maximum Subsquare 最大子方形
18.11 Imagine you have a square matrix, where each cell (pixel) is either black or white. Design an ...
随机推荐
- Wing IDE 5 的破解
Wing IDE 百度百科 1.安装好Python,已测的是Python 2.7.10: 2.新建一个py文件CalcActivationCode.py(名字自己随便取): 3.CalcActivat ...
- SQL Server 2008 R2——VC++ ADO 操作 重复利用_CommandPtr
==================================声明================================== 本文原创,转载在正文中显要的注明作者和出处,并保证文章的完 ...
- Gulp使用入门操作十一步压缩JS
前提需要安装nodejs 一. 全局安装Gulp npm install -g gulp 二.新建一个 gulpfile.js 文件 chapter2└── gulpfile.js 三.在 gulpf ...
- linux中如何查看进程对应的cpu使用情况?
使用ps aux | grep <进程名>即可查看指定进程的cpu使用情况.
- CentOS下一键安装Openstack
CentOS下一键安装Openstack 系统环境:Oracle VirtualBox 4.38CentOS-6.5-x86_64-bin-DVD1.iso 安装前需要修改 /etc/hosts文件, ...
- linux netstat 命令简解
Netstat 简介: Netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告.常见参数-a (all)显示所有选项,默认不显示LISTEN相 ...
- 杂谈SharpDx中的WIC组件——我们需要WIC的图片编码功能么?
在前文 SharpDX之Direct2D教程II——加载位图文件和保存位图文件 中,发现在VB2010中不能很好的运用SharpDx中的WIC组件进行图片的编码工作.可能是我的设置问题,也可能是Sha ...
- runv kill 流程分析
1.runv/kill.go Action: func(context *cli.Context) 该函数做的工作很简单,就是通过grpc客户端,发送一个grpc请求而已,如下: c.Signal(n ...
- CentOS安装Hypernetes相关问题解法
1.手动编译hyper缺少libdevmapper.h git clone -b v2_02_103 https://git.fedorahosted.org/git/lvm2.git /usr/lo ...
- LeetCode题解-----Median of Two Sorted Arrays
题目描述: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of t ...