Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ -------------------------------------------------------------------------------------------------------------------------- Song.h -------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------- MusicLibrary.h -------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------- PlayList.h -------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------- PlayListEntry.h -------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------- Song.cpp -------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------- MusicLibrary.cpp -------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------- PlayList.cpp #include #include PlayList.h PlayList::PlayList

C++

image text in transcribed

image text in transcribedimage text in transcribed

--------------------------------------------------------------------------------------------------------------------------

Song.h

image text in transcribed

--------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------

MusicLibrary.h

image text in transcribed

--------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------

PlayList.h

image text in transcribed

--------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------

PlayListEntry.h

image text in transcribed

--------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------

Song.cpp

image text in transcribedimage text in transcribed

--------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------

MusicLibrary.cpp

image text in transcribed

image text in transcribed

image text in transcribed

--------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------

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 }

--------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------

main.cpp

#include #include #include

#include "Song.h" #include "MusicLibrary.h" #include "PlayList.h"

using namespace std;

int main(int argc, char** argv) { string filename; int numsongs; int option=0; cout > filename;

cout > option;

if ( option > 2 ) { cout

MusicLibrary mylibrary(numsongs); mylibrary.readSongsFromFile(filename);

// Playlist 1: create a playlist with all songs if ( option == 0 ) { PlayList list1; for ( int i=0; i

if ( option == 1 ) { // Playlist2: only U2 songs PlayList list2; for ( int i=0; i getArtist() == "U2" ) { list2.appendSong (song); } } list2.printList(); }

if ( option == 2 ) { PlayList list1; for ( int i=0; i

--------------------------------------------------------------------------------------------------------------------------

The purpose of this assignment is to developed the code to manage a music playlist. The playlist has to be implemented as a doubly linked list. The code for the assignment is organized as follows: 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 MusicLibrary 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 MusicLibrary.h and MusicLibrary.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 'appendSong(' which appends a Song to the doubly linked list. This function is expected to allocate a new PlayListEntry object, correctly store the pointer to the Song in the object, update 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 PlayListEntry 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 printSong, 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. 1 #ifndef SONG_H #define SONG_H 2 3 4 #include using namespace std; 5 6 7 8 9 10 11 12 13 14 15 16 17 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); 18 19 string getTitle) const; void setTitle (const string title ); string getArtist() const; void setArtist (const string artist); string getAlbum() const; void setAlbum (const string album); 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 int getYear() const; void setYear (const int year); int getPlayTime() const; void setPlayTime(const int time ); void printSong) const; #endif // SONG_H Q#ifndef MUSICLIBRARY_H #define MUSICLIBRARY_|| #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 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 public: MusicLibrary(int maxsongs); MusicLibrary(); bool addSong(string title, string artist, string album, int year, int time); bool addSong(Song& song); void readSongs FromFile(string filename); int getNum Songs () const; Song* getSong (const int pos ) const; static int getNumSongsInFile(string filename); #endif // MUSICLIBRARY_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; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 public: Playlist(); Playlist Playlist& other); wPlaylist(); 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 #ifndef PLAYLISTENTRY_H #define PLAYLISTENTRY_H #include "Song.h" Nm inco class PlaylistEntry { public: Song *song; PlaylistEntry *next; PlaylistEntry *prev; PlaylistEntry() 9 10 11 12 13 14 15 16 17 18 19 20 21 22 song = nullptr; next = nullptr; prev = nullptr; #endif // PLAYLISTENTRY 1 #include _#include "Song.h" 2 3 4 5 Song: :Song) 6 7 8 Year = ; PlayTime - ; 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; 9 10 11 12 10 13 14 15 16 17 18 19 20 20 21 22 23 24 25 26 27 0 28 20. 29 30 31 32 33 34 35 36 37 > 38 39 40 +0 41 * 42 43 void Song::setArtist(const string artist) { Artist = artist; string Song::getAlbum() const { return Album; } void Song::setAlbum(const string album) Album = album; Qint Song::getYear() const { return Year; 44 45 * 46 + 47 48 49 void Song::setYear(const int year) { { Year = year; | } 50 51 52 53 Hint Song::getPlayTime() const { return PlayTime; 54 55 56 void Song::setPlayTime(const int time) { PlayTime time; [ } 57 58 59 60 Qvoid Song::printSong () const { cout #include #include #include #include #include #include #include "MusicLibrary.h" 5 QMusicLibrary::MusicLibrary(int maxsongs) { maxSongs = maxsongs; numSongs = ; mySongs new Song[maxsongs]; MusicLibrary:: MusicLibrary() { delete[] mySongs; } Qint MusicLibrary::getNum Songs () const { return numSongs; } Song* MusicLibrary::getSong (const int pos ) const 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 if (pos > numSongs ) { cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions