Question

Overview: You will be writing classes that implement a playlist simulation for a music streaming app.The...

Overview: You will be writing classes that implement a playlist simulation for a music streaming app.The Playlist class will contain a dynamic array of Song objects, and the Song class contains several pieces of information about a song. You will need to:

1) Finish the writing of two classes: Song and Playlist. The full header file for the Song class has been provided in a file called Song.h.

2) Write a main program (filename menu.cpp) that creates a single Playlist object and then implements a menu interface to allow interaction with the object.

Program Details and Requirements

  1. Using the Song class declaration, write the Song.cpp file and define all of the member functions that are declared in the file Song.h. (Do not change Song.h in any way. Just take the existing class interface and fill in the function definitions). Notice that there are only five genres of songs in this class: COUNTRY, EDM, POP, ROCK, and R&B. The expected functions’ behaviors are described in the comments of this header file.

  2. Write a class called Playlist (filenames should be Playlist.h and Playlist.cpp). A Playlist object should contain at least the following information: the name of the Playlist, the total duration of the Playlist, and a list of songs. There is no size limit to the list of songs, so it should be implemented with a dynamically allocated array (this means you will need a dynamic array of Song objects. Note: std::vector is not allowed here in this assignment!). You can add any public or private functions into the Playlist class that you feel are helpful.

  3. In addition to the Playlist class itself, you will also create a menu program (menu.cpp) to manage the list of songs in an interactive way. However, the Playlist class will do most of the work, and thePlaylist member functions will be the interface between the menu program and the Playlist’s internal data (name, duration, and list of Songs). The menu program (menu.cpp) only takes charge of iteratively interacting with end-users by showing menus, accepting input from end-users, calling corresponding functions provided by the playlist, and showing the results properly to end-users.

  4. Rules for the Playlist class:

    • All member data of class Playlist must be private.

    • There should be NO cin statements inside the Playlist class member functions. To ensure the

      class is more versatile, any user input (i.e., keyboard) described in the menu program below should be done in the menu program itself. Design the Playlist class interface such that any items of information from outside the class are received through parameters of the public member functions.

    • There should be NO cout statements in the Song class outside of the display function.

    • The list of Songs must be implemented with a dynamically allocated array. There should never be more than 5 unused slots in this array (i.e., the number of allocated spaces may be at most 5 slots larger than the number of slots that are actually filled with real data). This means that you will need to ensure that the array allocation expands or shrinks at appropriate times. Whenever the array is resized, print the following a message ("** Array being resized to <number of slots> allocated slots") that states that the array is being resized, and what the

      new size is.

      Example: "** Array being resized to 10 allocated slots".

    • Since dynamic allocation is being used inside the Playlist class, an appropriate destructor

      must be defined, to clean up memory. The class must not allow any memory leaks!

    • You must use the const qualifier in all appropriate places where it makes sense (i.e., const

      member functions and const parameters).

  5. The main program (menu.cpp) you write should create a single Playlist object and then implement a menu interface to allow interaction with the object. The program should begin by asking the user to input a name for the Playlist. This name should be stored in the Playlist object. You may assume user entry will be a string no longer than 20 characters. The name of the playlist will be updated to the value entered by the user, unless the new name is empty or made up of only white spaces. In the latter case display an appropriate message informing the user that the name was invalid and ask the user to enter the data again (example: “Invalid playlist name. Please re-enter:”).

    Your main program should implement the following menu loop (any single letter options should work with BOTH lower and upper case inputs):

A: Add a song to the playlist

F: Find a song in the playlist

R: Rename playlist

S: Remove a song

D: Display the playlist

G: Genre summary

M: Show this Menu
Q: Quit/exit the program

Behavior of menu selections:

