For this assignment, you will write a program that maintains a database of music, using a linked list.                 
The program has four commands:                 
Command | Purpose |
---|---|
a title,artist | Add the given song to the database. |
d title,artist | Delete the given song from the database. |
l | List everything in the database. |
q | Quit the program. |
User input looks like this:                 
% gcc -std=c99 music.c -o music % ./music Welcome to the song database! Command: l There are no songs. Command: a Yellow Submarine,Beatles "Yellow Submarine" by "Beatles" added. Command: a Hey Jude,Beatles "Hey Jude" by "Beatles" added. Command: a Mamma Mia,Abba "Mamma Mia" by "Abba" added. Command: a Reform School Musical,Various Artists "Reform School Musical" by "Various Artists" added. Command: l Artist Title ------ ----- Abba Mamma Mia Beatles Hey Jude Beatles Yellow Submarine Various Artists Reform School Musical Command: d A Good Song,Eminem "A Good Song" by "Eminem" not found. Command: d Hey Jude,Beatles "Hey Jude" by "Beatles" deleted. Command: l Artist Title ------ ----- Abba Mamma Mia Beatles Yellow Submarine Various Artists Reform School Musical Command: q Happy listening!
You must use this structure for your linked list:                 
struct Song { char title[24]; char artist[24]; struct Song *next; };
You must write the following functions:                 
void show_all(struct Song *head)
void add_song(struct Song **ptr_to_head, char *title, char *artist)
void delete_song(struct Song **ptr_to_head, char *title, char *artist)
You may write other functions, as needed.
You won’t get far without writing main()
.
                
show_all()
takes a struct Song *
, but add_song()
and
delete_song()
take a struct Song **
. Really.
I’d do the program in this order:                 
show_all()
.
a
” command,
and just use printf()
to display what the title & artist are,
without bothering to actually insert anything into a list.
add_song()
, but don’t insert the song in
alphabetical order, at first.
Just insert it at the beginning of the list.
add_song()
to insert the song in the proper place.
delete_song()
.
This assignment is worth 5 points. You’ll lose points if you submit a file that:                 
music.c
{ }
for no reason
Use                 
~cs157/bin/checkin HW4 music.c
or web checkin                 
Modified: 2017-11-19T18:48                  User: Guest                  Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |