(Latest Revision: 03/27/2000)

Discussion of the level two program


  SPECIFICS:

  ++ My "buildList" opens the clients file,
     checks for failure to open file, reads in
     the first integer (numClients), executes a
     for-loop, and then closes the file.  The
     body of the for-loop executes "numClients"
     times.  Each time through the loop, one
     call is made to "getNextClient" and one
     call to "putClientInList".  The foregoing
     two functions are only stubs that do nothing
     except write a message.

  ++ My "doCommands" opens the datecoms file,
     checks for failure to open file, executes a
     do-while loop, and then closes the datecoms
     file.  The body of the loop reads a string
     (data type is actually string).  The code
     then calls "doNewClient", "doUnMatch",
     "doPrintMatch", "doPrintFree", or "doQuit"
     depending on the value of the string read.
     If the string does not match any command,
     the code prints an error message and
     executes exit(-1) to halt the program.  The
     do...  functions are all stubs.

     In addition to printing a message,
     doNewClient and doUnMatch must read enough
     input to get past the current line so that
     functions that read input after they do will
     be reading from the correct place.

     doUnMatch only has to read two more strings
     and ignore them.

     doNewClient reads four strings, ignores
     them, then reads the integer number of
     interests (numInterests), and then reads
     numInterests more strings (using a
     for-loop), and ignores them.

  ++ My "dumpLists" opens the clients.out file,
     checks for failure to open file, calls stub
     functions to get the number of men and
     number of women in the current client
     lists, writes the sum of the two number to
     the file, executes two for-loops, and then
     closes the file.

     The first for-loop works with an index i
     that ranges from 1 to the number of men, and
     calls a stub to write the i-th men's list
     element to the file.

     The second for-loop works with an index i
     that ranges from 1 to the number of women,
     and calls a stub to write the i-th women's
     list element to the file.

     numMen is just a stub that writes a message
     and returns the value 20.  numWomen is the
     same, except it returns 10.  The stub
     writeRecord just writes a message.

  ++ Here are my data types for the level two program:

/* ================================================== */
/*     DATA TYPES                                     */
/* ================================================== */
  /* stub definition for the string list class */
typedef int stringListClass ;

/* definition of the client record */

typedef struct
  {
             string  lastName ;
             string  firstName ;
             string  phoneNum ;
                int  numInterests ;
    stringListClass  interests ;
                int  matchPos ;
  } 
  clientItemType ;  

  /* stub definition for the client list class */
typedef int clientListClass ;
typedef clientListClass clientData[2] ;

 ++ Here are my function prototypes

/* ================================================== */
/*     FUNCTION PROTOTYPES                            */
/* ================================================== */
void buildLists(clientData) ;
     void getNextClient(clientItemType &, char &, ifstream & ) ;
     void putClientInList(clientItemType, char &, clientData) ;

void doCommands(clientData) ;
     void doNewClient(clientData, ifstream &) ;
     void doUnMatch(clientData, ifstream &) ;
     void doPrintMatch(clientData) ;
     void doPrintFree(clientData) ;

void dumpLists(clientData) ;
     int numMen(clientData) ;
     int numWomen(clientData) ;
     void writeRecord(ofstream &, int, clientData, int) ;
/* ================================================== */
/* ================================================== */