The primary goal of this programming assignment is to give students experience defining, implementing and using classes in their program. In particular, you will be developing a program to store, process and display information about popular songs.
Your first task is to create a "Song" class that captures five pieces of meta data about each song (its title, its genre, its artist, its playing time in seconds, and the year it was created). We are not planning to implement iTunes or Pandora, so you can ignore other kinds of meta data like audio file type (mp3 or wav), audio file size, song popularity, and cost.
Since the "Song" class is very basic, we can use the default copy constructor and default destructor methods that are provided automatically by the compiler. Your "Song" class should implement the following four methods:
The set method uses the parameters provided to change the meta data of the song. It is like an assignment statement in concept, where the old value is replaced by the new value. The get method retrieves the meta data of the song via the reference parameters provided. This is the way in which we may find out the value of a song object or variable. The print method displays the meta data in one line so it can be easily read.
Your next task is to write a main program that uses the "Song" class to store and display information about songs. First, you need to declare an array of Songs that can be used to store meta data for up to 20 songs. Then you need to interactively ask the user to input the five pieces of meta data for each song, looping until the maximum number of songs is reached or the user types ^D (control D) which is the end-of-file character. For testing purposes, HERE is an ASCII file with some song data you could use for input. We have inserted a blank line between songs, but you can delete these lines if you want to use cut/paste to enter song data into your program.
After reading the song data, your program will then use the "Print" method to output all of the song information in the same order it was input. Then, your program should sort the song data in alphabetical order based on the title of the song, and then print the song information a second time. Finally, your program should sort the song data in ascending order based on the playing time, and print the song information a third time. For comparison purposes, HERE is an ASCII file with some sample program output. Your output may look different depending on how you print song data.
Your first task is to design the Song class. The basic class definition is shown below. You need to fill in the missing parameter and variable declarations.
Your next task is to implement the four methods above. Use the examples of classes in the notes and the labs to make sure you have the syntax correct.
Once you have completed the design of the Song class, you still have a few design decisions. First, you must decide how to read in the user input and store the information. Since most titles and author names contain multiple words, you need to come up with a simple way to read the five pieces of meta data into five variables.
Your second design decision is how to print the song data on one line. For example, you could print the fields with spaces or commas separating the fields, or you could use fixed width fields to output the data. One is easier to implement, the other is easier to read.
Your third design decision is how to sort the song data based different keys (title of a song or length of the playing time). Here, you are encouraged to reuse the selection sort algorithm you implemented in hw4, or the bubble sort code discussed in the book and class notes. C++ will let you assign one Song object to another using the "=" operator, so this greatly simplifies the implementation of sort code (you can swap two Songs in an array in just three lines of code).
First you should implement the Song class and use some simple method calls in the main program to debug your class. Next make sure you can read the five attributes of a song. Then read and store songs and so on. It is important to make these changes incrementally one feature at a time, writing comments, adding code, compiling, and debugging. This way, you always have a program that "does something" even if it is not complete.
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: