forked from mr-sergi/Hacktoberfest-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Phone Directory System
447 lines (322 loc) · 7.34 KB
/
Phone Directory System
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
// TELEPHONE DIRECTORY SYSTEM
#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
#include<graphics.h>
#include<dos.h>
class stud
{
public:
char name[20];
char address[20];
unsigned int ph_no;
void get(void);
void show(void);
void modify(void);
};
void stud::get(void)
{
int i=0;
cout<<"\n Enter name -> ";
cin.get(name[i]);
while(name[i]!='\n')
{
i=i+1;
cin.get(name[i]);
}
cin.getline(name,20,'\n');
cout<<" Enter address -> ";
cin.getline(address,20,'\n');
fflush(stdin);
cout<<" Enter ph_no\t-> \t";
cin>>ph_no;
fflush(stdin);
}
void stud::show(void)
{
cout<<"\n";
cout<<" NAME :"<<"\t"<<name<<"\n";
cout<<" ADDRESS :"<<"\t"<<address<<"\n";
cout<<" Ph_No :"<<"\t"<<ph_no<<"\n";
}
void main()
{
int gdriver = DETECT, gmode, errorcode;
int x,y;
int midx,midy;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
closegraph();
}
y:
char*pass="RPV";
char*ppass;
gotoxy(25,8);
int size=7;
settextstyle(7,0,size);
setbkcolor(BLUE);
setcolor(WHITE);
outtextxy(180,50,"WELCOME" );
setcolor(WHITE);
outtextxy(250,200,"TO");
settextstyle(8,0,5);
setfillstyle(1,DARKGRAY);
setcolor(WHITE);
outtextxy(60,350,"\n\nTELEPHONE DIRECTORY");
getch();
clearviewport();
settextstyle(3,0,4);
settextstyle(7,0,4);
getch();
clearviewport();
g:
ppass=getpass("ENTER THE PASSWORD::");
if(strcmpi(pass,ppass)!=0)
{
cout<<"\n\t\t\tIncorrect password";
cout<<"\n\t\t\tTry again";
getchar();
goto g;
}
else
{
stud s;
char name[20];
char name1[20];
int ch;
clrscr();
setbkcolor(BLUE);
setcolor(YELLOW);
closegraph();
z:
cout<<"\n\n\n\n\n\n\n\n\n";
initgraph(&gdriver, &gmode,"c:\\turboc3\\bgi");
setcolor(BLUE);
rectangle(60,10,600,400);
setfillstyle(1,YELLOW);
bar(61,11,599,399);
outtextxy(200,30," HELP -> PRESS ANY KEY 1 TO 6 " );
settextstyle(TRIPLEX_FONT ,HORIZ_DIR,4);
outtextxy(220,50,"\n\n1. TO ADD " );
setcolor(BLUE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(220,100,"\n\n2. TO SHOW " );
setcolor(BLUE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(220,150,"\n\n3. TO SEARCH " );
setcolor(BLUE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(220,200,"4.\n\n TO MODIFY " );
setcolor(BLUE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(220,250,"\n\n\n5. TO DELETE " );
setcolor(BLUE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(220,300,"\n\n\n6. TO EXIT " );
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(220,350," Enter the choice ->");
gotoxy(62,23);
cin>>ch;
switch(ch)
{
case 1: //responsible for addition of record
{
clrscr();
fstream f;
f.open("rec",ios::in|ios::out|ios::ate|ios::app|ios::binary);
char ans;
s.get();
f.write((char *)&s,sizeof(s));
clrscr();
outtextxy(250,360, " Do you want to continue:- ");
ans=getche();
if(ans=='Y' || ans=='y'){goto z;}
f.close();
break;
}
case 2: // will show all the contents of the file
{
clrscr();
cout<<"\n\n";
fstream f;
f.open("rec",ios::in|ios::out|ios::ate|ios::app|ios::binary);
f.seekg(0);
int ctr=0;
while(f.read((char *)&s,sizeof(s)) )
{
ctr=ctr+1;
if(ctr==8) {getchar(); clrscr();ctr=0;}
s.show();
if(f.eof()==1)
{break;}
}
f.close();
outtextxy(240,350, " Do you want to continue :-");
char ans;
ans=getche();
if(ans=='y'|| ans=='Y'){
closegraph();
goto z;}else{exit(1);}
}
case 3: // search
{
gotoxy(60,25);
clearviewport();
rectangle(10,10,630,470);
setbkcolor(DARKGRAY);
textbackground(3);
textcolor(5);
clrscr();
char ans;
ifstream f;
stud s;
char name[20];
char address[20];
unsigned int ph_no;
f.open("rec",ios::in|ios::binary);
cout<<"\n\n\n Enter name whose record to be search :";
cin>>name;
do
{
f.read((char *)&s,sizeof(s));
if(f.eof()==1) {break;}
if(strcmpi(s.name,name)==0)
{
cout<<"\n Name :"<<s.name;
cout<<"\n address :"<<s.address;
cout<<"\n phone_no :"<<s.ph_no;
getchar();
}
}while(f);
f.close();
settextstyle(7,0,1);
outtextxy(250,410,"Do You Want To Continue:");
ans=getchar();
if(ans=='Y'||ans=='y')
goto z;
else
{
closegraph();
break;
}
case 4: //for the modification
{
clrscr();
char ans;
fstream f; stud s;
char name[20]; char address[20]; unsigned int ph_no;
f.open("rec",ios::in|ios::binary);
cout<<"\n\n\n Enter person ph_no whose record to be changed :";
cin>>ph_no;
do
{
f.read((char *)&s,sizeof(s));
if(f.eof()==1) {break;}
if(s.ph_no==ph_no)
{
cout<<"\n Current Name :"<<s.name;
cout<<"\n Current Address :"<<s.address;
cout<<"\n Current Phone No :"<<s.ph_no;
getchar();
cout<<"\n Enter the new name :";
cin>>name;
cout<<"\n Enter the city :";
cin>>address;
cout<<"\n Enter new ph_no :";
cin>>ph_no;
strcpy(s.name,name);
strcpy(s.address,address);
s.ph_no=ph_no;
int l=f.tellg();
f.close();
f.open("rec",ios::out|ios::binary|ios::ate);
f.seekg(l-sizeof(s));
f.write((char *)&s,sizeof(s));
}
}while(f);
f.close();
outtextxy(290,360, " Do you want to continue :-");
ans=getche();
if(ans=='Y'||ans=='y')
{goto z;}
break;
}
case 5: //responsible for the deletion of the record
{
clrscr();
char name[20];
stud s;
ifstream fin;
fstream fout;
fin.open("rec",ios::in|ios::binary);
fout.open("va",ios::app|ios::binary);
cout<<"\n \t\t\t DELETING :-";
int i;
fflush(stdin);
cout<<"\n\n Enter the name :- ";
cin.get(name[i]);
while(name[i]!='\n')
{
i=i+1;
cin.get(name[i]);
}
fflush(stdin);
fflush(stdout);
cin.getline(name,20,'\n');
while(fin)
{
fin.read((char *)&s,sizeof (s));
if(strcmp(s.name,name)==0)
{fout.read((char *)&s,sizeof(s));
}
else
{
if(fin.eof()==1) {break;}
fout.write((char *)&s,sizeof(s));
}
}
fin.close();
fout.close();
system("del rec");
system("ren va rec");
cout<<"\n Enter is get Deleted:-";
getchar();
char ans;
outtextxy(240,340, " Do you want to continue:- ");
ans=getche();
if (ans=='y' || ans=='Y')
{goto z;}
else
if (ans=='n' || ans=='N')
{getchar();
exit(1);
}
}
case 6:
{
clearviewport();
outtextxy(250,360,"THE END OF THE PROJECT:-");
outtextxy(260,390,"\n \n\n\n\n PLEASE PRESS ENTER");
getchar();
closegraph();
exit(1);
}
default:
goto z;
}
}
}
}