CSE 143

Homework #3

Hints, tips, corrections, and announcements

The most recent announcements will be listed first.


4/21/99 Some clarifications.


4/20/99 Some tips on processing files and streams.

  1. First, make sure you understand everything in HW2 (socuser.cpp) where a file is opened and read in.
  2. The demo program is fairly robust; it can detect and recover from a variety of errors in the file.  Your program doesn't have to (this time).  The only error you have to handle (according to the detailed instructions) is if the user types a bad filename.   Otherwise, if there is bad data on the file, and your program blows up, that's OK.
  3. The data file we gave you as a sample is complicated.  It is often effective to get your program running first on simple data.  For example, can your program process a file that has no appointments, just a today's date line? If you can already do this, how about the next step: a file which contains regular (one-time only) appointments, etc. etc.
  4. In addition to the file stream functions mentioned in lecture, the file stream class have a number of other methods.  Take a look at Appendix A.  Some that are mentioned there that you might find helpful at some point include (for an input stream F):   F.get; F.peek; and F.ignore.
  5. Sometimes (not always) there are simple ways to do complex things.  For example, one student told me he was going to read in a date such as 4/19 by reading characters into a string, writing a loop to look for the '/' characters, then converting the numeric characters to integers.  Yes, you can make that work, if you can't think of a simpler way.

4/20/99 What do the functions called from main do?

Now that you have had some time to think about the assignment, here are a few hints on the functions called by main.

upToDate should go through the list of appointments, and remove all the ones before today (incrementing and adding back in any repeating ones!), so that the resulting list only has appointments with valid dates that occur today or later.  It takes as arguments three streams (remember, pass by reference!) so that it can interact with the user if necessary.  The sample solution from which the demo was built only uses the error stream (to see its use, try making an appointment file that has no appointments with good dates, or that has only appointments that occur before the "today" date given on the first line).  The function takes two extra stream arguments because you might want to handle such cases better than we do (of course, you don't have to do so!).

processToday should go through all the appointments that occur today, remove them from the list (again, increment them and add them back in if they repeat), and print out their names.  Try to match the behavior of the demo.

storeFile is pretty straightforward; the only caveat is that the date written to the output file should be tomorrow's date (can you see why?) instead of today's date.   Since today is passed as an argument, storeFile will have to do something to get the date of tomorrow.


4/18/99 Passing streams as parameters.

Streams in C++ are just variables, so there's no reason you can't pass them as parameters to functions.  Make sure you have the type right (istream or ostream).   The one catch is that they should be passed as reference parameters.  Our old friends cout (and cerr, if you are using that) are ostreams, and cin is an istream, so they could also be passed as parameters.  For example, the upToDate function you see called from main might have a prototype like this:  void upToDate(AppointmentList& list, Date now, istream& in, ostream& err, ostream& out); 

Why do this?  It allows you to easily change where the streams are coming from or going to, without changing the function.  One day you pass cout as the parameter for out, and another day, for debugging purposes, you might pass the name of an output file stream that you created in main.  Or you could call such the function twice in the program and have the streams going different places each time.