For this project, you will be implementing the storage portion of a digital music player. You will use an object-­oriented design.

Design and implement the two C++ classes described below. Then implement a driver program (a main function) that tests the functionality of the Song and MP3Player classes. You should design the Song class first, since the MP3Player class will need to call Song member functions.


For each song, you should store the following information (in private instance variables):

• Song title (e.g., “Hey Jude”)

• Artist name (e.g., “The Beatles”)

• Size (the song’s size in MB; a double value that must be non-­‐‑negative)

• Play count (the number of times the song has been played; an int)

• Lyrics (e.g., “Take a sad song and make it better”; one line of the song’s lyrics, used in this assignment to simulate ‘playing’ the song)

You should implement the following functionality for a Song:

• Two constructors: one that takes no arguments (and sets title, artist, and lyrics to empty strings and size to 0.0 MB), and one that accepts a value for title, artist, lyrics, and song size (in that order). Remember to initialize play count appropriately in both constructors. The constructors should prevent the initialization of a negative song size by setting size to 0.0 MB on any negative argument for size.

• Getters for all instance variables, with the following names: getTitle, getArtist, getLyrics, getSize, getPlayCount

• Setters for all instance variables except the play count. Remember that song size cannot be negative; its setter function should set size to 0.0 MB on any negative argument. The setters should have the following names: setTitle, setArtist, setLyrics, setSize

• A toString function to return a string representation of the song in the following format:

Song Title, by Song Artist [X.Y MB] (played Y times)

• A playSong function that manages the value of the play count instance variable, and that prints the following to console out:

NOW PLAYING: Song Title by Song Artist

~~~ song’s lyrics go here ~~~

• Overload the ==, <, and > operators o For ==, two songs are equal if they have the same title and artist values o For < and >, compare only the song title values, unless the song titles are the same, in which case you should compare the artist values instead


The MP3Player stores an array of Song objects. For any given song in the MP3Player, the song title and artist name together must be unique. In other words, you can have three entries for a song called “Landslide” if one artist is “Fleetwood Mac”, one is “The Smashing Pumpkins”, and one is “Dixie Chicks”. Note that this is different than in the first MP3Player project.

When an MP3Player is created, it should dynamically allocate an array of Songs of an integer size specified by the first constructor parameter. The constructor should also accept a parameter specifying the maximum storage capacity of the MP3Player (in MB), as a double. You should also implement a destructor that prevents memory leaks.

The MP3Player should provide the following operations:

• addSong: takes a Song and adds it to the MP3Player. If the MP3Player’s array is full, it should call the resize function first (see below) and then continue with the song add. If the Song exceeds the memory capacity of the MP3Player in MB, the add should fail and the function should return false. If a Song with the same title and artist is already in the MP3Player, the add should fail and the function should return false. If the Song has a size of 0.0, the add should fail and the function should return false.

• removeSong: takes a song title and an artist name (in that order), and removes any matching Song from the MP3Player. Returns true if a Song was removed; false otherwise.

• playSong: takes a song title and an artist name (in that order), and “plays” the matching Song in the MP3Player by adjusting the Song’s play count and printing the following to console:

NOW PLAYING: Song Title by Song Artist

~~~ song’s lyrics go here ~~~

Returns true if the Song was played; false otherwise.

• displayPlaylist: prints to console a list of all songs in the MP3 player in sorted order (from lowest to highest as defined by Song’s < and > operators), with one Song entry per line in the below format:

Song Title, by Song Artist [X.Y MB] (played Y times)

• getRemainingMB: returns the number of MB (a double) of remaining storage capacity available on the MP3Player.

• getSongCount: returns the integer number of Songs stored in the MP3Player

(this is not the same as the size of the Songs array)

The MP3Player must implement at least the following internal (helper) functions:

• resize: doubles the size of the Songs array by allocating a new array and copying all the existing Songs into it. Be sure to clean up any dynamically allocated memory that is no longer needed.

• sort: re-­‐‑orders the Songs in the list into alphabetical order by title, with artist name used in the case of songs with the same title, by using the < (or >) operator over the Song objects.

• search: takes a Song object to search for and returns the index of the match in the Songs array, or a -­‐‑1 if the Song does not exist in the array. You may

implement either a linear or a binary search, but you must use the Song class’s == operator to identify the match.

If there are other helper functions you need in your MP3Player class, you may add additional internal member functions. For example, you may find it useful to have an overloaded search function that takes two strings as parameters (a song title, and an artist name), creates a Song object with that title and artist set, and calls the search function that accepts a Song as an argument.


Your main function should be a driver program that tests the functionality of the

Song and MP3Player classes. See the website for a sample driver program that

MUST compile with your code (without changing the driver program at all).

I recommend expanding the given driver to do more complete testing of your code. The provided driver is a sample; it is possible to have several bugs that will not be exposed by this driver. I will be testing your code using a much more complete driver.

• Your submission must include a Makefile capable of compiling the executable program from three .cpp files. Your files (and Makefile) must use the following names:




MP3Player.cpp MusicDriver.cpp

• Do NOT change the names, return types, or parameter types of any public member functions.

• Be sure to declare all non-­‐‑mutator member functions as const functions.

• Put a header comment at the top of each file.

• Do not add extra I/O to the class functions! The only functions outside of the driver that may produce console output are Song::playSong(), MP3Player::playSong(), and MP3Player::displayPlaylist().

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include "Song.h"

    this->artist = "";
    this->lyrics = "";
    this->size = 0;
    this->title = "";
    this->playCount = 0;

Song::Song(string title, string artist, string lyrics , double size){
    this->artist = artist;
    this->lyrics = lyrics;
    if (size < 0) {
       size = 0;
    this->size = size;
    this->title = title;
    this->playCount = 0;

Song::Song(const Song& o) {
    this->artist = o.artist;
    this->lyrics = o.lyrics;
    this->size = o.size;
    this->title = o.title;
    this->playCount = o.playCount;

Song::~Song() {

string Song::toString() {
    // Song Title, by Song Artist [X.Y MB] (played Y times)
    stringstream ss;
    ss << title << ", by " << artist << setprecision(2) << " [" << size <<" MB] (played " << playCount << " times)";
    return ss.str();

void Song::setArtist(string artist) {
    this->artist = artist;

void Song::setLyrics(string lyrics) {
    this->lyrics = lyrics;
$48.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats