Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

9.17 Main Lab 9 - Playlist (C++ only) This is from zyBooks Deliverables are: Song.cpp, Playlist.cpp, main.cpp, Playlist.h, Song.h Background I have a music player

9.17 Main Lab 9 - Playlist (C++ only)

This is from zyBooks

Deliverables are: Song.cpp, Playlist.cpp, main.cpp, Playlist.h, Song.h

Background

I have a music player on my phone. I can buy songs, add them to playlists and play them. Obviously it would be redundant to store each song in each playlist; each playlist is just a list of pointers to the songs.

For this lab you will simulate this behavior. Your program will need to have options to:

Add songs to the system library (you will store the text of the first line of the song, rather than the audio)

Add playlists

Add songs to a playlist

List playlists

Play a playlist

List all of the songs in the library with a count of how many times each song has been played

Delete a song from a playlist

Delete a playlist

Delete a song from the library (and thus from all playlists that contain it)

Note that we will not be checking many error cases. In real programming this would be bad, you should usually try to recognize and respond to as many types of errors as you can. In the context of class we are trying to acquaint you with as many concepts as possible, so for the sake of educational efficiency we will not be checking most errors in this lab, you may assume that your user provides correct input. You may add all appropriate error testing if you wish, but we will not be testing for it.

Requirements

See the example below to see the expected formatting.

Part 1 - The Menu (10 points)

Prompt the user to select one of several operations:

add Adds a list of songs to the library list Lists all the songs in the library addp Adds a new playlist addsp Adds a song to a playlist listp Lists all the playlists play Plays a playlist delp Deletes a playlist delsp Deletes a song from a playlist delsl Deletes a song from the library (and all playlists) options Prints this options menu quit Quits the program 

After any operation is complete (except for quitting), re-prompt the user to select another operation. If the user enters an unknown option, just print the menu. For part 1, only the quit and options option need work.

Part 2 - Add and display songs (25 points)

For this part you will need to create a song class and vector of pointers to songs. This will be your library of songs.

As songs are added use "new".

At the end of your program free the space for each song using "delete".

Add songs

Prompt the user for the name of the song (you do not need to check for duplicate names).

Prompt the user for the first line of the song.

Initialize the count of how many times this song has been played to 0.

Continue to prompt for songs until the user responds with "STOP".

List all songs - display a list of all of the songs currently in the system and the number of times each song has been played.

Part 3 - Playlists (40 points)

For this part you will need to create a playlist class and a vector of playlists.

Add a playlist

Prompt the user for the name of the playlist (you do not need to check for duplicate names).

Add the new playlist to the vector of playlists.

List a playlist

Add a song to a playlist

List all of the playlists currently in the system and let the user select one of them.

List all of the songs currently in the system and let the user select one of them.

Add a pointer to the selected song into the selected playlist.

Play playlist

List all of the playlist names and let the user select one of them.

"Play" the songs in the play list by printing their first lines.

Whenever a song is played from any playlist, add to the count of how many times it has been played. Note that this is the number of times it has been played, not the number of playlists it is on.

Verify that when you use the "list all songs" operation that the correct count is displayed.

Part 4 - Delete songs and playlists (25 points)

Delete a playlist

Delete a song from a playlist

Note that this does not delete the song from the library

Delete a song from the library. Think about this one!

You will need to first delete the song from any playlist which contains it

You must free the memory that the song object was allocated to (c++ delete)

Then erase it from the library

Deductions graded by TA's

You must create and use a Song class and a PlayList class. (10 points)

You must create and use a vector of Song pointers as the music library. (10 points)

Your playList class must contain and use a vector Song pointers. (10 points)

You must create the class declarations and definitions in separate files as instructed. (10 points)

Always create your own default constructor for each class, and create a parameterized constructor(s) as required. You may combine these into one constructor function by creating a default constructor with default parameters. (5 points each)

You must use new to create your songs and free memory (delete) for any song which you delete from the library, and all songs after you quit the program. If you use pointers for playlists you must also free memory when playlists are deleted. To help the TAs, place a comment about freeing memory next to the lines in your code which free memory, and in your header give the file and line numbers of those lines. (10 points)

Sample Input

options add Paradise When she was just a girl Come come ye saints Come come ye saints, no toil or labor fear Yellow Look at the stars Superheroes All her life she has seen When he comes again I wonder when he comes again, will herald angels sing Time Ticking away the moments that make up a dull day STOP list addp Coding Music addp Sunday Favorites addp Game Day listp addsp 0 2 addsp 0 1 addsp 0 3 addsp 1 1 addsp 1 4 play 0 play 1 list delp 2 listp delsp 0 0 play 0 delsl 1 play 0 play 1 list quit 

Sample Output Visual Studio View

