Project 3 - A CD Database

Due - May 10, 2004

For this project, you will build on your Lab 8. This program will call upon the functions you wrote for Lab 8 to open a file and build an array of structures which store information about a personal CD collection. This program should the call a function which will show the user a menu and ask the user which operation she would like to perform. The operations you should implement are the following:
  1. Add a New CD: If the user chooses to add a new CD to her collection, you should ask her for the name of the artist and name of the album she would like to add. Store this information in the appropriate position in the array and perform any other necessary updates.
  2. Delete a CD: If the user chooses to delete a CD from her collection, you should ask her which CD she would like to delete. The user should enter a number corresponding to the selected CD and your program should delete that entry from the array.
  3. Search: If the user chooses to search for a particular artist, your program should ask the user which artist she would like to search for. Then, perform a linear search of the array and print out any CDs by that artist.
  4. Quit: If the user chooses to quit, you should ask the user for the name of the file where she would like to save the updated collection. Then, save all of the information stored in the array into a file with that name. Make sure you also store the number of CDs in the collection as the first character(s) of the file.
An example run of your program might look as follows:

Your Collection:
(1 of 3)
Artist: Madonna
Album: Like a Prayer

(2 of 3)
Artist: Talking Heads
Album: Naked

(3 of 3)
Artist: Amos, Tori
Album: Little Earthquakes

*******************************************************************
Select an operation:
1: Add a CD
2: Delete a CD
3: Search for CDs by artist
4: Quit
> 1
Enter the name of the artist: Madonna
Enter the name of the album: Immaculate Collection
Your Collection:
(1 of 4)
Artist: Madonna
Album: Like a Prayer

(2 of 4)
Artist: Talking Heads
Album: Naked

(3 of 4)
Artist: Amos, Tori
Album: Little Earthquakes

(4 of 4)
Artist: Madonna
Album: Immaculate Collection

*******************************************************************
Select an operation:
1: Add a CD
2: Delete a CD
3: Search for CDs by artist
4: Quit
> 3
Enter the name to search for: Madonna
Artist: Madonna
Album: Like a Prayer

Artist: Madonna
Album: Immaculate Collection

*******************************************************************
Select an operation:
1: Add a CD
2: Delete a CD
3: Search for CDs by artist
4: Quit
> 2
Enter number of CD to delete: 3
Confirm: Deleting Amos, Tori? y
Your Collection:
(1 of 3)
Artist: Madonna
Album: Like a Prayer

(2 of 3)
Artist: Talking Heads
Album: Naked

(3 of 3)
Artist: Madonna
Album: Immaculate Collection

*******************************************************************
Select an operation:
1: Add a CD
2: Delete a CD
3: Search for CDs by artist
4: Quit
> 4
Enter file name: collection.txt
Saved...

Hints

  1. You should include the string.h library so that you can use the string comparison and manipulation functions. See page 433 of your text for a list of string functions.
  2. The function strcmp will only return 0 if the strings are EXACTLY the same.
  3. To make your delete function easier to implement, modify your print function to print out a number associated with each CD as shown above. For example, print (1 of 3) above the first CD in a collection of 3.
  4. Use gets to read a string containing spaces from standard input. To ensure that the string you read from the keyboard does not include the newline character, you will need to do something similar to the following (see page 444 of the text):
    if(line[strlen(line) - 1] == '\n') {
      line[strlen(line) - 1] = '\0';
    }
  5. Make sure all of your functions perform all necessary error checking. For example, a user cannot add a new CD if the number of CDs in the collection is 50.

Extra Credit Opportunities

  1. Implement a function to sort the list of CDs. You should sort the list after you read it in from the file, and resort the list after every change (addition or deletion). Anytime the list is printed for the user, it should be in sorted order. You should use the selection sort algorithm from Section 8.6 of the text.
  2. Store your structures in a linked list instead of an array.

  1. Make sure that each function is well documented.
  2. Make sure a lab assistant (Dianne or I) has seen your program run. I will schedule additional lab times during the final exam period for this purpose.
  3. Copy and paste the output of your program to the bottom of your program itself. Make sure the output is a comment. That means, put a /* before the output and a */ after the output.
  4. Make sure all of your functions perform all necessary error checking.

Sami Rollins