Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NEED TO IMPLEMENT HASH.CPP FILE #ifndef HASH_H #define HASH_H #include using nam

ID: 3832036 • Letter: N

Question

NEED TO IMPLEMENT  HASH.CPP FILE

#ifndef HASH_H
#define HASH_H

#include

using namespace std;

class Entry {
       string name;
       string phone;
       float salary;
public:
       Entry(string name, string phone, float salary) {
           this->name = name;
           this->phone = phone;
           this->salary = salary;
       }
       string getKey() { return name; }
       string getPhone() { return phone; }
       float getSalary() { return salary; }
       void setKey(string str) { name = str; }
};

class HashMap {
public:
   class Overflow{};
   HashMap(int size);
   ~HashMap();
   unsigned long hash(string str);
   void put(Entry *e);
   Entry* get(string key);
   Entry* remove(string key);
protected:
   Entry **table;
   int size;
};

#endif

//hashmain.cpp

#include
#include "hash.h"

using namespace std;

int main() {
   HashMap table(128);
   Entry *e1 = new Entry("Sam", "760-750-4567", 100000);
   Entry *e2 = new Entry("Mary", "760-750-1234", 120000);
   Entry *e3 = new Entry("Jim", "760-750-0000", 70000);
   table.put(e1);
   table.put(e2);
   table.put(e3);

   string key;
   cout << "Type in the search key (use 'q' for quit): ";
   cin >> key;
   while(key != "q") {
       Entry *e = table.get(key);
       if(e != NULL)
           cout << e->getKey() << "'s phone number is " << e->getPhone() << ", and salary is " << e->getSalary() << endl;
       else
           cout << "The key '" << key << "'' is not in the table." << endl;
       cout << "Type in the search key (use 'q' for quit): ";
       cin >> key;
   }
   return 0;
}

Explanation / Answer

#include <iostream>

#include "hash.cpp"
using namespace std;
void main() {
HashMap table(128);
Entry *e1 = new Entry("Sam", "760-750-4567", 100000);
Entry *e2 = new Entry("Mary", "760-750-1234", 120000);
Entry *e3 = new Entry("Jim", "760-750-0000", 70000);
table.put(e1);
table.put(e2);
table.put(e3);
string key;
cout << "Type in the search key (use 'q' for quit): ";
cin >> key;
while(key != "q") {
Entry *e = table.get(key);
if(e != NULL)
cout << e->getKey() << "'s phone number is " << e->getPhone() << ", and salary is " << e->getSalary() << endl;
else
cout << "The key '" << key << "'' is not in the table." << endl;
cout << "Type in the search key (use 'q' for quit): ";
cin >> key;
}

}

//You will have to include #include <string> and strings must be declared this way  std::string string_name

#ifndef HASH_H
#define HASH_H
#include <string>
using namespace std;
class Entry {
std::string name;
std::string phone;
float salary;
public:
Entry( std::string name, std::string phone, float salary) {
this->name = name;
this->phone = phone;
this->salary = salary;
}
std::string getKey() { return name; }
std::string getPhone() { return phone; }
float getSalary() { return salary; }
void setKey( std::string str) { name = str; }
};
class HashMap {
public:
class Overflow{};
HashMap(int size);
~HashMap();
unsigned long hash( std::string str);
void put(Entry *e);
Entry* get(std::string key);
Entry* remove(std::string key);
protected:
Entry **table;
int size;
};
#endif