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.
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.
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.
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.
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.
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.
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: