CS
210 – Fundamentals of Programming I
Spring 2007 – Programming
Project 2, Part A
30 points
Out: April 11 &
12
Due: April 18 & 19
Part A of this first programming project consists of writing the analysis and design for the following problem that meets the given design criteria. The work must be entirely your own, except for any help you may get from the instructor. Hand in a clean, readable copy of your analysis and design.
Part B will be assigned on April 18 & 19. The implementation portion of the project will be due on the last day of class, April 30 & May 1. There will some additional implementation requirements not specified here.
Problem Statement
An on-line music library such as iTunes is a collection of albums that may be rated by a user and used to form playlists from the album tracks. A music library needs to keep track of the albums in its collection and their ratings. (To simplify this problem, we will rate only an album and not the individual tracks) In addition, users want answers to questions like "What albums in this music library were recorded by Bruce Springsteen?"
We would like a program that keeps track of albums in a music library. For each album, the library should keep track of the artist of the album, the title of the album, the genre of the album, the year the album was recorded, a list of song titles (tracks) on the album, and the user's rating for the album.
The program should be menu-driven and allow the user to do the following actions repeatedly:
create an empty music library
add an album to the collection
change the rating of a particular album by giving its artist and title
print out all the information on a particular album by giving its artist and title
print out a table of artists, titles, years, and user rating of all the albums in the library's collection
print out a table of artists, titles, years, and user ratings of albums of the same genre
print out a table of artists, titles, and user ratings of albums recorded in the same year
print out a table of artists, titles, years, and ratings of albums having a user rating at least has high as a given rating
print out a table of titles, years, and user ratings of albums recorded by the same artist
print out a playlist of a given number of randomly chosen tracks from the albums in the collection
print out the number of albums in the collection
See the sample program run for examples of some of these actions.
If an album already exists in the collection when a user tries to add it, the program should ignore the action request. The program should print an error message if the user tries to add an album with a user rating not in range 0-5 inclusive or if the user tries to change an album's user rating to a value not in range 0-5 inclusive. In either case, the application should set the user rating for that album to 0. If no albums match the listing criteria, the program should print a message saying so.
Design Criteria
This program must be designed using a MusicLibrary class to represent the music library. Recall that the analysis and design of a class consists of the specification of the attributes and the analysis and designs of all member (and friend) functions. The MusicLibrary class should contain all of the information and operations necessary to do the library actions given above. In particular, it should contain at least a collection of Album objects. There should only be one (default) constructor that creates an empty MusicLibrary object (i.e., one with an empty collection of albums.) The Album class developed in Programming Assignment 7 should be used to model the data for an album. I.e., you should use Album objects and their operations as needed. You should not add any operations to the Album class or change any of the Album operations.
In addition, there will be an analysis and design of the main program. The main program analysis should consist of at least one MusicLibrary object, and its design should use MusicLibrary member functions to execute the actions of the library. As usual, significant subproblems should be solved using functions. Note that when a class object variable is declared, the default constructor is called automatically, so when the program begins, an empty MusicLibrary object will be created automatically. The creation action is intended to allow the user to replace any existing MusicLibrary object with a new, empty one.
To make keyboard input easier, you should assume all of the string inputs (i.e., artist, title, genre, and song titles) are one "word" and use the regular input operation. Multi-word titles and names will be input with underscores between the words, e.g., Born_to_Run, or without spaces, e.g., NewAge.
Example Program Run
Welcome to the CS 210 Music Library!
An empty music library has been created.
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: B
Please enter the new data in the following order:
artist, title, genre, year,
track list ending in END_OF_TRACKLIST,
and rating separated by spaces or newlines:
Bruce_Springsteen Born_to_Run Rock 1975
Thunder_Road Born_to_Run Jungleland END_OF_TRACKLIST
5
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: B
Please enter the new data in the following order:
artist, title, genre, year,
track list ending in END_OF_TRACKLIST,
and rating separated by spaces or newlines:
U2 Joshua_Tree Rock 1987
Where_the_Streets_Have_No_Name
I_Still_Haven't_Found_What_I'm_Looking_For
With_or_Without_You
END_OF_TRACKLIST
5
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: B
Please enter the new data in the following order:
artist, title, genre, year,
track list ending in END_OF_TRACKLIST,
and rating separated by spaces or newlines:
The_Flaming_Lips Yoshimi_Battles_the_Pink_Robots Rock 2002
Fight_Test Yoshimi_Battles_the_Pink_Robots_Pt1
Do_You_Realize??
Approaching_Pavonis_Mons_by_Balloon_(Utopia_Planitia)
END_OF_TRACKLIST
5
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: B
Please enter the new data in the following order:
artist, title, genre, year,
track list ending in END_OF_TRACKLIST,
and rating separated by spaces or newlines:
Yanni Live_at_the_Acropolis NewAge 1993
Santorini Keys_to_Imagination Reflections of Passion
END_OF_TRACKLIST
4
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: B
Please enter the new data in the following order:
artist, title, genre, year,
track list ending in END_OF_TRACKLIST,
and rating separated by spaces or newlines:
Tim_McGraw Live_Like_You_Were_Dying Country 2004
How_Bad_Do_You_Want_It My_Old_Friend
Live_Like_You_Were_Dying Walk_Like_a_Man
END_OF_TRACKLIST
3
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: E
Artist Title Year Rating
----------------------------------------------------------------
Bruce_Springsteen Born_to_Run 1975 5
U2 Joshua_Tree 1987 5
The_Flaming_Lips Yoshimi_Battles_the_Pink_Robots 2002 5
Yanni Live_at_the_Acropolis 1993 4
Tim_McGraw Live_Like_You_Were_Dying 2004 3
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: D
Please enter the artist: Bruce_Springsteen
Please enter the album title: Born_to_Run
Artist: Bruce_Springsteen
Title: Born_to_Run
Genre: Rock
Year recorded: 1975
Track list:
Thunder_Road
Born_to_Run
Jungleland
User rating: 5
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: I
Please enter the artist: U2
Title Year Rating
---------------------------------------------
Joshua_Tree 1987 5
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: J
How many songs for this playlist? 3
How_Bad_Do_You_Want_It
Reflections of Passion
I_Still_Haven't_Found_What_I'm_Looking_For
Please choose from the following actions:
A. Create a new music library
B. Add a new album to the collection.
C. Change the user rating of an album
D. Print out information about an album
E. Print out a list of all albums
F. Print out a list of albums of the same genre
G. Print out a list of albums recorded in the same year
H. Print out a list of albums having at least a certain rating
I. Print out a list of albums recorded by a particular artist
J. Print out a random playlist of song tracks
K. Print out the number of albums in library collection
Q. Quit the program.
Your choice: Q
Thank you for using the CS 210 Music Library!
04/10/07