Question: Main.cpp #ifndef PLAYLISTENTRY_H #define PLAYLISTENTRY_H #include Song.h class PlayListEntry { public: Song *song; PlayListEntry *next; PlayListEntry *prev; PlayListEntry() { song = nullptr; next = nullptr;

 Main.cpp #ifndef PLAYLISTENTRY_H #define PLAYLISTENTRY_H #include "Song.h" class PlayListEntry { public:Song *song; PlayListEntry *next; PlayListEntry *prev; PlayListEntry() { song = nullptr; next

= nullptr; prev = nullptr; } }; #endif // PLAYLISTENTRY MusicLibrary.cpp #include

#include #include #include #include #include #include #include "MusicLibrary.h" MusicLibrary::MusicLibrary(int maxsongs) { maxSongs

= maxsongs; numSongs = 0; mySongs = new Song[maxsongs]; } MusicLibrary::~MusicLibrary() {

Main.cpp

#ifndef PLAYLISTENTRY_H #define PLAYLISTENTRY_H

#include "Song.h"

class PlayListEntry { public: Song *song; PlayListEntry *next; PlayListEntry *prev;

PlayListEntry() { song = nullptr; next = nullptr; prev = nullptr; } };

#endif // PLAYLISTENTRY

MusicLibrary.cpp

#include #include #include #include #include #include #include #include "MusicLibrary.h"

MusicLibrary::MusicLibrary(int maxsongs) { maxSongs = maxsongs; numSongs = 0; mySongs = new Song[maxsongs]; }

MusicLibrary::~MusicLibrary() { delete[] mySongs; }

int MusicLibrary::getNumSongs () const { return numSongs; }

Song* MusicLibrary::getSong (const int pos ) const { if ( pos > numSongs ) { cout

return &mySongs[pos]; }

bool MusicLibrary::addSong(string title, string artist, string album, int year, int time) { if (numSongs == maxSongs) { cout

return true; }

bool MusicLibrary::addSong(Song& song) { if (numSongs == maxSongs) { cout

return true; }

void MusicLibrary::readSongsFromFile(string filename) {

ifstream input; input.open(filename);

if (input.is_open()) { string line; while ( getline(input, line) ) { string title, artist, album; string s_year, s_time; int year; int time; istringstream inSS(line);

getline(inSS, title, ','); getline(inSS, artist, ','); getline(inSS, album, ','); getline(inSS, s_year, ','); getline(inSS, s_time);

// Trim whitespaces artist.erase(artist.begin(), std::find_if(artist.begin(), artist.end(), [](char ch) {return !isspace(ch); })); album.erase(album.begin(), std::find_if(album.begin(), album.end(), [](char ch) {return !isspace(ch); }));

year = stoi(s_year); time = stoi(s_time); addSong(title, artist, album, year, time); } input.close(); } else { cout

int MusicLibrary::getNumSongsInFile(string filename) { ifstream input; int lines; string line; input.open(filename); if (input.is_open()) { for(lines = 0; getline(input, line); lines++); input.close(); } else { cout

MusicLibrary.h

#ifndef MUSICLIBRARY_H #define MUSICLIBRARY_H

#include #include "Song.h"

using namespace std;

class MusicLibrary { private: int maxSongs; int numSongs; // number of Songs in library Song* mySongs; // dynamic array storing all Songs

public: MusicLibrary(int maxsongs); ~MusicLibrary();

bool addSong(string title, string artist, string album, int year, int time); bool addSong(Song& song); void readSongsFromFile(string filename);

int getNumSongs () const; Song* getSong (const int pos ) const; static int getNumSongsInFile(string filename); }; #endif // MUSICLIBRARY_H

PlayList.cpp

#include #include "PlayList.h"

PlayList::PlayList () { firstSong=nullptr; lastSong=nullptr; numSongs = 0; playTime = 0; } PlayList::PlayList(PlayList& other) { // implement copy-constructor }

PlayList::~PlayList() { // implement destructor }

int PlayList::getPlayListLength() const { return playTime; } int PlayList::getNumSongs() const { return numSongs; }

void PlayList::printList() const { // implement printList() }

PlayListEntry *PlayList::getSong( const int pos ) { // implement getSong() }

void PlayList::appendSong(Song *song) { // implement appendSong()

}

void PlayList::deleteSong(Song *song) { // implement deleteSong }

void PlayList::moveUp(PlayListEntry *song) { // implement moveUp }

void PlayList::reverseOrder() { // implement function reversing the order of Songs }

PlayList.h

#ifndef PLAYLIST_H #define PLAYLIST_H

#include "PlayListEntry.h" #include "Song.h"

using namespace std;

class PlayList { private: PlayListEntry* firstSong; PlayListEntry* lastSong; int numSongs; int playTime; public: PlayList(); PlayList( PlayList& other); ~PlayList();

int getPlayListLength() const; int getNumSongs () const; PlayListEntry *getSong( const int pos ); void printList() const; // Append a Song to the end of the playlist void appendSong(Song *song); // Delete a song from the playlist void deleteSong(Song *song);

// Move a song one spot up in the playlist void moveUp (PlayListEntry *entry);

// Revert the order of songs on the playlist void reverseOrder(); }; #endif // PLAYLIST_H

PlayListEntry.h

#ifndef PLAYLISTENTRY_H #define PLAYLISTENTRY_H

#include "Song.h"

class PlayListEntry { public: Song *song; PlayListEntry *next; PlayListEntry *prev;

PlayListEntry() { song = nullptr; next = nullptr; prev = nullptr; } };

#endif // PLAYLISTENTRY

Song.cpp

#include #include "Song.h"

Song::Song() { Year = 0; PlayTime = 0; }

Song::Song(string title, string artist, string album, int year, int time) : Title(title), Artist(artist), Album(album), Year(year), PlayTime(time) {}

string Song::getTitle() const { return Title; } void Song::setTitle(const string title) { Title = title; }

string Song::getArtist() const { return Artist; } void Song::setArtist(const string artist) { Artist = artist; }

string Song::getAlbum() const { return Album; } void Song::setAlbum(const string album) { Album = album; }

int Song::getYear() const { return Year; } void Song::setYear(const int year) { Year = year; }

int Song::getPlayTime() const { return PlayTime; } void Song::setPlayTime(const int time) { PlayTime = time; }

void Song::printSong () const { cout

Song.h

#ifndef SONG_H #define SONG_H

#include using namespace std;

class Song { private: string Title; string Artist; string Album; int Year; int PlayTime; public: Song(); Song(string title, string artist, string album, int year, int time); string getTitle() const; void setTitle (const string title ); string getArtist() const; void setArtist (const string artist); string getAlbum() const; void setAlbum (const string album); int getYear() const; void setYear (const int year ); int getPlayTime() const; void setPlayTime(const int time ); void printSong() const; }; #endif // SONG_H

Class Song This class provides the abstraction for an individual song, including song title, artist, album, year of publication, and play time in seconds. The class further provides a method printSong which displays relevant information for a Song. Code is provided in Song.h and Song.cpp. Students should not modify these files, but use 'as is'. Class Music Library This class provides the abstraction and implementation for a Music Library, including reading Songs from a file and storing them in the library. Code is provided in Music Library.h and Music Library.cpp. Students should not modify these files, but use 'as is'. Class PlayList This class provides the abstraction for the Playlist. A Playlist is managed as a double linked list, with the content being a *pointer to a Song * in the Music Library. The abstraction for the linked list node is in the class PlayListEntry (file PlayListEntry.h). The header file PlayList.h is fully implemented and does not require any changes. All the work is expected to happen in the file PlayList.cpp. Specifically, students are expected to implement the following functionality: implement the method 'appendSong0 which appends a Song to the doubly linked list. This function is expected to allocate a new PlayListEntry object, corre store the pointer to the song in the objec upda the prev and next pointers in the new PlayListEntry as well as already existing PlayListEntry s (if required), update the number of Songs and the total playtime of the Playlist, as well as the pointers to the first and the last Song in the PlayList (if required). Difficulty level: 3 (scale 1-5) implement the method 'getSong0' which returns a pointer to n-th node in the linked, with n being provided as an input argument. If the linked list does not contain n nodes and no pointer to a Song can be returned the function is expected to return an error message, e.g. if the playlist contains 4 Songs but the code requests song at Position 5: Cannot return Song at position 5 numSongs is 4. Note: the first song in the linked list is at position 0. Difficulty level: 2 (scale 1-5) implement the method 'deleteSong: the method is expected to identify a PlayList Entry given a pointer to a Song, remove the corresponding PlayListEntry from the linked list correctly (i.e. making sure that all prev and next pointers of nearby elements are correctly updated, and numSongs and playTime is updated correctly). If the playlist is empty, the function is expected to return the error Could not find Song. Playlist is empty. If the song identified by the pointer is not part of the playlist, the function is expected to return the error message: Could not find Song in Playlist. Difficulty level: 3 (scale 1-5) implement method 'printList()' which invokes the printSong0 method of each Song in the playlist in the same order as stored in the playlist. Difficulty level: 2 (scale 1-5) implement the method moveUpO' which moves a song identified by a PlayListEntry pointer one sport up in the playlist. If the Song identified by the PlayListEntry is already the first Song in the list, the function is expected to output Already at top of Playlist, cannot move up. and no changes to the linked list are performed. Difficulty level: 4 (scale 1-5) implement the copy constructor of the PlayList class. Difficulty level: 4 (scale 1-5) implement the method 'reverseOrder". This function is expected reverse the order of songs in the playlist, i.e. the last song becomes the first song, the second last song will be the second song...., the first song becomes the last song. Difficulty level: 4.5 ( scale 1-5) Class PlayListEntry This class provides the abstraction required to manage songs in double linked list implemented in the Playlist class. Code is provided in PlayListentry.h. Students should not modify this files, but use 'as is'. main.cpp A main file providing some examples on how the PlayList class is expected to be used is provided. You will most likely have to make changes to this file as part of the development process (e.g. to test some of the functions that you developed in more details), but please DO NOT upload your modification main.cpp to zybooks. The original main.cpp file is expected as part of the zybook tests IMPORTANT Classes and methods names must match exactly for unit testing to succeed. Submissions with hard coded answers will receive a grade of 0. 301700. 1797888 LAB ACTIVITY 25.1.1: Homework 1 - S 21 - Linked Lists 0/100 Submission Instructions Downloadable files main.cpp MusicLibrary.h , MusicLibrary.cpp Song.h Song.cpp Download PlaylistEntry.h PlayList.h PlayList.cpp songs-long.txt Compile command g++ main.cpp MusicLibrary.cpp song.cpp PlayList.cpp -Wall -o We will use this command to compile your code a.out Upload your files below by dragging and dropping into the area or choosing a file on your hard drive. main.cpp Drag file here or Choose on hard drive. MusicLibrary.h Drag file here or Choose on hard drive. MusicLibrary.cpp Drag file here or Choose on hard drive. Song.h Drag file here or Choose on hard drive. Song.cpp Drag file here or Choose on hard drive. PlayListEntry.h Drag file here or Choose on hard drive. PlayList.h Drag file here or Choose on hard drive. PlayList.cpp Drag file here or Choose on hard drive. songs-long - Notepad Eile Edit Format View Help Zoo Station, U2, Achtung Baby, 1991, 203 Youngblood, 5 Seconds of Summer, Youngblood, 2018, 311 Money for Nothing, Dire Straits, Brothers in Arms, 1986, 501 Summer of 69, Bryan Adams, Reckless, 1984, 178 Livin on a Prayer, Bon Jovi, Slippery when Wet, 1986, 241 Mysterious Ways, U2, Achtung Baby, 1991, 203 Bohemian Rapsody, Queen, A Night at the Opera, 1975, 451 Piano Man, Billy Joel, Piano Man, 1973, 263 Suicide Blonde, INXS, X, 1990, 177 Hungry Like a Wolf, Duran Duran, Rio, 1982, 204 One, U2, Achtung Baby, 1991, 217 Beautiful Day, U2, All that you cant leave behind, 2000, 246 Elevation, U2, All that you cant leave behind, 2000, 225 Walk On, U2, All That You Cant Leave Behind, 2000, 295 Youre the Best Thing About Me, U2, Songs of Experience, 2017, 225 Get Out of Your Own Way, U2, Songs of Experience, 2017, 238 Red Flag Day, U2, Songs of Experience, 2017, 199 The Blackout, U2, Songs of Experience, 2017, 285 Class Song This class provides the abstraction for an individual song, including song title, artist, album, year of publication, and play time in seconds. The class further provides a method printSong which displays relevant information for a Song. Code is provided in Song.h and Song.cpp. Students should not modify these files, but use 'as is'. Class Music Library This class provides the abstraction and implementation for a Music Library, including reading Songs from a file and storing them in the library. Code is provided in Music Library.h and Music Library.cpp. Students should not modify these files, but use 'as is'. Class PlayList This class provides the abstraction for the Playlist. A Playlist is managed as a double linked list, with the content being a *pointer to a Song * in the Music Library. The abstraction for the linked list node is in the class PlayListEntry (file PlayListEntry.h). The header file PlayList.h is fully implemented and does not require any changes. All the work is expected to happen in the file PlayList.cpp. Specifically, students are expected to implement the following functionality: implement the method 'appendSong0 which appends a Song to the doubly linked list. This function is expected to allocate a new PlayListEntry object, corre store the pointer to the song in the objec upda the prev and next pointers in the new PlayListEntry as well as already existing PlayListEntry s (if required), update the number of Songs and the total playtime of the Playlist, as well as the pointers to the first and the last Song in the PlayList (if required). Difficulty level: 3 (scale 1-5) implement the method 'getSong0' which returns a pointer to n-th node in the linked, with n being provided as an input argument. If the linked list does not contain n nodes and no pointer to a Song can be returned the function is expected to return an error message, e.g. if the playlist contains 4 Songs but the code requests song at Position 5: Cannot return Song at position 5 numSongs is 4. Note: the first song in the linked list is at position 0. Difficulty level: 2 (scale 1-5) implement the method 'deleteSong: the method is expected to identify a PlayList Entry given a pointer to a Song, remove the corresponding PlayListEntry from the linked list correctly (i.e. making sure that all prev and next pointers of nearby elements are correctly updated, and numSongs and playTime is updated correctly). If the playlist is empty, the function is expected to return the error Could not find Song. Playlist is empty. If the song identified by the pointer is not part of the playlist, the function is expected to return the error message: Could not find Song in Playlist. Difficulty level: 3 (scale 1-5) implement method 'printList()' which invokes the printSong0 method of each Song in the playlist in the same order as stored in the playlist. Difficulty level: 2 (scale 1-5) implement the method moveUpO' which moves a song identified by a PlayListEntry pointer one sport up in the playlist. If the Song identified by the PlayListEntry is already the first Song in the list, the function is expected to output Already at top of Playlist, cannot move up. and no changes to the linked list are performed. Difficulty level: 4 (scale 1-5) implement the copy constructor of the PlayList class. Difficulty level: 4 (scale 1-5) implement the method 'reverseOrder". This function is expected reverse the order of songs in the playlist, i.e. the last song becomes the first song, the second last song will be the second song...., the first song becomes the last song. Difficulty level: 4.5 ( scale 1-5) Class PlayListEntry This class provides the abstraction required to manage songs in double linked list implemented in the Playlist class. Code is provided in PlayListentry.h. Students should not modify this files, but use 'as is'. main.cpp A main file providing some examples on how the PlayList class is expected to be used is provided. You will most likely have to make changes to this file as part of the development process (e.g. to test some of the functions that you developed in more details), but please DO NOT upload your modification main.cpp to zybooks. The original main.cpp file is expected as part of the zybook tests IMPORTANT Classes and methods names must match exactly for unit testing to succeed. Submissions with hard coded answers will receive a grade of 0. 301700. 1797888 LAB ACTIVITY 25.1.1: Homework 1 - S 21 - Linked Lists 0/100 Submission Instructions Downloadable files main.cpp MusicLibrary.h , MusicLibrary.cpp Song.h Song.cpp Download PlaylistEntry.h PlayList.h PlayList.cpp songs-long.txt Compile command g++ main.cpp MusicLibrary.cpp song.cpp PlayList.cpp -Wall -o We will use this command to compile your code a.out Upload your files below by dragging and dropping into the area or choosing a file on your hard drive. main.cpp Drag file here or Choose on hard drive. MusicLibrary.h Drag file here or Choose on hard drive. MusicLibrary.cpp Drag file here or Choose on hard drive. Song.h Drag file here or Choose on hard drive. Song.cpp Drag file here or Choose on hard drive. PlayListEntry.h Drag file here or Choose on hard drive. PlayList.h Drag file here or Choose on hard drive. PlayList.cpp Drag file here or Choose on hard drive. songs-long - Notepad Eile Edit Format View Help Zoo Station, U2, Achtung Baby, 1991, 203 Youngblood, 5 Seconds of Summer, Youngblood, 2018, 311 Money for Nothing, Dire Straits, Brothers in Arms, 1986, 501 Summer of 69, Bryan Adams, Reckless, 1984, 178 Livin on a Prayer, Bon Jovi, Slippery when Wet, 1986, 241 Mysterious Ways, U2, Achtung Baby, 1991, 203 Bohemian Rapsody, Queen, A Night at the Opera, 1975, 451 Piano Man, Billy Joel, Piano Man, 1973, 263 Suicide Blonde, INXS, X, 1990, 177 Hungry Like a Wolf, Duran Duran, Rio, 1982, 204 One, U2, Achtung Baby, 1991, 217 Beautiful Day, U2, All that you cant leave behind, 2000, 246 Elevation, U2, All that you cant leave behind, 2000, 225 Walk On, U2, All That You Cant Leave Behind, 2000, 295 Youre the Best Thing About Me, U2, Songs of Experience, 2017, 225 Get Out of Your Own Way, U2, Songs of Experience, 2017, 238 Red Flag Day, U2, Songs of Experience, 2017, 199 The Blackout, U2, Songs of Experience, 2017, 285

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!