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的可变是如何实现的?

    Objective-C的可变是怎么实现的?      

  2. 数据仓库建模与ETL实践技巧

    数据分析系统的总体架构分为四个部分 —— 源系统.数据仓库.多维数据库.客户端(图一:pic1.bmp) 其中,数据仓库(DW)起到了数据大集中的作用.通过数据抽取,把数据从源系统源源不断地抽取出来, ...

  3. Effective Java 33 Use EnumMap instead of ordinal indexing

    Wrong practice: Putting sets into an array indexed by the type's ordinal /** * Added demo for the &q ...

  4. Report List Controls

    Report风格的ListCtrl的扩展,原文链接地址:http://www.codeproject.com/Articles/5560/Another-Report-List-Control 1.列 ...

  5. JSP过滤器Filter配置过滤类型汇总

    一.配置方法1 映射过滤应用程序中所有资源<filter>    <filter-name>loggerfilter</filter-name>    <fi ...

  6. 通过反射获取SSM的controller层的注解以及注解中的value值

    package com.reflection.test; import java.lang.annotation.Annotation; import java.lang.reflect.Invoca ...

  7. SSL certificate problem unable to get local issuer certificate解决办法

    SSL certificate problem unable to get local issuer certificate 解决办法: 下载:ca-bundle.crt 将它放在自己的wamp或者x ...

  8. 【转载】kafka的工作原理

    http://www.ibm.com/developerworks/cn/opensource/os-cn-kafka/index.html 消息队列 消息队列技术是分布式应用间交换信息的一种技术.消 ...

  9. 探索 OpenStack 之(10):深入镜像服务Glance

    本篇博文来探讨下镜像服务Glance. 0.  基本概念 0.1 基本功能 Glance提供REST API来支持以下镜像操作: 查询 注册 上传 获取 删除 访问权限管理 0.2 Glance RE ...

  10. 编写JS代码的“use strict”严格模式及代码压缩知识

    Javascript的语法比较松散,大家对该门语言的印象可能是“简单”,我认为这恰恰相反.使用严格模式能防止你写出粗制滥造的语法代码来.应用了严格模式后尽管控制台报告的某些错误需要很大精力排除,但是从 ...