CSCE 2004 - Homework 7
Due Date - 12/12/2013 at 11:59 PM

1. Problem Statement:

The primary goal of this programming assignment is to give students more experience defining and implementing classes, as well as using classes in their program. In the previous homework, you have written a Song class and used it in your program. This assignment will make some improvements to the Song class and introduce another class called Song_Library. The Song_Library class consists of a collection of Songs, and a number of actions on this collection that are similar to what you might see in an iTunes playlist. In particular, operations to initialize the list of songs, to sort the list according to the song title, to sort the list according to song length, to randomly shuffle the list of songs, and to print the list of songs to the screen. Many of these operations are similar to what you implemented in the previous homework, but this time we will be packaging them up into Song_Library class to make them easier for other programmers to use.

2. Design:

Improving the Song Class:

Your first task is to improve your Song class by adding two new methods: get_title and get_length that simply return the title and length fields respectively. These methods may be useful for implementing the sort_title and sort_length methods in the Song_Library class.

class Song
   void set(string t, string g, int y, string a, int l);
   void get(string& t, string& g, int& y, string& a, int& l);
   void print();
   string get_title();
   int get_length();

   string title;
   string genre;
   int year;
   string artist;
   int length;

Creating the Song_Library class:

Your next task is to implement the Song_Library class. As you can see below, this class uses an array of 20 Song objects to store meta data about songs. The private variable "count" stores the number of songs that are currently stored in the "list" array. The first constructor function simply sets the "count" to zero. The second constructor function, reads an ASCII file containing song meta data and stores this information in the "list" and updates the "count". To keep things simple, assume the format of this ASCII file contains five lines of meta data per song. If you add code for skipping blank lines between songs, you can use THIS file for testing purposes.

The Song_Library has five public methods. The "is_empty" method will return true if the count is zero and false otherwise. The "sort_time" method will sort the songs in the "list" in alphabetical order according to their titles. Similarly, "sort_length" will sort the "list" of Songs according to their lengths. The "shuffle" method will randomize the order of the songs in "list". Finally, the "print" method will print all of the songs in the "list" to the screen with one Song per line. Because all of these methods are inside the Song_Library class, they will automatically have access to the private variables "list" and "count", so they do not need to be passed as parameters.

class Song_Library
   Song_Library(string filename);
   bool is_empty();
   void sort_title();
   void sort_length();
   void shuffle();
   void print();

   static const int SIZE = 20;
   Song list[SIZE];
   int count;

3. Implementation:

The code for reading songs from a file instead of prompting the user should be very similar to your code in the previous homework except you will be using "infile" instead of "cin". When you are implementing the sort methods in the Song_library class, you may want to use the "get_title" and "get_length" methods in the Song class instead of just "get". You may also want to add private methods "min_title" and "min_length" to the Song_library class to find the location of the Song with the minimum title or minimum length. Finally, you may want to implement a private method "swap" that exchanges two Songs in the "list".

We have provided a very simple menu-based program HERE to test the methods in the Song_Library class. As you can see, we are not going to put iTunes out of business, but this program gives you something to work with as you write and debug your Song_Library methods. To get your code to compile and run quickly, all you need to do is create empty implementations for all of the methods above. Then, you can add methods one at a time, borrowing from your previous homework, or our posted solutions.

4. Testing:

Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. Try your program with several input values, and save your testing output in text files for inclusion in your project report.

5. Documentation:

When you have completed your C++ program, write a short report (less than one page long) describing what the objectives were, what you did, and the status of the program. Does it work properly for all test cases? Are there any known problems? Save this report in a separate text file to be submitted electronically.

6. Project Submission:

In this class, we will be using electronic project submission to make sure that all students hand their programming projects and labs on time, and to perform automatic analysis of all programs that are submitted. When you have completed the tasks above go to the class web site to "upload" your documentation (a single pdf or txt file), and your C++ program (a single cpp or txt file). Do NOT upload an executable version of your program.

The dates on your electronic submission will be used to verify that you met the due date above. All late projects will receive reduced credit:

You will receive partial credit for all programs that compile even if they do not meet all program requirements, so handing projects in on time is highly recommended.