[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;
};
时间: 2024-10-25 19:53:42

[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 String 1.4 Replace Spaces 1.5 Compress String 1.6 Rotate Image 1.7 Set Matrix Zeroes 1.8 String Rotation Chapter 2. Linked Lists 2.1 Remove Duplicates

poj1743 Musical Theme

地址:http://poj.org/problem?id=1743 题目: Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 28675   Accepted: 9674 Description A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range

POJ1743 Musical Theme [没做出来]

Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27539   Accepted: 9290 Description A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range 1..88, each representing a key on the

[CareerCup] 18.9 Find and Maintain the Median Value 寻找和维护中位数

18.9 Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated. LeetCode上的原题,请参见我之前的博客Find Median from Data Stream. 解法一: priority_queue<int> small; priority_queue<int,

[CareerCup] 18.4 Count Number of Two 统计数字2的个数

18.4 Write a method to count the number of 2s between 0 and n. 这道题给了我们一个整数n,让我们求[0,n]区间内所有2出现的个数,比如如果n=20,那么满足题意的是2, 12, 20,那么返回3即可.LeetCode上有一道很类似的题Factorial Trailing Zeroes,但是那道题求5的个数还包括了因子中的5,比如10里面也有5,这是两题的不同之处.那么首先这题可以用brute force来解,我们对区间内的每一个数字

POJ 1743 Musical Theme (后缀数组)

题目大意: 刚才上88个键弹出来的音符. 如果出现重复的,或者是高一个音阶的重复的都算. 思路分析: 具体可以参考训练指南222. height数组表示按照排序后的sa最近的两个后缀的最长前缀. 将height 分块.然后二分答案,二分答案之后去判断是否满足. 要考虑到不重合,还有大于5. 所以二分的时候要从5开始,然后判断的时候要加一个 up - down >len #include <cstdio> #include <iostream> #include <alg

CareerCup Facebook Total number of substring palindrome

Write a function for retrieving the total number of substring palindromes. For example the input is 'abba' then the possible palindromes= a, b, b, a, bb, abba So the result is 6. Updated at 11/11/2013: After the interview I got know that the O(n^3) s

Careercup | Chapter 4

二叉查换树,左孩子小于等于根,右孩子大于根. 完全二叉树,叶子都在最后一层,所有结点(除了叶子)都有两个孩子. 平衡二叉树,左右子树的高度在一定范围内. 4.1 Implement a function to check if a binary tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that the heights of the two s

CareerCup之1.8 字符串移位包含问题

[题目] 原文: 1.8 Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring ( i.e., "waterbottle" is a rotat