Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write codes in C++ to implement a Song Playlist. 1. Create a playlist using multiple songs. 2. Add songs to the playlist. 3. Remove a

Write codes in C++ to implement a Song Playlist.

1. Create a playlist using multiple songs.

2. Add songs to the playlist.

3. Remove a song from the playlist.

4. Play songs in a loop (for this activity, we will print all the songs once)

Here are the steps to solve the problem:

1. First, design a basic structure that supports circular data representation.

2. After that, implement the insert and erase functions in the structure to support various operations.

3. We have to write a custom iterator. This is a bit tricky. The important thing is to make sure that we are able to traverse the container using a range-based approach for a loop. Hence, begin() and end() should return different addresses, although the structure is circular.

4. After building the container, build a wrapper over it, which will store different songs in the playlist and perform relevant operations, such as next, previous, print all, insert, and remove.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

1. First create the file "SongLinkeList.h, then include the header and write the template node class "cir_list_node" with the required data members. 2. Write the destructor to delete the data from the node. 3. Create the template class "cir_list" write a basic constructor and size function. 4. In the template class write the insert and erase functions. Both will take one value to be inserted or deleted: 5. Create the subclass cir_list_it" as a part of the class cir_list. Write a basic structure for the required iterator and add members to access the actual data. a. Implement the following core function of an iterator - pre- and post increments. cir_list_it& operator++ () cir_list_it operator++(int) b. Add the decrement-related operations to make it bidirectional: cir_list_it& operator-- () cir_list_it operator--(int) c. Implement equality-related operators for the iterator, which are essential for range-based loop friend bool operator==(const cir_list_it& iti, const cir_list_it& it2) friend bool operator!= (const cir_list_it& iti, const cir_list_it& it2) d. Write the begin and end functions with their const versions as well cir_list_it begin() cir_list_it begin() const cir_list_it end() cir_list_it end() const e. Write a copy constructor, initializer list constructor, and destructor. cir_list (const cir_list& other) cir_list (const std::initializer_list& il) -cir_list() 6. Write a class Playlist" for the music player's playlist for our actual application. Instead of storing the songs, we'll just go ahead and store integers indicating the ID of the song for ease of understanding. 7. Declare a public data member cir_list of type int. 8. Implement functions to add and delete songs. void insert (int song) void erase (int song) 9. Implement functions to print all the songs. void loopOnce() 10. A main function is provided for you to use the Playlist class of our music player, and test your code. #include "SongLinkeList.h" int main() { playlist pl; pl.insert(1); pl.insert (2); std::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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago