-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18010011067_Odev1.cpp
More file actions
439 lines (407 loc) · 10.1 KB
/
18010011067_Odev1.cpp
File metadata and controls
439 lines (407 loc) · 10.1 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
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
/*
* BISMILLAHIRRAHMANIRRAHIM
* @Project : Veri Yapilari-Odev1 - BAYRAM YARIM - 18010011067
* @Author : Bayram YARIM [byyarim@gmail.com]
* @File : 18010011067.cpp
* @Desc : DataStruct
* @Create : 02.10.2022 20:55
* @Update : 02.10.2022 23:18
* @Version : v-
* @Build : #-
* @OS : Debian-Linux
* @IDE : Qt Creator - qMake Compiler
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
//OS System Select
#ifdef __linux__
#define clrscr system("clear");
#elif _WIN32
#define clrscr system("@cls");
#else
#define clrscr system("@cls");
#endif
//Circle Linked List
typedef struct tsCLL
{
char Name[20];
char Surname[20];
long int Phone;
struct tsCLL *NextCLL;
} TCLL;
TCLL *root=NULL, *iTemp;
void MainMenu();
void CLLList();
void CLLAdd();
void CLLSearchPhone();
void CLLSearchName();
void CLLDelete();
void CLLSort();
void ProgramAbout();
void ProgramExit();
int GetKeyboardValue()
{
#ifdef __linux__
int result = getchar();
#elif _WIN32
int result = getch();
#else
int result = getch();
#endif
return result;
}
void ShowMessage(int MenuNo, char *eMessage)
{
printf("\n\n\n");
printf("%20s%s\n\n"," " ,eMessage);
printf("\t\tAna menuye donmek icin ENTER tusuna basiniz...");
int iSelect = GetKeyboardValue();
#ifdef __linux__
GetKeyboardValue();
#endif
//printf("%d",iSelect);
switch(iSelect)
{
case 27: //ESC
case 13: //Enter
MainMenu();
break;
case 32:
switch (MenuNo)
{
case 1: CLLAdd(); break;
case 2: CLLList(); break;
case 3: CLLSearchPhone(); break;
case 4: CLLSearchName(); break;
case 5: CLLDelete(); break;
case 6: CLLSort(); break;
default: MainMenu(); break;
}
break;
default:
MainMenu();
ShowMessage(0, eMessage);
break;
}
}
TCLL *GetDataRecord()
{
TCLL *iRecord = (TCLL*)malloc(sizeof (TCLL));
printf("%40s","Ad Giriniz:");
scanf("%s", &(iRecord->Name));
printf("%40s","Soyad Giriniz:");
scanf("%s", &(iRecord->Surname));
printf("%40s","Telefon Giriniz:");
scanf("%d", &(iRecord->Phone));
return iRecord;
}
/*
* Telefon Numarasi kontrolu
* Kayit var ise return True
* Kayit yok ise return False
*/
bool CLLPhoneControl(int phoneNo)
{
bool result=false;
iTemp = root;
if (iTemp != NULL)
{
do {
if (iTemp->Phone == phoneNo)
{
result=true;
break;
}
iTemp = iTemp->NextCLL;
} while (iTemp != root);
}
return result;
}
/*
* KAYIT EKLEME FONKSIYONU
* Kayit en basa eklenir.
*/
void CLLAdd()
{
TCLL *rec = GetDataRecord();
if (root == NULL )
{
root = rec;
root->NextCLL = rec;
}
else
{
if (CLLPhoneControl(rec->Phone) == true)
{
ShowMessage(0, "Girilen bu telefon baska kayitta mevcut. Kayit Eklenemez!");
return;
}
iTemp = root;
while (iTemp->NextCLL != root) {
iTemp = iTemp->NextCLL;
}
iTemp->NextCLL = rec;
rec->NextCLL = root;
}
ShowMessage(1, "KAYIT EKLEME TAMAMLANDI\n");
}
/*
* Tum kayitlari listeleme fonksiyonu
* Tum kayitlari listeler ve kayit sayisini gosterir
* Kayit yok ise mesaj verir!
*
*/
void CLLList()
{
clrscr;
int recCount=0;
iTemp = root;
if (iTemp != NULL)
{
printf("Ad\t\tSoyad\t\tTelefon\n");
printf("==========================================================\n");
do {
printf("%s\t\t%s\t\t%ld\n", iTemp->Name, iTemp->Surname, iTemp->Phone);
iTemp = iTemp->NextCLL;
recCount++;
} while (iTemp != root);
printf("==========================================================\n");
printf("\tToplam %d kayit listelendi", recCount);
}
else
{
ShowMessage(2, "Rehberde listelenecek kayit bulunamadi!");
}
ShowMessage(2, " ");
}
/*
* Telefon numarasina gore tum kayitlari tarar
* Kayit var ise bilgilerini gosterir
* Kayit yok ise uyari mesaji verir!
*
*/
void CLLSearchPhone()
{
long int phoneNo;
bool result=false;
iTemp = root;
if (iTemp != NULL)
{
printf("%40s","Aranacak Telefon No Giriniz:");
scanf("%ld", &phoneNo);
do {
if (iTemp->Phone == (int)(phoneNo))
{
printf("%ld numarasi %s %s kisisine kayitlidir.\n", phoneNo, iTemp->Name, iTemp->Surname);
result = true;
break;
}
iTemp = iTemp->NextCLL;
} while (iTemp != root);
}
else
{
ShowMessage(3, "Aranacak bir veri bulunamamaktadir!");
}
if (result == false) printf("%ld numarasi herhangi bir kayitta bulunamadi!", phoneNo);
ShowMessage(0, " ");
}
/*
* Ad bilgisine gore tum kayitlari tarar
* Kayit var ise bilgilerini gosterir
* Kayit yok ise uyari mesaji verir!
*
*/
void CLLSearchName()
{
char uName[20];
bool result=false;
iTemp = root;
if (iTemp != NULL)
{
printf("%40s","Aranacak kisi ismini giriniz:");
scanf("%s", &uName);
printf("Ad\t\tSoyad\t\tTelefon\n");
printf("==========================================================\n");
do {
if (strcmp(iTemp->Name, uName) == 0)
{
printf("%s\t\t%s\t\t%ld\n", iTemp->Name, iTemp->Surname, iTemp->Phone);
result = true;
}
iTemp = iTemp->NextCLL;
} while (iTemp != root);
printf("==========================================================\n");
}
else
{
ShowMessage(4, "Aranacak bir veri bulunamamaktadir!");
}
if (result == false) printf("\t%s isimli herhangi bir kayit bulunamadi!", uName);
ShowMessage(0, " ");
}
/*
* Telefon numarasina gore tum kayitlari tarar
* Kayit var ise kayit silinir
* Kayit yok ise uyari mesaji verir!
*
*/
void CLLDelete()
{
long int phoneNo;
bool result=false;
iTemp = root;
TCLL *firstRec = NULL;
if (iTemp != NULL)
{
printf("%40s","Silinecek kayitin Telefon No Giriniz:");
scanf("%ld", &phoneNo);
do {
if (iTemp->Phone == (int)(phoneNo))
{
result = true;
break;
}
firstRec = iTemp;
iTemp = iTemp->NextCLL;
} while (iTemp != root);
if (result == true)
{
if (firstRec == NULL)
{
root = NULL;
}
else
{
firstRec->NextCLL = iTemp->NextCLL;
free(iTemp);
ShowMessage(5, " Kayit silindi!");
}
}
else
{
ShowMessage(0, "Aranilan kayit bulunamadi!");
}
}
else
{
ShowMessage(0, "Silinecek bir veri bulunmamaktadir!");
}
}
/*
* iki kaydi degistirir.
*
*/
void CLLSwap(TCLL *L1, TCLL *L2)
{
TCLL *swTemp = NULL;
memcpy(&swTemp, &L1, sizeof(L1));
memcpy(&L1, &L2, sizeof(L2));
memcpy(&L2, &swTemp, sizeof(swTemp));
}
/*
* Tum kayitlari tarar ve soyadina gore siralama yapar
*
*/
void CLLSort()
{
TCLL *aTemp = root, *sortL1 = NULL;
if (aTemp != NULL)
{
do{
sortL1 = aTemp->NextCLL;
while(sortL1 != root) {
if (strcmp((char*)aTemp->Surname, (char*)sortL1->Surname) >= 0)
{
CLLSwap(aTemp, sortL1);
}
sortL1= sortL1->NextCLL;
}
aTemp =aTemp->NextCLL;
}while(aTemp->NextCLL != root);
printf("========SIRALI LISTE========\n");
printf("Ad\t\tSoyad\t\tTelefon\n");
printf("==========================================================\n");
do {
printf("%s\t\t%s\t\t%ld\n", aTemp->Name, aTemp->Surname, aTemp->Phone);
aTemp = aTemp->NextCLL;
} while (aTemp->NextCLL != root);
}
else
{
ShowMessage(6, "Listelenecek kayit bulunmamaktadir!");
}
ShowMessage(2, " ");
}
void ProgramAbout()
{
clrscr;
printf("================================================================================\n");
printf("\t\t\tProgram : VERI YAPILARI - ODEV1\n");
printf("\t\t\tAuthor : Bayram YARIM\n");
printf("\t\t\tSchoolNo: 18010011067\n");
printf("\t\t\tMail : byyarim@gmail.com\n");
printf("================================================================================\n");
ShowMessage(0," ");
}
void ProgramExit()
{
printf("\n\t\t[ Programdan cikis yapiliyor...Bye!]\n\n");
exit(0);
}
void MainMenu()
{
int MenuSelect;
clrscr;
printf("*******************************************************************************\n");
printf("\t\t\tTELEFON REHBERI\n");
printf("*******************************************************************************\n");
printf("\t\t\t [1] : KAYIT EKLE\n");
printf("\t\t\t [2] : KAYIT LISTELE\n");
printf("\t\t\t [3] : KAYIT ARA ( TELEFON )\n");
printf("\t\t\t [4] : KAYIT ARA ( AD ) \n");
printf("\t\t\t [5] : KAYIT SIL ( TELEFON )\n");
printf("\t\t\t [6] : KAYIT SIRALA ( SOYAD ) \n");
printf("\t\t\t[h/H]: PROGRAM HAKKINDA\n");
printf("\t\t\t[e/E]: CIKIS\n");
printf("*******************************************************************************\n");
printf("\t\t\tMENUDEN ISLEM SECINIZ:\n");
MenuSelect = GetKeyboardValue();
switch(MenuSelect)
{
case 49: //1
CLLAdd();
break;
case 50: //2
CLLList();
break;
case 51: //3
CLLSearchPhone();
break;
case 52: //4
CLLSearchName();
break;
case 53: //5
CLLDelete();
break;
case 54: //6
CLLSort();
break;
case 'H': case 'h': case 'A': case 'a':
ProgramAbout();
break;
case 'E': case 'e': case 'Q': case 'q':
ProgramExit();
break;
default:
MainMenu();
break;
}
}
int main()
{
MainMenu();
return 0;
}