This is a 2-week lab, with a milestone demonstration due within 1 week.
ln Lab 3, you wrote a console-based application that searched text files for all occurrences of a given string within the file. In this lab, your program will appear to work as before (identically, in fact) from the user's perspective, but you will internally modify your program according to a substantially different design of the internal components.
The UML diagram illustrating the skeletal structure of your modified application is shown below:
The FileTextSearcher class implements the attributes and methods in the UML class diagram; in addition:
the getNextSearchResult() method of FileTextSearcher is superceded by getSearchResults(). The getSearchResults() method, rather than being called repeatedly from within your main application, must only be called once. With this single call, this new method now returns a SearchResultsCollection* pointer. The SearchResultsCollection object referenced (pointed to) by the returned pointer actually points to a whole "linked list" of SearchResult objects, which your main application must iterate through in order to retrieve each individual result.
Your SearchResult class must be modified to chain, or point to, additional instances of SearchResult objects, via a private SearchResult* pointer. The last SearchResult object in the chain will contain a NULL SearchResult* pointer called nextResult. Each time a SearchResult object is created, its constructor should initialize this pointer to NULL.
The FileTextSearcher class is the creator of the SearchResultsCollection object and all SearchResult objects that the collection contains. This implies that, somewhere in the search method, the new() operator is being invoked to create all those SearchResult objects. It also causes each new SearchResult object to be added to the SearchResultsCollection by calling the addSearchResult and passing a SearchResult* ponter to that method. (Note that the SearchResultsCollection object should append each new SearchResult object onto the end of its collection, rather than insert it at the beginning.) After creating these objects, your main application receives the pointer to the SearchResultsCollection via a call to the FileTextSearcher method getSearchResults(). Once it has this SearchResultCollection* pointer, your program can iterate through the linked list by following the pointers, beginning with a call to SearchResultCollection's getFirstSearchResult() method.
When your main application is done processing (reporting) the search results, it has to clean up - that is, it has to delete() all of the SearchResult objects in the chain, as well as the SearchResultsCollection object. Thus, while FileTextSearcher takes responsibility for creating the objects, in this case it does not bear the burden of disposing of them, and leaves that up to your main (or some other global function associated with your main). You have to do this cleanup in the correct order so that you don't "orphan" any objects and cause memory leaks; consider this aspect of the assignment very carefully. Note that when you invoke the delete() operator on a pointer (to an object), that object's destructor is automatically called.
This is a 2 week lab, but you must demonstrate the partial implementation no later than during the second lab 4 session; preferably, you will complete this part in the first lab session.
You must also submit your partial implementation (but no report) according to these instructions:
- Navigate to your VS .NET project directory (see this note on configuring the workspace).
- You should have a subdirectory under your VS .NET project directory with the name of the project you used for this lab.
- Upload your submission through WebCT (assignment "Lab 4 Part 1"), selecting only the .cpp, .h, .sln, and .vcproj files from this directory. Upload each file separately; do not zip files.
- Enter the overall time you spent on this lab into the FAST system (for week 5).
The lab report and completed program is due by Tuesday, April 25 at 11pm.
You must demonstrate your finished, working program during the lab 5 session (Wednesday, April 26).
Submit your completed assignment following these instructions:Be sure to keep copies of all your files, in case something gets lost.
- Navigate to your VS .NET project directory (see this note on configuring the workspace).
- You should have a subdirectory under your VS .NET project directory with the name of the project you used for this lab.
- Upload your submission through WebCT (assignment "Lab 4 Part 2"), selecting only the .cpp, .h, .sln, .vcproj, and .doc files from this directory. Upload each file separately; do not zip files.
- Enter the overall time you spent on this lab into the FAST system (for week 6).
Your lab grade will be determined by the following factors:
Program quality