1) Class creation

Create a class called Song. It will contain the following private attributes:

The song title.

The artist who performs the song

The duration of the song in terms of seconds. A song that lasts 3 minutes and 30 seconds will hold a value of 210.

Create a program that does nothing but instantiates the class.

Compile and fix errors.

2) Constructor Implementation

Declare and Implement a no-arg (default) constructor for this class. The constructor should assign a value of -99 to the duration attribute.

Declare and implement a getter (accessor) for the duration member.

3) Test that the constructor works properly.
After instantiating the class, output the result of the return value from the getter.
So, your main() code should look something like this:

Song mySong;

cout << "The length of the song is:" << mySong.getDuration() << endl;

What value do you expect to see from this output?

4) What's wrong (if anything) with the following code?

Song mySong;

cout << "The title of the song is:" << mySong.title << endl;

5) Create another constructor

Create a second 3-arg constructor that will accept the title of the song, the name of the song's artist, and the duration as arguments. Implement this constructor so that these values are assigned to the correct members.

6) Create getters for the other two members.

7) Test the 3-argument constructor in a way similar to step 3.

8) Create several (at least 2) instances of real-life songs, using the 3-arg constructor (take a guess at the duration if you don't know).

9) Create an array of 3 Songs.

Which of the 2 constructors is run for each Song instance in this case? HINT: You can always test this by putting some debugging output in the constructors.

Recommended Answers

All 7 Replies

Nobody will write it for you. If you're not willing to do it yourself, we're not even willing to help you a little bit.

I wish I had a virtual hand that would reach out and just slap the hell out of anyone who makes a post like this :)

class vhand{ ... };

Come on, dragon. Surely you can manage that!!

>Come on, dragon. Surely you can manage that!!
It's the remote processing that gets a little tricky.

>> It's the remote processing that gets a little tricky.
Don't listen to her! She doesn't believe in you. I know you can do it!

>Don't listen to her! She doesn't believe in you. I know you can do it!
If I can't do it, it's impossible without a good jump in human evolution. :)

commented: Ah. You're not nearly modest enough! +3

But he has wings, Naure. Wings!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.