This project will help you show your mastery of strings, vectors (esp. list management), classes, and libraries (as well as other things which came before).
Write a program to handle a user's rolodex files. (A rolodex is a system with tagged cards each representing a 'contact' person. It would contain a name, address, and phone number. In this day and age, it would probably have at least one email address as well and possibly multiple phone numbers.)
Typical operations people want to do to a rolodex entry are:
1) Add entry 2) Edit entry 3) Delete entry 4) Search for entry 5) Print all entries 6) Quit
You can decide what the maximum number of rolodex entries is and how long each part of an entry is (name, address, etc.).
When they choose to edit an entry, give them the option of selecting from the current list entries or returning to the main menu.
Similarly for deleting an entry. Also note that when deleting an entry, you must move all following entries down to fill in the gap.
When they choose to search for an entry, go to a sub-menu:
1) search by Name 2) search by Address 3) search by Phone number 4) search by Email address 5) Return to Main Menu
All searches are to be content searches. (In other words, if the rolodex contains a person named Bob Jones, this person should be found by searches by name of: ob, ob J, Jones, etc. as well as of Bob Jones.) (And not just for names. This should apply to email searches, phone number searches, et al.)
Question: Should you print all matches to a search or just the first one?
All menus are to be choose-able by both number and capitalized letter(s).
Hint: You'll only have one class — most likely. It might look something like this:
class RolodexEntry { string fname, lname; // together or separate? string street, town, state; long zip; short zip_4; string phone, // or 3 short's? (area, exchange, line) email; public: // ...ctor's, accessors, mutators, i/o, equality, etc. };
(But see the options below...)
Hint: This class should have its own library. Other libraries may also be used for collections of functions (like searching a list, etc.).
This assignment is (Level 6).
Add (Level 3) to add a sorting option to the main menu. If they choose to sort, you must let them pick which data item to sort on. Then sort the rolodex entries as they requested.
You must write your own sort function(s) as per our discussions in Chapter 6. You cannot use the sort standard library function!
Tip: Have your class provide a compare method which returns similarly to string::compare (negative, 0, or positive). Its arguments should be a string to compare with and some indication as to which of the data fields to compare the string to (maybe a char or short with provided constants the caller could pass; maybe even an enumeration!).
Something like:
enum CompTo { Name, Street, Town, ... }; class RolodexEntry { public: short compare(const string & comp_this, CompTo to_this); };
(For more on enumerations, see the style guidelines elsewhere on this site. If you use this approach rather than a simple short argument to determine what member variable to compare, I'll throw in an extra (Level 1) for the extra knowledge gained.)
Tip: If you remember that the list is sorted on item X, you can use a binary search when they search for an entry by X next time.
Add (Level 1.5) to make the searching (and/or sorting) case insensitive (ignore upper vs. lower case differences). (Maybe that lab from earlier might help..?)
Add (Level 2) to detect whether the user entered a number or a name at prompts involving a list of the people (including overwrite, delete, and edit). If they've entered a number, proceed as normal. If they've entered a name, use your search capability to decide which contact it was. (If the name matches multiple contacts, you should print a new — hopefully smaller — list of the matches for them to choose from.)
Add (Level 3) to add a second class to manage the list of rolodex entries. This will keep the main uncluttered by list management details. (This can be difficult, though. Keep straight in your head what is a rolodex entry behavior and what is a rolodex/list behavior!)
To get you started:
class Rolodex { vector<RolodexEntry> list; public: bool full(void) const { return false; } bool empty(void) const { return list.empty(); } RolodexEntry get(long index) const; bool set(long index, const RolodexEntry & new_entry); bool add(const RolodexEntry & new_entry); // other methods and constructors };
If you did all above options, this project could be worth as much as (Level 15.5).