Carleton University
Department of Systems and Computer Engineering
SYSC 2002 - Winter 2009

Assignment 2

Imagine that you are running a travel agency, and have a file containing information upon possible vacations. Within this file (see “vacations.txt”) there are three lines of data for each vacation. The first gives a description of the vacation, the second contains one or more keywords that define what the vacation is all about, and the third gives the departure and return dates.

To better serve your customers, you want a program that will read in the information in this file and then allow searches to be performed. Searches are to involve three criteria. The first of these is vacation length. The customer gets to specify how long a vacation he wants. The second criterion is the customer’s availability. The customer gets to specify his earliest possible departure date and his latest possible return date. And, finally, the customer can specify that he is only interested in vacations that have a certain keyword (e.g. “SUN”) associated with them. If this is at all confusing, running the sample executable (“asst2.exe”) should clear things up pretty quickly. Note that the keyword feature is optional, and can be suppressed by entering “NONE”. In this case the search simply returns all vacations which meet the duration and availability criteria.

This exercise is intended to come you some experience with using classes written by somebody else. You must use both the “Date” class presented in class and the standard “String2002” class. Writing your own classes will come later (assignment #3). To get you started, a main function has been provided (see “skeleton.cpp”). It isn’t really very interesting, and writing it wouldn’t teach you much. You get to write everything else, including the required declaration for structure “vacationInfo”.

The input function (“readVacationData”) is similar in many respects to the corresponding function from assignment #1. You may want to start with the assignment #1 function and modify it as required. Properly dealing with the end of file condition is a bit tricky, and it is easy to end up with code which will work or not work, depending upon whether the person who built the data file bothered to hit “Enter” after entering the final line. If you are in doubt (or in trouble), use the pseudo-code below as a guide. It is robust, and will work properly in either case. Skipping “whitespace” involves advancing through the file, ignoring spaces, tabs, and newlines (collectively known as “whitespace”) until we get to either some other character or the end of the file. The easiest way to do this is to use the “ws” manipulator, as shown below:

       fin >> ws; // skip whitespace

Note that, when the vacation description is read, we want to read the entire line (blanks and all) into the String2002 object. The same is true when reading the keywords for a vacation. The notes explain how to do this.

    loop

       skip all “whitespace”
       attempt to read vacation description
       if read failed
          if eof encountered
             return true // we have reached the end of the file normally
          else
             // something has gone wrong
             return false
          }
       }
       attempt to read keywords
       attempt to read dates
       if read failed
          // something has gone wrong
          return false
       }

    }

You may assume that both all keywords in the data file and all keywords entered by users will always be in uppercase. This eliminates the case issue altogether. If things were otherwise, we could deal with the issue by converting all keywords to uppercase within the program. If you wish, you are of course welcome to do this. The really keen are also invited to attempt more sophisticated keyword matching. A customer might, for example, want “SUN” but not “SEX”.

Be sure to test your program thoroughly. Don’t forget that it should work for any valid data file and not just the short sample data file provided. You are absolutely free to add to this file in order to generate additional testing possibilities, and even to come up with your own data files altogether.

Call your program "vacations.cpp" and submit the entire file.

Updated: Sunday, January 11th, 2008.