CPE/CSC 101
Spring 2007
Programming Project #4

Due Date

Test Plan due Thursday 31 May at class time.
Completed program due Friday 8 June 5:00pm.

You must turn in your source electronically on Hornet using the handin command by this deadline.   Instructions are provided below.
No extensions will be granted! No late submittals will be accepted!  

Playlist Time Calculator

A popular pasttime among music collectors is creating "mix" tapes or cd's that contain a variety of songs taken from different albums.  One frequent task is to determine if the total time of the songs selected for recording is less than the time available on the recording media (CD or audio tape).  You are to write a computer program to assist with that task.

Resources

cp -i ~cs101-1/Programs/songdata.txt  $HOME
~cs101-1/Programs/playlistcalculator.exe

General constraints

Requirements

The user will create a songlist using a text editor named songdata.txt.  The songlist contains a list of all candidate songs (up to 99 songs in length). Each line of the songlist contains the title of the song, the length of the song in seconds, the artist, and the year the song was released. For example:
songdata.txt

Hey_Jude 181 The_Beatles 1968
Stairway_to_Heaven 180 Led_Zeppelin 1971
Radar_Love 239 Golden_Earring 1974
Riders_On_The_Storm 543 The_Doors 1971
What's_So_Funny?_('bout_Peace,_Love,_and_Understanding) 221 Elvis_Costello 1979
No_Need_To_Argue 347 The_Cranberries 1994
Don't_Get_Fooled_Again 497 The_Who 1971
Thick_As_A_Brick 1265 Jethro_Tull 1972
Close_To_The_Edge 1130 Yes 1972
This_one_song_has_28_letters 001 Nobody 1900

Note that no blanks are allowed in the song or artist names; use underlines to separate words.  When the program begins it reads the songlist and displays the songs so they can be selected by the user.  (If the file can't be opened, display this error message: "Unable to open songdata.txt - missing file?") The song length is converted and displayed as minutes and seconds.

[ 1]  3:01 Hey_Jude
[ 2]  3:00 Stairway_to_Heaven
[ 3]  3:59 Radar_Love
[ 4]  9:03 Riders_On_The_Storm
[ 5]  3:41 What's_So_Funny?_('bout_Peac
[ 6]  5:47 No_Need_To_Argue
[ 7]  8:17 Don't_Get_Fooled_Again
[ 8] 21:05 Thick_As_A_Brick
[ 9] 18:50 Close_To_The_Edge
[10]  0:01 This_one_song_has_28_letters
                                        Total:  0:00   Remaining: 50:00
Song number?

The user selects a song by entering the reference number displayed next to the song.  Songs that have been selected by the user appear in the right hand column.

[ 1]  3:01 Hey_Jude
[ 2]  3:00 Stairway_to_Heaven
[ 3]  3:59 Radar_Love
                                        [ 4]  9:03 Riders_On_The_Storm
[ 5]  3:41 What's_So_Funny?_('bout_Peac
[ 6]  5:47 No_Need_To_Argue
                                        [ 7]  8:17 Don't_Get_Fooled_Again
[ 8] 21:05 Thick_As_A_Brick
[ 9] 18:50 Close_To_The_Edge
[10]  0:01 This_one_song_has_28_letters
                                        Total: 17:20   Remaining: 32:40
Song number?


After each user entry, the table is redisplayed with the song moved to the other column. Songs can be moved from the left column to the right or from the right column to the left. The program should then calculate and display the total time of songs in the right column, as well as the recording time remaining.

When the user attempts to move a song from left to right, make sure there is enough remaining time for the song to fit.  If there isn't don't move the song and display a message saying there is not enough remaining time for that song.

     **** Not enough remaining time for song #1 ****

[ 1]  3:01 Hey_Jude
[ 2]  3:00 Stairway_to_Heaven
[ 3]  3:59 Radar_Love
                                        [ 4]  9:03 Riders_On_The_Storm
[ 5]  3:41 What's_So_Funny?_('bout_Peac
[ 6]  5:47 No_Need_To_Argue
[ 7]  8:17 Don't_Get_Fooled_Again
                                        [ 8] 21:05 Thick_As_A_Brick
                                        [ 9] 18:50 Close_To_The_Edge
[10]  0:01 This_one_song_has_28_letters
                                        Total: 48:58   Remaining:  1:02
Song number? 0
3 records written to playlist.txt.

Exit the program by entering a song number of 0.

When the user exits the program, all the songs currently shown in the playlist are written to a data file, playlist.txt, which has the format as shown in this example:
 543 1971 Riders_On_The_Storm            The_Doors                     
1265 1972 Thick_As_A_Brick               Jethro_Tull                   
1130 1972 Close_To_The_Edge              Yes    
The number of songs written to the data file is displayed (using the format shown in the example above).


You may assume
Constraints:

Required Function Specifications

  1. Write a function with this prototype
         void showTime(int seconds);
    that accepts a time as a whole number of seconds and displays it as minutes and seconds using a print formatter of "%2d:%02d".  Use this function whenever you need to display the time.

  2. Write a function that reads the datafile and stores the values in your internal data structure (array of records).  The function returns an int that is the number of songs read from the file.

  3. Write a function to compute the remaining time of the songs in the the right-hand column and return it as a whole number of seconds. One parameter to this function is the list of songs, but there will be others needed as well.

  4. Write a function that displays the two column table of songs and the total and remaining time.  You will need to provide as input parameters to this function all the data it needs to display.

  5. Write a function that saves the selected playlist songs to the external data file playlist.txt.

Data Structure Constraints

Testing

You are required to write a test plan for your program.  Use the Test Plan form that we have used in class to describe the input data and expected outputs of your program.   Your test plan should include enough test cases to demonstrate minimum complete coverage.  That is, your test data must cause every statement in the program to be executed, and produce correct results. 

Here is a sample run with the instructor's test data.

Grading
10% Test Plan provides minimum complete coverage
40%  Correct functionality; reading data file, displaying the table, selecting and deselecting songs, time calculations, writing playlist file.
15%  Correct design and use of the required functions.
20%  Algorithm design meets quality standards for flexibility, maintainability, etc.
10%  Coding standards are followed.
5%    Clean compile (no warnings using the required compiler flags of –Wall –ansi -pedantic).

Remember, your program will be tested on Hornet.  Code that does not compile will receive a grade of zero.

Handing in Your Source Electronically
       handin  cs101-x  Program4  program4.c


Optional (Possible extra credit).

To make the assignment more challenging, choose from the following enhancements:
Extra Challenge 1:   Have the songs in the playlist (the right-hand column) appear on consecutive lines (with no blank lines interspersed).
Extra Challenge 2:   Have the input file follow the playlist format known as Extended M3U format:
http://www.assistanttools.com/articles/m3u_playlist_format.shtml
Extra Challenge 3:   Delete a song by entering a negative sign in front of the song number.
Extra Challenge 4:   Do input validity checking.
Extra Challenge 5:  Have the "Song Number?" prompt display the range of available songs, e.g., "(1-9)".