159k views
2 votes
Write a program in C++ language that implements a music player using Doubly Circular Linked List

using OOP concepts.
This assignment has three parts:
1- Write a class(new type) to define the Song type.
2- Implement the Doubly Circular Linked List, which will operate with Song type.
3- Implement the Music Player
4- Test it in the main function
All Constructors should use the initializer list.
1. Song class
Member variables:
string song Title;//song title
string singerName;//singer name
Member functions:
Song(string, string);
virtual ~Song();
string getSongTitle();
string getSingerName();
void setSongTitle(string);
void setSingerName(string);
Overload << operator, this will help to print an object of type Song.
Answer questions below before implementing class Song:
Which methods should be public and which ones can be private?
Should data members be public or private?

User Jorgusch
by
7.4k points

1 Answer

4 votes

Final answer:

The Song class for a music player in C++ necessitates private member variables for encapsulation and public member functions for externally accessible operations, including overloaded << operator for stream interaction.

Step-by-step explanation:

In the class Song, the member variables song Title and singerName should be private to ensure data encapsulation, which is a fundamental principle of Object-Oriented Programming (OOP). The member functions such as constructors, destructors, getters, and setters should be public as they need to be accessed by the objects of class Song. Overloaded operators, like <<, should also be public to allow the Song objects to interact with streams. By doing this, accessing and modifying a Song's details are done through controlled interfaces.

In addition, all constructors should use an initialization list for efficient initialization of member variables. The destructor doesn't need to do much here since no dynamic allocation is involved, but it should be virtual to ensure proper cleanup in case of inheritance.

Overall, the design ensures a clear and easy-to-use API for the Song class while safeguarding the data members from direct external access.

User Splicer
by
7.8k points