Welcome to the Firstline Player! Enter options to see menu options. Enter your selection now: options add Adds a list of songs to the library list Lists all the songs in the library addp Adds a new playlist addsp Adds a song to a playlist listp Lists all the playlists play Plays a playlist delp Deletes a playlist delsp Deletes a song from a playlist delsl Deletes a song from the library (and all playlists) options Prints this options menu quit Quits the program Enter your selection now: add Read in Song names and first lines (type "STOP" when done): Song Name: Paradise Song's first line: When she was just a girl Song Name: Come come ye saints Song's first line: Come come ye saints, no toil or labor fear Song Name: Yellow Song's first line: Look at the stars Song Name: Superheroes Song's first line: All her life she has seen Song Name: When he comes again Song's first line: I wonder when he comes again, will herald angels sing Song Name: Time Song's first line: Ticking away the moments that make up a dull day Song Name: STOP Enter your selection now: list Paradise: "When she was just a girl", 0 play(s). Come come ye saints: "Come come ye saints, no toil or labor fear", 0 play(s). Yellow: "Look at the stars", 0 play(s). Superheroes: "All her life she has seen", 0 play(s). When he comes again: "I wonder when he comes again, will herald angels sing", 0 play(s). Time: "Ticking away the moments that make up a dull day", 0 play(s). Enter your selection now: addp Playlist name: Coding Music Enter your selection now: addp Playlist name: Sunday Favorites Enter your selection now: addp Playlist name: Game Day Enter your selection now: listp 0: Coding Music 1: Sunday Favorites 2: Game Day Enter your selection now: addsp 0: Coding Music 1: Sunday Favorites 2: Game Day Pick a playlist index number: 0 0: Paradise 1: Come come ye saints 2: Yellow 3: Superheroes 4: When he comes again 5: Time Pick a song index number: 2 Enter your selection now: addsp 0: Coding Music 1: Sunday Favorites 2: Game Day Pick a playlist index number: 0 0: Paradise 1: Come come ye saints 2: Yellow 3: Superheroes 4: When he comes again 5: Time Pick a song index number: 1 Enter your selection now: addsp 0: Coding Music 1: Sunday Favorites 2: Game Day Pick a playlist index number: 0 0: Paradise 1: Come come ye saints 2: Yellow 3: Superheroes 4: When he comes again 5: Time Pick a song index number: 3 Enter your selection now: addsp 0: Coding Music 1: Sunday Favorites 2: Game Day Pick a playlist index number: 1 0: Paradise 1: Come come ye saints 2: Yellow 3: Superheroes 4: When he comes again 5: Time Pick a song index number: 1 Enter your selection now: addsp 0: Coding Music 1: Sunday Favorites 2: Game Day Pick a playlist index number: 1 0: Paradise 1: Come come ye saints 2: Yellow 3: Superheroes 4: When he comes again 5: Time Pick a song index number: 4 Enter your selection now: play 0: Coding Music 1: Sunday Favorites 2: Game Day Pick a playlist index number: 0 Playing first lines of playlist: Coding Music Look at the stars Come come ye saints, no toil or labor fear All her life she has seen Enter your selection now: play 0: Coding Music 1: Sunday Favorites 2: Game Day Pick a playlist index number: 1 Playing first lines of playlist: Sunday Favorites Come come ye saints, no toil or labor fear I wonder when he comes again, will herald angels sing Enter your selection now: list Paradise: "When she was just a girl", 0 play(s). Come come ye saints: "Come come ye saints, no toil or labor fear", 2 play(s). Yellow: "Look at the stars", 1 play(s). Superheroes: "All her life she has seen", 1 play(s). When he comes again: "I wonder when he comes again, will herald angels sing", 1 play(s). Time: "Ticking away the moments that make up a dull day", 0 play(s). Enter your selection now: delp 0: Coding Music 1: Sunday Favorites 2: Game Day Pick a playlist index number to delete: 2 Enter your selection now: listp 0: Coding Music 1: Sunday Favorites Enter your selection now: delsp 0: Coding Music 1: Sunday Favorites Pick a playlist index number: 0 0: Yellow 1: Come come ye saints 2: Superheroes Pick a song index number to delete: 0 Enter your selection now: play 0: Coding Music 1: Sunday Favorites Pick a playlist index number: 0 Playing first lines of playlist: Coding Music Come come ye saints, no toil or labor fear All her life she has seen Enter your selection now: delsl 0: Paradise 1: Come come ye saints 2: Yellow 3: Superheroes 4: When he comes again 5: Time Pick a song index number: 1 Enter your selection now: play 0: Coding Music 1: Sunday Favorites Pick a playlist index number: 0 Playing first lines of playlist: Coding Music All her life she has seen Enter your selection now: play 0: Coding Music 1: Sunday Favorites Pick a playlist index number: 1 Playing first lines of playlist: Sunday Favorites I wonder when he comes again, will herald angels sing Enter your selection now: list Paradise: "When she was just a girl", 0 play(s). Yellow: "Look at the stars", 1 play(s). Superheroes: "All her life she has seen", 3 play(s). When he comes again: "I wonder when he comes again, will herald angels sing", 2 play(s). Time: "Ticking away the moments that make up a dull day", 0 play(s). Enter your selection now: quit Goodbye!

Deliverables are: Song.cpp, Playlist.cpp, main.cpp, Playlist.h, Song.h

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

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

978-0764535376

More Books

Students also viewed these Databases questions