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
- handin
reference
- The instructor's executable program
you can run to see
the expected behavior of the finished program. To obtain the
sample data file and run the Instructor
Solution enter the following commands on hornet:
cp
-i ~cs101-1/Programs/songdata.txt $HOME
~cs101-1/Programs/playlistcalculator.exe
- Your textbook.
- Your instructor.
- Tutoring Center (Sun-Thur, 7:00-9:00pm)
General constraints
- Keep track of the time you spend
developing the
project. Recommended: Time
Log Form
- NOTE: This project is to be an
individual effort! DO NOT
collaborate with any of your classmates -- or anyone else on this
project. You should think of this project as a take-home
examination. Violating this rule may result in being failed
from the
course.You may not discuss this assignment in any way with
anyone but your instructor or a tutor in the Tutoring Center.
- Your program must not use any global
data; instead you must declare variables that are local to the main
function.
- To receive full credit your program
must implement the
required functions as specified.
- Your program must use the required
functions appropriately.
- Your program must mimic the Instructor
Solution program’s behavior exactly.
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
- The song datafile exists and is named "songdata.txt".
- The maximum length time for a song in the data file is
99 minutes and 59 seconds.
- The song length for songs in the file are positive
integers.
- The length of a song name in the file will be less than 81
characters.
- There will be most 99 songs in the data file.
Constraints:
- The maximum length of a displayed song title is 28
characters. However, when the song is written to the playlist.txt
file, the entire name must be written.
- If the user enters a negative number or a number that isn't a
valid song number, just redisplay the song table. Don't display
any error message.
- Set the available recording time to 50 minutes using a #define
constant so that it can
be easily modified.
Required Function
Specifications
- 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.
- 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.
- 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.
- 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.
- Write a function that saves the selected playlist songs to the
external data file playlist.txt.
Data Structure Constraints
- You must use the following declarations:
/* Column type - the two columns of the display */
typedef enum { left, right } columns;
typedef struct
{
char
song[LINE_LEN]; /* song name */
char artist[LINE_LEN]; /*
who sang it */
int
time;
/* song duration in seconds */
int
year;
/* release year */
columns
column; /* which
column currently contains the song */
}
song_t;
- Hint: Although a cursory examination of the problem may lead you
to
think you need two arrays, one for the left-hand column and one for the
right-hand column, this is not a good idea.
- Create just a
single array of song records and don't move the names
anywhere. Use the column field to indicate which column a song
should be displayed in.
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
- Be
sure to compile and test your code on hornet using the required
compiler flags (-lm -Wall –ansi – pedantic)
one last time just before turning the files in.
- Use
the following handin
command being sure to replace the x with your
section number, for
example
cs101-1, cs101-2, et cetera.
handin
cs101-x Program4 program4.c
- Determine the number of lines of code in your files:
~cs101-1/bin/countloc program4.c
- Complete the programmer productivity summary
form for this project.
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)".
Last modified on 06/06/2007 21:46:47