All user inputs described in the menu options below should be done in the menu program (not inside the Song or Playlist classes). The input should then be sent to the Playlist class -- the Playlist class member functions should do most of the actual work, since they will have access to the list of songs. For all user inputs (keyboard), assume the following:

  • A song title and artist will always be input as strings (c-style strings), of maximum lengths 40 and 25, respectively. You may assume that the user will NOT enter more characters than the stated limits for these inputs.

  • A playlist’s name will always be input as a string (c-style strings) of maximum length 20. You may assume that the user will NOT enter more characters than the stated limit for this input. If the input is empty or made up of spaces only, display an error message and ask the user to enter the data again (example error message: "Invalid name. Please re-enter: ").

  • When asking for the genre, user entry should always be a single character. The correct values are C, E, P, R, and B; for country, EDM, pop, rock, and R&B, respectively. Uppercase and lowercase inputs should both be accepted. Whenever the user enters any other character for the genre, this is an error -- print an error message and prompt the user to enter the data again (example error message: "Invalid genre entry. Please re-enter: ").

  • User input of a song’s duration should be in seconds, and should be a positive integer. Whenever the user enters a number that is not positive, it is considered an error -- so an error message should be printed and the user should be prompted to re-enter the duration (example error message: "Must enter a positive duration. Please re-enter: "). Note that zero is NOT a positive number.

  • User input of menu options are letters, and both upper and lower case entries should be allowed.

    A: This menu option should allow the adding of a Song to the Playlist. The user will need to type in the song's information. Prompt and allow the user to enter the information in the following order:title, artist, genre, duration. The information should be sent to the Playlist object and stored in its list of songs.

    F: This option should allow the user to search for a Song in the Playlist by title or by artist. When this option is selected, ask the user to enter a search string (may assume user entry will be a string no longer than 40 characters). If the search string matches exactly a Song title, display the information for that Song (output format is described in the display function of the Song class). If the search string matches an artist in the Playlist, display the information for all songs by that artist. Note that a search string could match several songs and several artists. In that case, print the information for all the matches that are found. If no matching songs are found, display an appropriate message informing the user. (example: No songs found).

    R: This option should allow the user to enter a new name for the Playlist. When this option is selected, ask the user to enter a new name for the playlist as a string (may assume user entry will be a string no longer than 20 characters). The name of the playlist will be updated to the value entered by the user, unless the new name is empty or made up of only white spaces. In the latter case no update will be made and an appropriate message informing the user that the name was invalid and no update was performed should be displayed (example: “Invalid playlist name. Playlist name was not updated”).

    S: This option should allow the user to remove a song from the playlist. When this option is selected, ask the user to type in the title of the song and remove this song from the playlist. If there is no such title, inform the user and return to the menu (example: “No songs removed from PlaylistName”). If there is more than one Song with the same title, delete ALL of the songs with that title from the playlist.

    D: This option should display the entire Playlist, one Song per line, in an organized manner (as mentioned in the description of the function display in the Song class). Each line should contain one Song's information, as described in the Song.h file. After this, also display the total number of songs in the playlist, as well as the total duration of the playlist. The duration should be printed as minutes and seconds notation (m:ss).

    If the playlist is empty, an appropriate message should be displayed instead (example: “The playlist <Playlist name> is Empty”).

    G: This option should list the Playlist’s songs for one specific genre. When this option is selected, ask the user to input a genre. For the genre selected, print out the Songs in the Playlist, as in the Display (D) option, but only for the Songs matching the selected genre. After this, also display the number of songs in this genre, as well as the total duration (the sum of the individual durations) of the songs in this genre. The total duration should be printed as minutes and seconds notation (m:ss). If the playlist is empty, an appropriate message should be displayed instead (example: “The playlist <Playlist name> is empty”).

    M: Re-display the menu.

  • Q: Exit the menu program. Upon exiting, print out the playlist and a goodbye message and the length of the playlist (example: Exiting program. Your playlist was m:ss long).

  • Note: the interface for Song.h indicates that all the strings are represented as c-style strings. Please do NOT change the interface! However, inside the implementation of Song and Playlist, if you want to use C++string (don’t forget to #include <string>), that is still allowed. That is, you may need to transform between c-style strings and modern c++ strings in your implementation. On the other hand, you can also consistently use c-style strings in all your implementations.

    General Requirements

  • All member data of the class must be private.

  • Do NOT use std::vector in this assignment. Do not use language or library features, third-party

    libraries, or OS-specific API calls.

  • Adhere to the good programming practices discussed in class (e.g., no global variables, other than

    constants or enumerations, DO NOT #include .cpp files, properly document your code).

  • Your .h files should contain the class declaration only. The .cpp files should contain the member

    function definitions.

  • You only need to do error-checking that is specified in the descriptions above. If something is not specified (e.g. user entering a letter where a number is expected), you may assume that part of the input will not be evaluated;

  • When you write source code, it should be readable and well-documented.

song.h file:

Do NOT change Song.h in any way!

// Song.h -- header file for the Song class
//
// An object of type Song stores information about a single song.
// The variable "category" stores the Genre of the song
// (one of the five items in the enumerated type Genre).

#ifndef 
#define 

enum Genre {COUNTRY, EDM, POP, ROCK, RB};

class Song 
{
public:
    Song();           // Default constructor, sets up blank song object

    void set(const char* t, const char* a, Genre g, int d);

    // the set function should allow incoming data to be received through
    // parameters and loaded into the member data of the object (i.e., this
    // function "sets" the state of the object to the data passed in).
    // The parameters t, a, g, and d represent the title, artist, genre,
    // and duration of the song, respectively.

    const char* getTitle() const;               // returns the title stored in the object
    const char* getArtist() const;      // returns the artist
    int getDuration() const;                // returns the duration
    Genre getGenre() const;                     // returns the genre

    void display() const;                       // described below

private:
    char title[41];         // may assume title is 40 characters or less
    char artist[26];    // may assume artist name is 25 characters or less
    Genre type;
    int duration;       // Duration of a song in seconds.
                        // Must be a positive integer (larger or equal to zero)
};

// display() function
//
// The member function display() should print out one Song object on one line
// by printing its title, artist, genre, and duration. These should be printed such that
// when you print several songs one after the other (see examples below),
// their fields will align under each other. The duration should be printed as minutes
// and seconds notation (m:ss). Examples:
//
// Town Called Malice       The Jam            Rock                3:04
// One Dance                Drake              R&B                 3:25
// Girls Like You           Maroon 5           Pop                 4:30

#endif 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Song.h

@interface Song : NSObject

@property (nonatomic, copy) NSString *artist, *title, *album, *time;

-(void) setSong:(NSString *)theSongName andArtist:(NSString *)theArtist andAlbum:(NSString *)theAlbum andPlayingTime:(NSString *)theTime;

@end

Song.m

#import "Song.h"

@implementation Song

@synthesize title, album, artist, time;

-(void) setSong:(NSString *)theSongName andArtist:(NSString *)theArtist andAlbum:(NSString *)theAlbum andPlayingTime:(NSString *)theTime{

self.title = theSongName;

self.artist = theArtist;

self.album = theAlbum;

self.time = theTime;

}

@end

Playlist.h

#import <Foundation/Foundation.h>

#import "Song.h"

@interface PlayList : NSObject

@property (nonatomic, copy) NSString *playListName;

@property (nonatomic, strong) NSMutableArray *songsCollection;

-(void) addSongToPlayList:(Song *) someSong;

-(void) removeSongFromPlayList:(Song *) theSong;

-(void) print;

-(id) initWithName:(NSString *) listName;

-(id) init;

@end

Playlist.m

#import "PlayList.h"

#import "Song.h"

@implementation PlayList

@synthesize songsCollection, playListName;

-(void) addSongToPlayList:(Song *) someSong{

[songsCollection addObject:someSong];

}

-(id) initWithName:(NSString *)listName{

self = [super init];

if (self) {

self.playListName = listName;

songsCollection = [[NSMutableArray alloc]init];

}

return self;

}

-(id) init {

return [self initWithName:@"No Name"];

}

-(void) removeSongFromPlayList:(Song *)theSong{

[songsCollection removeObjectIdenticalTo:theSong];

}

-(void) print{

NSLog(@"------------------- %@ -------------------------------------",playListName);

for (Song *mySong in songsCollection) {

NSLog(@"%-15s %-25s %-18s %-10s",[mySong.artist UTF8String], [mySong.title UTF8String], [mySong.album UTF8String], [mySong.time UTF8String]);

}

NSLog(@"-----------------------------------------------------------------");

}

@end

MusicCollection.h

#import <Foundation/Foundation.h>

#import "PlayList.h"

@interface MusicCollection : NSObject

@property (nonatomic, copy) NSMutableArray *playlistsCollection;

@property (nonatomic, copy) PlayList *library;

@property (nonatomic, copy) NSString *name;

-(id) initWithName:(NSString *) collectionName;

//-(void) addSongToPlaylist:(Song *) aSong toPlaylist:(PlayList *) playlistName;

//-(void) removeSongFromPlaylist:(Song *) aSong fromPlaylist:(PlayList *) playlistName;

-(void) addPlaylistToCollection:(PlayList *) playListToAdd;

-(void) removePlayListFromCollection:(PlayList *) playListToRemove;

-(void) searchCollection:(NSString *) someCollection;

-(void) list;

@end

MusicCollection.m

#import "MusicCollection.h"

@implementation MusicCollection

@synthesize playlistsCollection, library, name;

-(id) initWithName:(NSString *)collectionName {

self = [super init];

if (self) {

name = [NSString stringWithString:collectionName];

playlistsCollection = [NSMutableArray array];

library = [[PlayList alloc] initWithName:@"Library"];

}

return self;

}

-(void) addPlaylistToCollection:(PlayList *)playListToAdd{

if ([playlistsCollection containsObject: playListToAdd] == NO)

[playlistsCollection addObject: playListToAdd];

for (Song *song in playListToAdd.songsCollection) {

if ([library.songsCollection containsObject:song] == NO)

[library addSongToPlayList:song];

}

}

-(void) removePlayListFromCollection:(PlayList *)playListToRemove {

if ([playlistsCollection containsObject: playListToRemove] == YES)

[playlistsCollection removeObject:playListToRemove];

for (Song *song in playListToRemove.songsCollection)

[library removeSongFromPlayList:song];

}

-(void) list {

for (PlayList *playlist in playlistsCollection)

[playlist print];

}

-(void) searchCollection:(NSString *)someCollection {

NSMutableArray *results = [[NSMutableArray alloc] init];

for (PlayList *lookUp in playlistsCollection) {

if ([lookUp.playListName rangeOfString:someCollection options:NSCaseInsensitiveSearch].location != NSNotFound)

[results addObject:lookUp];

}

for (PlayList *playlists in results) {

[playlists print];

}

}

@end

main.m

#import <Foundation/Foundation.h>

#import "Song.h"

#import "Playlist.h"

#import "MusicCollection.h"

int main(int argc, const char * argv[])

{

@autoreleasepool {

Song *song1 = [[Song alloc] init];

Song *song2 = [[Song alloc] init];

Song *song3 = [[Song alloc] init];

Song *song4 = [[Song alloc] init];

Song *song5 = [[Song alloc] init];

Song *song6 = [[Song alloc] init];

Song *song7 = [[Song alloc] init];

[song1 setSong:@"Heart Attack" andArtist:@"Demi Lovato" andAlbum:@"Demi's Album" andPlayingTime:@"3:15"];

[song2 setSong:@"When I Was Your Man" andArtist:@"Bruno Mars" andAlbum:@"Bruno Album" andPlayingTime:@"1:31"];

[song3 setSong:@"Harlem Shake" andArtist:@"Baauer" andAlbum:@"Baauer Album" andPlayingTime:@"3:22"];

[song4 setSong:@"I believe I Can Fly" andArtist:@"R-Kelly" andAlbum:@"R-Kelly Album" andPlayingTime:@"2:33"];

[song5 setSong:@"A Milli" andArtist:@"Lil Wayne" andAlbum:@"Lil Wayne Album" andPlayingTime:@"1:34"];

[song6 setSong:@"Diamonds" andArtist:@"Rihana" andAlbum:@"Rihana Album" andPlayingTime:@"2:32"];

[song7 setSong:@"Work Hard Play Hard" andArtist:@"Wiz Khalifa" andAlbum:@"Wiz Khalifa Album" andPlayingTime:@"1:54"];

PlayList *playlist1 = [[PlayList alloc] initWithName:@"My Favorit's"];

PlayList *playlist2 = [[PlayList alloc] initWithName:@"Good Time's"];

PlayList *playlist3 = [[PlayList alloc] initWithName:@"Partying"];

PlayList *playlist4 = [[PlayList alloc] initWithName:@"Hip Hop"];

[playlist1 addSongToPlayList:song1];

[playlist1 addSongToPlayList:song2];

[playlist2 addSongToPlayList:song3];

[playlist2 addSongToPlayList:song4];

[playlist3 addSongToPlayList:song5];

[playlist3 addSongToPlayList:song7];

[playlist4 addSongToPlayList:song7];

[playlist4 addSongToPlayList:song6];

[playlist4 addSongToPlayList:song5];

[playlist4 addSongToPlayList:song4];

[playlist4 addSongToPlayList:song3];

[playlist4 addSongToPlayList:song2];

MusicCollection *myCollection = [[MusicCollection alloc] initWithName:@"music"];

[myCollection addPlaylistToCollection:playlist1];

[myCollection addPlaylistToCollection:playlist2];

[myCollection addPlaylistToCollection:playlist3];

[myCollection addPlaylistToCollection:playlist4];

[myCollection list];

[myCollection searchCollection:@"Hip Hop"];

[playlist1 removeSongFromPlayList: song2];

[myCollection removePlayListFromCollection:playlist2];

[myCollection list];

[myCollection.library print];

}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Overview: You will be writing classes that implement a playlist simulation for a music streaming app.The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is a Java text only program. This program will ask if the user wants to...

    This is a Java text only program. This program will ask if the user wants to create a music playlist. If user says he or she would like to create this playlist, then the program should first ask for a name for the playlist and how many songs will be in the playlist. The user should be informed that playlist should have a minimum of 3 songs and a maximum of 10 songs. Next, the program will begin a loop...

  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

  • Program: Playlist (C++) I'm having difficulty figuring out how to get the header file to work....

    Program: Playlist (C++) I'm having difficulty figuring out how to get the header file to work. You will be building a linked list. Make sure to keep track of both the head and tail nodes. (1) Create three files to submit. Playlist.h - Class declaration Playlist.cpp - Class definition main.cpp - main() function Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps. Default constructor (1...

  • Create two classes. Song. Should include the name of the song and the artist Playlist. Should...

    Create two classes. Song. Should include the name of the song and the artist Playlist. Should include a list of song objects from the above class, a title for the list and a description of the list. Specific method requirements below. Functionality You should be able to print both a song and a playlist. Formatting should follow the below examples EXACTLY. I should be able to print a so11ng or a playlist by calling the standard python print function. Format...

  • You will be building a linked list. Make sure to keep track of both the head and tail nodes.

    Ch 8 Program: Playlist (Java)You will be building a linked list. Make sure to keep track of both the head and tail nodes.(1) Create two files to submit.SongEntry.java - Class declarationPlaylist.java - Contains main() methodBuild the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.Private fieldsString uniqueID - Initialized to "none" in default constructorstring songName - Initialized to "none" in default constructorstring artistName - Initialized to "none"...

  • I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp,...

    I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor copy constructor destructor addSong(song tune) adds a single node to the front of the linked list no return value displayList() displays the linked list as formatted in the example below no return value overloaded assignment operator A description of all of these functions is available in the textbook's...

  • Introduction Welcome to Rad.io, you've been hired to work on our music streaming app, think of...

    Introduction Welcome to Rad.io, you've been hired to work on our music streaming app, think of it as Spotify only more rad! You're in charge of handling our customer’s song list. When a user selects a playlist it will load into the list a number of songs. Users can skip to the next song, move to the previous, they can select a song to play next or select a song to add to the end of their list. Objective You...

  • Many of us have large digital music collections that are not always very well organized. It...

    Many of us have large digital music collections that are not always very well organized. It would be nice to have a program that would manipulate our music collection based on attributes such as artist, album title, song title, genre, song length, number times played, and rating. For this assignment you will write a basic digital music manager (DMM). Your DMM program must have a text-based interface which allows the user to select from a main menu of options including:...

  • (1) Create two files to submit: Song.java - Class definition MainClass.java - Contains main() method (2)...

    (1) Create two files to submit: Song.java - Class definition MainClass.java - Contains main() method (2) Build the Song class in Song.java with the following specifications: Private fields String songTitle String songArtist int secDuration Initialize String fields to "Not defined" and numeric to 0. Create overloaded constructor to allow passing of 1 argument (title), 2 (title, artist) and 3 arguments (title, artist, duration). Create public member method printSongInfo () with output formatted as below: Title: Born in the USA Artist:...

  • Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player --...

    Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player -- sorting song lists. In this assignment, you are asked to design a graphic user interface (GUI) for this function. To start, create a Java project named CS235A4_YourName. Then, copy the class Singer and class Song from finished Lab 4 and paste into the created project (src folder). Define another class TestSongGUI to implement a GUI application of sorting songs. Your application must provide the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT