Description
Remember the slogan Squidward, people order our patties. For today’s training program squidward, Mr. Krabs decided to buy the state of the art ordering system, so now you can work the grill. This automated system still preserves the essence of squidward, because we all know how customer friendly squidward can be. The automated ordering system needs to be able to look up menu items quickly, using a hash table.
template <class t1 , class t2 > class hash Map
{
public: hash Map ();
t2 & operator []( t1 ); private :
void resize ( int);
int hash Function ( std :: string );
struct keyVal
{
t1 key; t2 value ;
};
static const int MAX_COLLISIONS = 5; int filled Entries ;
std :: vector < std :: list <keyVal > > table ;
};
Each member contains/performs the following
• struct keyVal - maintains an entry in the hash table
• std::vector< std::list<keyVal> > table - hash table, an array of linked lists (each linked list is sorted by keys), each linked list contains no more than MAX_COLLISIONS amount of elements
• int filledEntries - keeps track of the amount of linked lists in table are full (have MAX_COLLISIONS
amount of nodes)
• static const int MAX_COLLISIONS - the max amount of nodes that can be stored in each linked list in the table vector
• hashMap<t1, t2>::hashMap() - constructor that sets filledEntries = 0 and sets the table size
table.resize(5)
• t2& hashMap<t1, t2>::operator[](t1 key) - implements the insert/find bracket operator (finds/in- serts a node with the parameter key), the steps you follow are:
1. If the load factor is 20% or more (load factor is filledEntires / table.size()), then
resize(table.size())
2. int i = hashFunction(key) % table.size()
3. auto it = table[i].begin() sets an iterator to point to the first node of the appropriate linked list
4. If a node with a matching key is found, then return this node’s value field
5. If a node with a matching key is not found and the linked list is not maxed out (the amount of nodes is less than MAX_COLLISIONS), insert a new entry into the correct spot of the linked list to preserve the sorted order (do not actually sort the entire list, just insert the element into the correct sorted spot),; set this node’s value field with t2(), if this insert causes this linked list to be maxed out, increment the filledEntries by 1; then return this new node’s value field
6. If the key does not exist and the linked list is maxed out, increment i = (i + 1) % table.size()
and then go to step 2
• int hashMap<t1, t2>::hashFunction(std::string key) - returns an integer using the hash object, the function contains
std :: hash <std :: string > result; return result( key );
• void hashMap<t1, t2>::resize(int amount) - resizes the table by the parameter amount, this re- quires a re-map, only re-map the elements whose value fields do not contain t2() (this could happen when in main, a few failed searches occur but an actual new entry was created)
Main
In main you need to declare the following struct
struct menu Type
{
menu Type () : price (0), quantity (0.0)
{}
menu Type ( double p, int q) : price ( p), quantity ( q)
{}
// operator used in the hash Map :: resize ( int) function
// that is used to determine if a node ’s value is not
// an empty entry
bool operator !=( const menu Type & m)
{
return quantity != m. quantity && price != m. price ;
}
int quantity ; double price ;
};
And using this struct, you define the following hashMap
hashMap <std :: string , menuType > krustyKrab Menu ;
Your program in main would follow the following steps
1. Prompt the user for an input file and open an std::ifstream infile variable
2. Create a std::vector<std::string> itemNames to store the item names in the same order they were read in (this is so we all get the same output for code grade)
3. Read each line (each line contains an item name, its price, and its quantity) and insert the item name into the itemNames vector and insert the element into the krustyKrabMenu hash table (you map the item name to menuType object that contains the item’s price and quantity amount)
4. Output the menu (only output the elements that are in stock i.e. the quantity of the item is above 0)
5. Prompt the user with the comforting message "Are you going to order today, sir? "
6. If the item name read in is not found or it’s quantity is 0, then output the message "We serve food here, sir"
and go back to step 5, otherwise go to the next step
7. Output "Great, excellent choice" and then output "How many? " and then read in a quantity amount
8. If the quantity of the item is less than the quantity read, output "Try again: " and re-read the quantity, if the quantity is valid, go to the next step
9. Output "Well done, took you long enough"
10. Subtract the quantity entered from the quantity from the item and update a running cost
11. If no items are left, output "Looks like you ordered everything on the menu, you know what that means"
then go to step 13
12. Prompt the user using the message "Will this complete your order? ", if an upper or lower case N is entered go to step 4, else go to the next step
13. Output "Your order comes out to $" and then the order amount, then finalize the program with another passive aggressive Squidward message "Have a great day...barnacle head"
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of