0% found this document useful (0 votes)
23 views2 pages

Ds Practical 7

The document presents a C++ implementation of a telephone book using a hash table for efficient client lookup. It includes methods for inserting client information, searching for a client's phone number, and displaying all entries. The main function demonstrates the usage of these methods with sample client data.

Uploaded by

karan.ppjgk22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Ds Practical 7

The document presents a C++ implementation of a telephone book using a hash table for efficient client lookup. It includes methods for inserting client information, searching for a client's phone number, and displaying all entries. The main function demonstrates the usage of these methods with sample client data.

Uploaded by

karan.ppjgk22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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:-

You might also like