-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1st.cpp
More file actions
126 lines (111 loc) · 3.13 KB
/
Copy path1st.cpp
File metadata and controls
126 lines (111 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include<bits/stdc++.h>
using namespace std;
// telephone implementation using hash table
class data {
public:
int client_id;
string telephone;
data() {
client_id = -1;
telephone = "";
}
data(int client_id, string telephone){
this->client_id = client_id;
this->telephone = telephone;
}
};
class Map {
public:
int TableSize;
data* hashTable;
Map(int size){
TableSize = size;
hashTable = new data[TableSize];
}
bool insert(int client_id, string telephone){
int ind = client_id % TableSize;
for(int i=0; i<TableSize; i++){
if(hashTable[ind].telephone == ""){
hashTable[ind] = data(client_id, telephone);
return true;
}
}
return false;
}
data search(int client_id){
int ind = client_id % TableSize;
for(int i=0; i<TableSize; i++){
if(hashTable[ind].client_id == client_id){
return hashTable[ind];
}
}
return data();
}
bool deleteData(int client_id){
int ind = client_id % TableSize;
for(int i=0; i<TableSize; i++){
if(hashTable[ind].client_id == client_id){
hashTable[ind] = data();
return true;
}
}
return false;
}
};
int main(){
Map database(10);
int choice = -1, c = -1;
string t;
data d;
while(choice != 4){
cout << "************* MENU *************\n";
cout << "1. Insert Client Details\n";
cout << "2. Search Client Details\n";
cout << "3. Delete Client Details\n";
cout << "4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch(choice){
case 1:
cout << "Enter Client id to insert: ";
cin >> c;
cout << "Enter telephone no. of Client: ";
cin >> t;
if(database.insert(c, t))
cout << "Data inserted Successfully.";
else
cout << "Database full.";
break;
case 2:
cout << "Enter Client id to search: ";
cin >> c;
d = database.search(c);
if(d.client_id == -1){
cout << "Data not Found.";
}
else {
cout << "Client has telephone no.: " << d.telephone;
}
break;
case 3:
cout << "Enter Client id to delete: ";
cin >> c;
d = database.search(c);
if(d.client_id == -1){
cout << "Data not Found.";
}
else {
database.deleteData(c);
cout << "Data with client id " << c << " Successfully deleted.";
}
break;
case 4:
return 0;
default:
cout << "Invalid Choice.";
break;
}
cout << "\n\n";
}
return 0;
}