Purpose: Way is a GPS navigation system that runs on "smart phones". StreetSmarts is a component in Way that enables users to enter street names using a smart phone's keypad.
Abbreviations, Acronyms:GPS | Global Positioning System |
LCD | Liquid Crystal Display |
Some applications that run on wireless telephones require multiple key presses for some letters. That is, the '2' key is pressed once for an 'A', twice for a 'B', and three times for a 'C'; the '3' key is pressed once for a 'D', twice for an 'E', and three times for an 'F'; etc... This would be both a tedious and time-consuming way to enter street names.
StreetSmarts is designed to make it easier to enter street names on a numeric keypad. It uses the correspondence that is printed on the keypad directly. That is, the '2' key represents the three letters 'A', 'B' and 'C', the '3' key represents the three letters 'D', 'E' and 'F', etc... This greatly reduces the number of required key presses. The only drawback of this approach is that the data entered by the user is ambiguous.
Hence, the system will first ask the user to enter the first n letters in the name of the street. It will then present (on the LCD display) a list of all of the streets that start with those n letters.
Your implementation must, instead, be based on hashing. Your hash function must be based on the telephone keypad correspondence illustrated below:
StreetSmartsTable
object.
streetnames.txt
and put them in the StreetSmartsTable
.
$ StreetSmartsDriver 5 Enter the first 5 characters: 64559 Milkweed Milky Milky Way Millway Millwheel Millwood Millwood Pond Millwood Pond Drice Millwoods Millwright Enter the first 5 characters: 223 Abe Ace Bad Enter the first 5 characters: ^D
(Note: Each street name should be entered on a single line. The loop should terminate when the user enters an "End of File" character.)
StreetSmartsTable
class is, essentially, a hashmap that
uses chaining to resolve collisions.
/** * Explicit Value Constructor * * @param digits The number of digits to use in the key */ StreetSmartsTable(int digits) /** * Destructor */ ~StreetSmartsTable(void) /** * Returns the first Node in the chain that has the * given key * * @param key The key (i.e., the digits entered at the keypad) */ Node *get(int key) /** * Put a street name in the table * * @param name The name of the street */ void put(char *name)
It may have other public and private methods as well.
The characters 'A', 'B' and 'C' must be converted to a 2, 'D', 'E', and 'F' must be converted to a 3, etc... (Note: You must ignore the case of the letter. So, 'a', 'b' and 'c' must also be converted to a 2.)
Spaces must be converted to a 1 and all other characters must be converted to a 0.
Each digit in the string must represent a digit in a base-10 number. That is, the value of the right-most character must be multiplied by 100, the value of the second right-most character (if there is one) must be multiplied by 101, etc...
For example:
String | Hash |
Bad | 223 |
One | 663 |
At | 28 |
I | 4 |
Note: Be careful if you use the pow()
function as it
returns a floating point number and if you cast the result
to an int
you may not always get what you want.
Node
class
of some kind for your "chain". You may implement this
class as you see fit.
Copyright 2010