CS157

CS157: Intro to C, Part II                

Fall 2017                

HW 4                

CS157 HW4: Music Database                

Objectives                

Description                

For this assignment, you will write a program that maintains a database of music, using a linked list.                 

The program has four commands:                 

CommandPurpose
a title,artistAdd the given song to the database.
d title,artistDelete the given song from the database.
lList everything in the database.
qQuit the program.

Sample Run                

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!

Required Stuff                

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)
Print the entire linked list.
void add_song(struct Song **ptr_to_head, char *title, char *artist)
Add this song to the list.
void delete_song(struct Song **ptr_to_head, char *title, char *artist)
Delete this song from the list.

You may write other functions, as needed. You won’t get far without writing main().                 

Requirements                

Hints                

I’d do the program in this order:                 

  1. Implement show_all().
  2. Implement the parsing (picking apart) for the “a” command, and just use printf() to display what the title & artist are, without bothering to actually insert anything into a list.
  3. Implement add_song(), but don’t insert the song in alphabetical order, at first. Just insert it at the beginning of the list.
  4. Change add_song() to insert the song in the proper place.
  5. Implement delete_song().

Grading                

This assignment is worth 5 points. You’ll lose points if you submit a file that:                 

How to submit your homework:                

Use                 

    ~cs157/bin/checkin HW4 music.c

or web checkin                 

How to receive negative points:                

Turn in someone else’s work.

Modified: 2017-11-19T18:48                 

User: Guest                 

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building