Assignment #10, COP-3337

This assignment asks you to do a dialog-based program that demonstrates the Dictionary class from Assignment #6. Your dialog will behave as follows. Initially there is an empty dictionary. A pair of English/Spanish words can be inserted, or an English word can be deleted, or we can do a lookup of an English word. I have a demo program that you can unzip and run to see what I'm looking for. You do not have to have this exact implementation, but you must have the same basic functionality. You must use the template Dictionary class as given in Assignment #6. Some of you had bugs (especially in Remove); fix them. You may use a friend's Dictionary class, provided you mention this in a comment.

Dialog Specifications

The SUBMIT button processes a query. If an operation fails, pop up an error message. Note that exactly one checkbox is selected at any time; initially set the INSERTcheckbox. The handler for a checkbox click will ensure that the other two checkboxes are turned off. Additionally, when DELETE or LOOKUP is selected, the SPANISH edit box should be made read-only. When the INSERT check box is selected the SPANISH edit box is made writable. For extra credit, when an English word is inserted into the dictionary, it should be added to the choice menu and when it is deleted, it should be removed from the choice menu. The EXIT button should exit the program.

General Strategies

Begin by using the resource editor to layout the components. Then use the class wizard (Member variables tab) to assign class variables that represent the state of the checkboxes and edit boxes. Next, add some routines for the events by going through the class wizard (Message maps tab). The easy events are the exit button and the checkbox buttons. The exit button will call OnOK( ); the checkbox buttons turn off the other two, adjust the SPANISH edit box's writable state, and then call UpdateData. While you're at it, add code to the initialization routine that sets theINSERT checkbox (just call the insert action handler).

The harder part is the SUBMIT button. You will need to add a Dictionary object as a data member of the class. (The class I am talking about is the same class that is having all these new functions added to it). To add the Dictionary object to the class, you'll have to go to the header file and find the class interface. You'll know you found it when you see the state variables for the checkboxes and edit boxes. It is then a simple matter to do the inserts, deletes, and lookups, unless you are also going to do the extra credit, in which case there is a little more work. Remember that if delete or lookup fails, you have to call AfxMessageBox to pop up an error message.

Inserting Into The Combo Box

This part is a little more complicated, so it's extra credit. I'll discuss it in class. You will need to know the magic incantation to add and delete entries from a combo box as the program runs. To do it, you'll need to add a second dictionary that will map the english word to its position in the combo box list. This is needed so the word can be removed from the combox box when it is deleted from the original dictionary. Oy.

Dirty Tricks

There are a couple of little annoyances you should be aware of.
  1. Turn off the precompiled header feature. I couldn't get it to work. Go to Build->Settings->C/C++. Look for Precompiled Headers in the Category droplist.
  2. You will not use the String class anymore. Instead, use CString, which is automatically loaded. It behaves somewhat like String, in that you can copy, compare, get bounds checks, and concatenate with +.
  3. You will need to download your Exception, Vector, and Dictionary classes, both in .h and .cpp. Add the .cpp files to the project.
  4. Templates don't quite work with separate compilation. You will need to add a file that explicitly instantiates the templates. I call this file TemplateHack.cpp. I threw everything into one file, though in practice, there should be one hack file for each instantiation. This allows less recompilation.
  5. Make sure you call UpdateData as appropriate.
  6. When you add the Dictionary data member, you will need to modify the constructor for the class (as usual, the class I am talking about is the one that we keep changing). Recall the the Dictionary must be constructed by providing an ItemNotFound object. This would be done in the constructor's initializer list. The constructor is implemented in the .cpp file where all the action is happening.

What to Submit

Submit the entire project directory on a 3.5" virus-free floppy. Give me a printout of the main class that has been altered by you. You do not have to resubmit the exception, dictionary, or vector classes in a printout (though it should be on the floppy). Include in your printout a statement of what works and what doesn't, and whether or not you are claiming extra credit. Print a few snapshots of your program in action. You can get a snapshot of a window by selecting it and using ALT+PrintScreen. You can then paste the result inside a WORD document. Do that a few times, and print out the WORD document. There are probably other ways to do it.