0% found this document useful (0 votes)
2 views

Input.cpp

The document contains a C++ program for a telephone book database that allows users to create, display, search, update, and delete records. It utilizes a hashing technique to manage records efficiently. The program includes a user interface for interaction and demonstrates various operations with sample input and output.

Uploaded by

nikamshivani112
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Input.cpp

The document contains a C++ program for a telephone book database that allows users to create, display, search, update, and delete records. It utilizes a hashing technique to manage records efficiently. The program includes a user interface for interaction and demonstrates various operations with sample input and output.

Uploaded by

nikamshivani112
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Class: SE​ Div:B

Name: Shivani Nikam


Roll No.:64​ ​ ​ ​ ​

INPUT:DSA PRAC1

#include <iostream>
using namespace std;
class node{
private:
string name;
string telephone;
int key;
public:
node(){
key = 0;
}
friend class hashing;
};

int ascii_generator(string s){


int sum = 0;
for(int i = 0; s[i] != '\0';i++){
sum = sum + s[i];
}
return sum % 10;
}

class hashing{
private:
node data[10];
string n;
string tele;
int k, index;
int size = 10;
public:
hashing(){
k = 0;
}

void create_record(string n, string tele){


k = ascii_generator(n);
index = k % size;
for(int j = 0; j < size; j++){
if(data[index].key == 0){
data[index].key = k;
data[index].name = n;
data[index].telephone = tele;
break;
}
else{
index = (index+1) % size;
}
}
}

void search_record(string name){


int index1 , k , flag = 0;
k = ascii_generator(name);
index1 = k % size;

for(int a = 0; a< size; a++){


if(data[index1].key == k){
flag = 1;
cout<<"\nRecord Found\n";
cout<<"Name :: "<<data[index1].name<<endl;
cout<<"Telephone :: "<<data[index1].telephone<<endl;
break;
}
else{
index1 = (index1 + 1) % size;
}
}
if(flag == 0){
cout<<" Record not found";
}
}

void delete_record(string name){


int index1, key, flag = 0;
key = ascii_generator(name);
index1 = key % size;

for(int a=0; a<size; a++){


if(data[index].key == key){
flag = 1;
data[index1].key = 0;
data[index1].name = " ";
data[index1].telephone = " ";
cout<<"\nRecord Deleted successfully"<<endl;
break;
}
else{
index1 = (index1 + 1) % size;
}
}
if(flag==0){
cout<<"\nRecord not found";
}
}

void update_record(string name){


int index1, key, flag=0;
key = ascii_generator(name);
index1 = key % size;

for(int a=0; a<size ;a++){


if(data[index1].key == key){
flag = 1;
break;
}
else{
index1 = (index1 + 1) % size;
}
}

if(flag == 1){
cout<<"Enter the new telephone number ::";
cin>>tele;
data[index1].telephone = tele;
cout<<"\nRecord Updated successfully";
}
}

void display_record(){
cout<<"\t Name \t\t Telephone";
for(int a = 0; a < size; a++){
if(data[a].key != 0){
cout<<"\n\t"<<data[a].name<<" \t\t\t "<<data[a].telephone;
}
}
}
};

int main(){
hashing s;
string name;
string telephone;
int choice, x;
bool loop = 1;

while(loop){
cout<<"\n------------------------------------------"<<endl;
cout<<" Telephone book Database "<<endl;
cout<<"\n------------------------------------------"<<endl;
cout<<" 1. Create Record"<<endl;
cout<<" 2. Display Record"<<endl;
cout<<" 3. Search Record"<<endl;
cout<<" 4. Update Record"<<endl;
cout<<" 5. Delete Record"<<endl;
cout<<" 6. Exit"<<endl;
cout<<" Enter Choice ::"<<endl;
cin>> choice;
switch(choice){
case 1:
cout<<"\nEnter name :: ";
cin>>name;
cout<<"Enter Telephone number :: ";
cin>>telephone;
s.create_record(name,telephone);
break;
case 2:
s.display_record();
break;

case 3:
cout<<"\nEnter the name :: ";
cin>>name;
s.search_record(name);
break;
case 4:
cout<<"\nEnter the name :: ";
cin>>name;
s.update_record(name);
break;
case 5:
cout<<"\nEnter the name to Delete :: ";
cin>>name;
s.delete_record(name);
break;
case 6:
loop = 0;
break;
default:
cout<<"You Entered something wrong!!!";
break;
}
}
return 0;
}
Class: SE​ Div:B
Name: Shivani Nikam
Roll No.:64​ ​ ​ ​ ​ ​
OUTPUT:DSA PRAC1
------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
1

Enter name :: Shivani


Enter Telephone number :: 3748590359

------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
1

Enter name :: Kaveri


Enter Telephone number :: 7986345290

------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
1

Enter name :: Ram


Enter Telephone number :: 9065492940

------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
1

Enter name :: Harshad


Enter Telephone number :: 8090594739

------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
1

Enter name :: Rajesh


Enter Telephone number :: 9090546389

------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
2
​ Name ​ ​ Telephone
​ Shivani ​ ​ ​ 3748590359
​ Rajesh ​ ​ ​ 9090546389
​ Ram ​ ​ ​ 9065492940
​ Harshad ​ ​ ​ 8090594739
------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
3

Enter the name :: Kaveri

Record Found
Name :: Kaveri
Telephone :: 7986345290

------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
3

Enter the name :: Rajesh

Record Found
Name :: Rajesh
Telephone :: 9090546389

------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
4

Enter the name :: Ram


Enter the new telephone number ::4809376240

Record Updated successfully


------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::
5

Enter the name to Delete :: ::

Record not found


------------------------------------------
Telephone book Database

------------------------------------------
1. Create Record
2. Display Record
3. Search Record
4. Update Record
5. Delete Record
6. Exit
Enter Choice ::

=== Code Execution Successful ===

You might also like