Computer Science 1622
Computer Science II

Programming Assignment 4
Arrays of Structures, Strings, Sorting (40 points)
Due Monday, February 8, 1998

The Problem

In this assignment you will develop a simple database that stores information about a person's set of compact discs. Operations that can be performed on the database are:

Notes on the program:

Getting Started

I suggest you use the following definitions for the data structure to hold the CD information:
  #define MAXCDS 25
  #define NAMELENGTH 16 
   
  typedef enum { MC_Alternative = 0, MC_ClassicRock, MC_HeavyMetal, MC_Pop } Music_Category;
  #define MAXCATEGORY 4
   
  typedef struct {
    int minutes;
    int seconds;
  } Length_Struct;
  
  typedef struct {
    char group_name[NAMELENGTH];
    char CD_name[NAMELENGTH];
    float cost;
    int num_tracks;
    float rating;
    Length_Struct length;
    int in_category[MAXCATEGORY];
  } CD_Struct;

Your function main should look like this:

  void main() {
    int num_CDs = 0;
    CD_Struct CDs[MAXCDS];
    char option;
  
    do {
      Menu();
      printf("Option: ");
      scanf(" %c",&option);
      Read_To_Newline(stdin);
      switch (option) {
        case 'I': case 'i': Insert_CD(CDs,&num_CDs); break;
        case 'D': case 'd': Delete_CD(CDs,&num_CDs); break;
        case 'C': case 'c': Print_Categories(CDs,num_CDs); break;
        case 'N': case 'n': Sort_CDs_By_Name(CDs,num_CDs); break;
        case 'R': case 'r': Sort_CDs_By_Rating(CDs,num_CDs); break;
        case 'P': case 'p': Print_CDs(CDs,num_CDs); break;
        case 'Q': case 'q': break;
        default:
          printf("Unknown menu option %c!\n",option);
      }
    } while ((option != 'Q') && (option != 'q'));
  }

What To Hand In

Hand in a full lab report for your program (consult the Programming Assignment Report Guidelines on what to include in this). Also include a listing of the data you used to test your program (you should discuss in your lab report what test data you used and whether this fully tests your solution). Finally you should attach output for your data showing that your program performs correctly.

Extra Credit - 10 points

Add two routines to your program, one at the end of the program and one at the beginning. The routine at the end of the program should save all of the CDs currently in the database to a file (you will need to figure out a format for the file). The routine at the beginning of the program should read in the file of CDs you saved the last time you ran the program (so that you will have all of the data you entered the last time you ran your program).