0% found this document useful (0 votes)
10 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)
10 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy