Practical No.
Q. Consider telephone book database of N clients. Make use of a hash table
implementation to quickly look up client‘s telephone number.
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;
class TelephoneBook {
private:
unordered_map<string, string> phoneBook;
public:
void insertClient(const string& name, const string& phoneNumber) {
phoneBook[name] = phoneNumber;
cout << "Inserted: " << name << " → " << phoneNumber << endl;
void searchClient(const string& name) {
if (phoneBook.find(name) != phoneBook.end()) {
cout << "Found: " << name << " → " << phoneBook[name] << endl;
} else {
cout << "Client '" << name << "' not found.\n";
void displayAll() {
cout << "\n--- Telephone Book ---\n";
for (const auto& entry : phoneBook) {
cout << entry.first << " → " << entry.second << endl;
};
int main() {
TelephoneBook book;
book.insertClient("Alice", "123-456-7890");
book.insertClient("Bob", "987-654-3210");
book.insertClient("Charlie", "555-555-5555");
book.searchClient("Bob");
book.searchClient("David");
book.displayAll();
return 0;
Output:-