CSC 161 Program #3"TextMenu"TextMenu is a nice and easy 3rd program, and maybe it's some code you will reuse in the future.
|
LogisticsThis program is worth 4 points, or 4% of your final grade. The pertinent time coordinates:
Some of the fun, new stuff we'll cover includes:
|
||||||||||||||
DescriptionIn Program 3, you will create classes that can be used to create text menus. A text menu is like the interface you probably had in the MorseCode program:
Usually this kind of menu stuff happens in main(). Something like this:
Please assume there is another coder in the wings (let's call her Jane Windows) who wishes to use your code for a Windows-based graphics menu system. This means that you will want to define a abstract base class called Menu and a subclass TextMenu. Jane would then theoretically create her own subclass WindowsMenu, or something like that. Get it? Some more requirements:
|
||||||||||||||
Design RequirementsThe vector class is a part of something called the "Standard Template Library". It's a collection of useful classes that are supported by most C++ compilers. Vectors are like a cool array that gets as big as you need it. It analogous to the convenience C++ strings provide over C-strings. You can read all about vectors starting on page 528 of our text. Check it out! I used a vector object to store the strings that were my menu choices. Use the vector to store pointers to string objects, rather than the string objects themselves, like this: vector<string *> choices; Using string pointers saves your program from copying every string you create.
|
||||||||||||||
GradingShort program this time:
thanks... yow, bill |
||||||||||||||
NotesApr 28, 2005 One of the nice side effect of reusable code (like our little TextMenu here) is the pressure put on the person developing the software to make it bullet-proof. Here's a little code snippet in an effort to make our TextMenu code more hearty... getting the user's menu choice:
Let's examine this code line by line:
See, cin carries its status, or how it is doing, along with it. When cin has a problem one of its flags is set and it stops working until the flag is cleared. try it... yow, bill Coming soon... fixing Bill and Eric's fstream reuse concerns from Morse Code. May 5, 2005 It is acceptable to store a vector of strings rather than string pointers. I'll talk more about this in class. Like this: vector<string> choices; thanks... yow, bill
|