CS 162 Spring 2000 Assignment 7 –Lists and Creating a class (again) 100 points

Assigned: 03/28/2000

Due: 04/10/2000 at the start of class.

Pairs: You may work in pairs if you want. Note, during the course of the semester, you cannot pair with any one person more than twice. If you work in a pair, turn in ONE copy that is the work of both of you, with both of your names on it. Each member of the pair will receive the same grade for that lab. In such a partnership, students must share as equally as possible the work and learning. Working together with truly shared effort and learning can be a positive experience. However, simply giving/receiving code from someone defeats the learning process. If substantial parts of a program are taken from non-partners, that is plagiarism. The copier and copyee will each receive a zero.

Main Assignment:

You will create a CD class that includes among its data members a list of Songs (using the list standard template and the song class available on my WWW page), the CD Title and Artist, and a main that will use it. The CD class should include constructors, and simple inspectors and mutators, plus member functions: PlayInOrder, PlayRandomOrder, and GetTotalTime (for all songs on the CD) plus any other functions that you need, and a << operator. It can have other data members as you need. You can use my mygetline() function if you like, to avoid any difficulties with getline(). Your main should demonstrate the capabilities of the class, via simulating a CD player, as illustrated below (e.g. it should allow the user to enter songs on a CD (initial setup), choose to play a CD sequentially, or in random order.

Details:

  1. You should do this the right way (as in Account, rather than the simplified War program)-- you should have a .h and a .cpp file for your class, plus a .cpp file for the main.
  2. Classes need a default constructor to allow declaring a variable without giving any values. This can be very basic. You need a CD class copy constructor. You will also either need to have a constructor or other function that allows interaction with the user to build up the contents of the CD song-by-song (rather than building the interaction into main where it might need greater access than it has).
  3. Songs have artists. When filling in the songs on the CD, assume that each song has the same artist as the CD (no various artists compilations) and fill it in (don’t pester the user for it).
  4. Random play should avoid repeats. Hint: one way to do this is to copy the CD into a temporary copy, and choose random songs from the temporary copy, removing songs from the copy as they are played.
  5. The Song class has been updated a little since I used it in class. Get the latest version from the WWW to allow use of == operator for songs, including by list’s remove function (hint, hint)
  6. Main can be really short if you make cd.cpp beefy. My main file is less than a page, but my cd.cpp is almost 5 pages.
  7. The song class defends itself from bad input, not you. You should validate verifiable inputs (e.g. y/n, seconds between 0 and 59).
  8. It is possible that sometime in a class member function that you would have to refer to the current object (rather than just one of its data members or member functions. If you do, *this refers to the (entire) current object.

Hand-in:

1) Listing of the program

2) Disk with your .h and two .cpp files and your working .exe file. NAME YOUR PROGRAM FILES yourlastname7.h, yourlastname7.cpp, and yourlastname7client.cpp; Name your project yourlastname7 so that the executable will be yourlastname7.exe. If you are working in pairs, use both last names (e.g. redmondsmith7.cpp)

Miscellaneous:

1) If you have any questions about what should be done, please ask!!

2) MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors). Test it more than once - I will!

3) Remember: Indentation, meaningful variable names, symbolic constants, and meaningful comments. Weaknesses in any of these could result in points off. Also make sure you put YOUR NAME(s), section, and e-mail address in comments at the beginning of the program.

Sample Interaction:

Enter the CD title: Making Movies

Enter the CD artist: Dire Straits

Enter the song title: Tunnel of Love

Enter the song time in whole minutes 8

Now enter seconds (between 0 and 59) 5

Are there more songs to add? (y or n): y

Enter the song title: Romeo and Juliet

Enter the song time in whole minutes 5

Now enter seconds (between 0 and 59) 50

Are there more songs to add? (y or n): y

Enter the song title: Skateaway

Enter the song time in whole minutes 6

Now enter seconds (between 0 and 59) 15

Are there more songs to add? (y or n): y

Enter the song title: Expresso Love

Enter the song time in whole minutes 5

Now enter seconds (between 0 and 59) 0

Are there more songs to add? (y or n): y

Enter the song title: Hand in Hand

Enter the song time in whole minutes 4

Now enter seconds (between 0 and 59) 46

Are there more songs to add? (y or n): y

Enter the song title: Solid Rock

Enter the song time in whole minutes 3

Now enter seconds (between 0 and 59) 17

Are there more songs to add? (y or n): y

Enter the song title: Les Boys

Enter the song time in whole minutes 4

Now enter seconds (between 0 and 59) 6

Are there more songs to add? (y or n): n

Choose:

1) Play In Order 2) Play Random Order 3) Quit

1

Playing song: 1 Tunnel of Love by Dire Straits lasts 8:05>

Playing song: 2 Romeo and Juliet by Dire Straits lasts 5:50>

Playing song: 3 Skateaway by Dire Straits lasts 6:15>

Playing song: 4 Expresso Love by Dire Straits lasts 5:00>

Playing song: 5 Hand in Hand by Dire Straits lasts 4:46>

Playing song: 6 Solid Rock by Dire Straits lasts 3:17>

Playing song: 7 Les Boys by Dire Straits lasts 4:06>

Played: 37 minutes and 19 seconds

Choose:

1) Play In Order 2) Play Random Order 3) Quit

2

Playing song: Les Boys by Dire Straits lasts 4:06>

Playing song: Solid Rock by Dire Straits lasts 3:17>

Playing song: Hand in Hand by Dire Straits lasts 4:46>

Playing song: Tunnel of Love by Dire Straits lasts 8:05>

Playing song: Expresso Love by Dire Straits lasts 5:00>

Playing song: Romeo and Juliet by Dire Straits lasts 5:50>

Playing song: Skateaway by Dire Straits lasts 6:15>

Played: 37 minutes and 19 seconds

Choose:

    1. Play In Order 2) Play Random Order 3) Quit

3

Goodbye!