Lab #7, Wednesday October 11

The purpose of this lab is to introduce you to writing a class in C++.

The following code uses the class "Song" to make a music play list. The play list is stored in the array of Song objects.

int main(int argc, char *argv[])
{
  // Creates an array of songs using the default constructor.
  // The default constructor sets the title and artist to "Undefined"
  // and the seconds to 0.
  Song songs[3];
  // Constructor setting the title, artist, and length in seconds
  Song s1("Lady Java", "Jenny Skavlan", 137);
  Song s2("Code Monkey", "Jonathan Coulton", 229);

  // Copy s1 to slot 0, s2 to slot 2, and default left at slot 1
  songs[0] = s1;
  songs[2] = s2;

  // Loop through each song and "play" them
  for (int i = 0; i < 3; i++)
  {
        cout << "Playing song " << songs[i].getTitle() <<
                " by " << songs[i].getArtist() <<
                " length: " << songs[i].getLength() / 60 <<
                " minutes, " << songs[i].getLength() % 60 <<
                " seconds." << endl;
  }
  return 0;
}
Write the Song class so this code will compile and run. The class should have three private variables: You will also need the following public functions:

The output of your program should look like this:

Playing song Lady Java by Jenny Skavlan length: 2 minutes, 17 seconds.
Playing song Undefined by Undefined length: 0 minutes, 0 seconds.
Playing song Code Monkey by Jonathan Coulton length: 3 minutes, 49 seconds.

Show your code/program to the lab assistant for credit, or email to kjmock@alaska.edu for lab credit.