本文实例为大家分享了C语言通讯录管理系统课程设计,供大家参考,具体内容如下
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
struct Sign{
char name[8];
char sex[4];
char birthday[12];
char phone[11];
char postcode[7];
char addr[30];
struct Sign *next;
}pe;
char PhoneCop[4] ;
//结构体
struct Sign *p1,*p2,*head;
FILE *fp;
void ShowMenu(){
system ( "color 1F" );
printf ( "################# 通讯录管理系统 v1.0 ###################\n" );
printf ( "#####################################################################\n" );
printf ( "# #\n" );
printf ( "# 1-----------------信息录入------------------- #\n" );
printf ( "# #\n" );
printf ( "# 2-----------------信息查询------------------- #\n" );
printf ( "# #\n" );
printf ( "# 3-----------------信息查看------------------- #\n" );
printf ( "# #\n" );
printf ( "# 4-----------------信息修改------------------- #\n" );
printf ( "# #\n" );
printf ( "# 5-----------------信息统计------------------- #\n" );
printf ( "# #\n" );
printf ( "# 6-----------------退出系统------------------- #\n" );
printf ( "# #\n" );
printf ( "#####################################################################\n" );
printf ( "# POWER BY ************* 兰州理工大学 201407 #\n" );
printf ( "#####################################################################\n" );
};
void HeadShow()
{
printf ( "################# 通讯录管理系统 v1.0 ###################\n" );
printf ( "---------------------------------------------------------------------\n" );
}
void FileLoading()
{
if ((fp= fopen ( "txl.dat" , "rb" ))==NULL)
{
printf ( "文件操作错误,请检查是否有权限操作文件!" );
Sleep(3000);
exit (1);
}
p1=( struct Sign*) malloc ( sizeof ( struct Sign));
p1->next=NULL;
head=p1;
while (! feof (fp))
{
if ( fread (p1, sizeof ( struct Sign),1,fp)!=1)
break ;
p2=( struct Sign*) malloc ( sizeof ( struct Sign));
p2->next=NULL;
p1->next=p2;
p1=p2;
}
fclose (fp);
}
void add()
{
char ch;
if ((fp== fopen ( "txl.dat" , "ab+" ))!=1)
{
printf ( "文件打开失败" );
exit (1);
}
while (1)
{ system ( "cls" );
printf ( "请输入__\n" );
p2=( struct Sign*) malloc ( sizeof ( struct Sign));
p2->next=NULL;
printf ( "姓名:" ); scanf ( "%s" ,pe.name);
printf ( "性别:" ); scanf ( "%s" ,pe.sex);
printf ( "生日:" ); scanf ( "%s" ,pe.birthday);
printf ( "电话号码:" ); scanf ( "%s" ,pe.phone);
printf ( "邮编:" ); scanf ( "%s" ,pe.postcode);
printf ( "地址:" ); scanf ( "%s" ,pe.addr);
strcpy (p1->name,pe.name);
strcpy (p1->sex,pe.sex);
strcpy (p1->birthday,pe.birthday);
strcpy (p1->phone,pe.phone);
strcpy (p1->postcode,pe.postcode);
strcpy (p1->addr,pe.addr);
p1->next=p2;
p1=p2;
if ( fwrite (&pe, sizeof ( struct Sign),1,fp)!=1)
printf ( "写入错误" );
printf ( "输入E或e来结束输入?" );
getchar ();
ch= getchar ();
if (ch== 'e' ||ch== 'E' )
break ;
}
fclose (fp);
}
void SaveChange()
{
if ((fp== fopen ( "txl.dat" , "w" ))!=1)
{
printf ( "文件打开失败" );
exit (1);
}
p1=head;
while (p1->next!=NULL)
{
if ( fwrite (p1, sizeof ( struct Sign),1,fp)!=1)
printf ( "写入错误" );
p1=p1->next;
}
fclose (fp);
}
void AllShow()
{
HeadShow();
printf ( "%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n" , "姓名" , "性别" , "生日" , "电话" , "邮编" , "地址" );
printf ( "---------------------------------------------------------------------\n" );
p1=head;
while (p1->next!=NULL)
{
printf ( "%10.8s %6.6s %10.12s %11.11s %9.7s %16.16s \n" ,p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
p1=p1->next;
}
}
void AllNum()
{ int i=0;
HeadShow();
printf ( " 共有记录条数为: \n" );
printf ( "---------------------------------------------------------------------\n" );
p1=head;
while (p1->next!=NULL)
{
i++;
p1=p1->next;
}
printf ( " %d \n" ,i);
printf ( "---------------------------------------------------------------------\n" );
printf ( " 共有联通用户为: \n" );
printf ( "---------------------------------------------------------------------\n" );
p1=head;
i=0;
while (p1->next!=NULL)
{
strncpy (PhoneCop,p1->phone,3);
if ( strcmp (PhoneCop, "130" )==0|| strcmp (PhoneCop, "131" )==0|| strcmp (PhoneCop, "132" )==0|| strcmp (PhoneCop, "155" )==0|| strcmp (PhoneCop, "156" )==0|| strcmp (PhoneCop, "185" )==0|| strcmp (PhoneCop, "186" )==0)
i++;
p1=p1->next;
}
printf ( " %d \n" ,i);
printf ( "---------------------------------------------------------------------\n" );
printf ( " 共有移动用户为: \n" );
printf ( "---------------------------------------------------------------------\n" );
p1=head;
i=0;
while (p1->next!=NULL)
{
strncpy (PhoneCop,p1->phone,3);
if ( strcmp (PhoneCop, "134" )==0|| strcmp (PhoneCop, "135" )==0|| strcmp (PhoneCop, "136" )==0|| strcmp (PhoneCop, "137" )==0|| strcmp (PhoneCop, "138" )==0|| strcmp (PhoneCop, "139" )==0|| strcmp (PhoneCop, "150" )==0|| strcmp (PhoneCop, "151" )==0|| strcmp (PhoneCop, "152" )==0|| strcmp (PhoneCop, "157" )==0|| strcmp (PhoneCop, "158" )==0|| strcmp (PhoneCop, "159" )==0|| strcmp (PhoneCop, "187" )==0|| strcmp (PhoneCop, "188" )==0)
i++;
p1=p1->next;
}
printf ( " %d \n" ,i);
printf ( "---------------------------------------------------------------------\n" );
printf ( " 共有电信用户为: \n" );
printf ( "---------------------------------------------------------------------\n" );
p1=head;
i=0;
while (p1->next!=NULL)
{
strncpy (PhoneCop,p1->phone,3);
if ( strcmp (PhoneCop, "180" )==0|| strcmp (PhoneCop, "189" )==0|| strcmp (PhoneCop, "133" )==0|| strcmp (PhoneCop, "153" )==0)
i++;
p1=p1->next;
}
printf ( " %d \n" ,i);
printf ( "---------------------------------------------------------------------\n" );
}
void CheckFace()
{ int Check_key;
printf ( "########### 通讯录管理系统 v1.0 ################\n" );
printf ( "############################################################\n" );
printf ( "# #\n" );
printf ( "# 1------按姓名查询 #\n" );
printf ( "# #\n" );
printf ( "# 2------按电话号码查询 #\n" );
printf ( "# #\n" );
printf ( "# 3------综合查询 #\n" );
printf ( "# #\n" );
printf ( "# 4------退出查询模块 #\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "############################################################\n" );
printf ( "# POWER BY ************* 兰州理工大学 201407 #\n" );
printf ( "############################################################\n" );
}
void Selelctname()
{ system ( "cls" );
HeadShow();
printf ( "%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n" , "姓名" , "性别" , "生日" , "电话" , "邮编" , "地址" );
printf ( "---------------------------------------------------------------------\n" );
p1=head;
char FindName[8];
int i=0;
printf ( "请输入要查询的姓名:" );
scanf ( "%s" ,&FindName);
while (p1->next!=NULL)
{
if ( strcmp (p1->name,FindName)==0)
{ printf ( "%10.8s %6.6s %10.10s %11.14s %9.7s %16.16s \n" ,p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
i++;
}
p1=p1->next;
}
printf ( "共 %d 条\n" ,i);
system ( "pause" );
}
void Selelctphone()
{ system ( "cls" );
HeadShow();
printf ( "%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n" , "姓名" , "性别" , "生日" , "电话" , "邮编" , "地址" );
printf ( "---------------------------------------------------------------------\n" );
p1=head;
char phone[11];
int i=0;
printf ( "请输入要查询的电话号码:" );
scanf ( "%s" ,&phone);
while (p1->next!=NULL)
{
if ( strcmp (p1->phone,phone)==0)
{ printf ( "%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n" ,p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
i++;
}
p1=p1->next;
}
printf ( "共 %d 条\n" ,i);
system ( "pause" );
}
void Selelctall()
{ system ( "cls" );
HeadShow();
printf ( "%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n" , "姓名" , "性别" , "生日" , "电话" , "邮编" , "地址" );
printf ( "---------------------------------------------------------------------\n" );
p1=head;
char all[30];
int i=0;
printf ( "请输入任意一项要查询的内容:" );
scanf ( "%s" ,&all);
while (p1->next!=NULL)
{
if ( strcmp (p1->name,all)==0|| strcmp (p1->sex,all)==0|| strcmp (p1->birthday,all)==0|| strcmp (p1->phone,all)==0|| strcmp (p1->postcode,all)==0|| strcmp (p1->addr,all)==0)
{ printf ( "%10.8s %6.6s %10.10s %11.11s %9.7s %16.16s \n" ,p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
i++;
}
p1=p1->next;
}
printf ( "共 %d 条\n" ,i);
system ( "pause" );
}
void Change()
{ char ChangeName[8];
int changekey;
system ( "cls" );
HeadShow();
int i,y=0;
p1=p2=head;
printf ( "请输入你要修改的条目的姓名:" );
scanf ( "%s" ,&ChangeName);
getchar ();
while (p1!=NULL)
{
if ( strcmp (p1->name,ChangeName)==0)
{ printf ( "%10.8s %6.6s %10.10s %11.11s %9.7s %16.16s \n" ,p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
printf ( "您要修改的是这条记录吗?1---是|2---否\n" );
scanf ( "%d" ,&i);
if (i==1)
{ y=1;
printf ( "你要修改的通讯录为:\n" );
printf ( "%10.8s %6.6s %10.10s %11.11s %9.7s %16.16s \n" ,p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
printf ( "请选择您的操作 1---删除|2---修改\n" );
scanf ( "%d" ,&changekey);
if (changekey==1)
{
if (p1==head)
{head=p1->next;
free (p1);
}
else
{
p2->next=p1->next;
free (p1);
SaveChange();
}
}
else if (changekey==2)
{
printf ( "姓名:" ); scanf ( "%s" ,p1->name);
printf ( "性别:" ); scanf ( "%s" ,p1->sex);
printf ( "生日:" ); scanf ( "%s" ,p1->birthday);
printf ( "电话:" ); scanf ( "%s" ,p1->phone);
printf ( "邮编:" ); scanf ( "%s" ,p1->postcode);
printf ( "地址:" ); scanf ( "%s" ,p1->addr);
SaveChange();
printf ( "\n OK! \n" );
}
}
}
else if ( strcmp (p1->name,ChangeName)&&(p1->next)==NULL)
{
i=0;
}
p2=p1;
p1=p1->next;
}
if (y==0)
{
printf ( "对不起,没有找到要修改的通讯名单,请检查你要修改的姓名是否正确\n" );
}
system ( "pause" );
}
void ExirShow()
{
system ( "color 0E" );
printf ( "########### 通讯录管理系统 v1.0 ################\n" );
printf ( "############################################################\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "# 谢谢使用! #\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "# #\n" );
printf ( "############################################################\n" );
printf ( "# POWER BY ************* 兰州理工大学 201407 #\n" );
printf ( "############################################################\n" );
}
void ErrorShow()
{ int errortime=5;
system ( "color 0E" );
for (errortime=5;errortime>0;errortime--)
{ printf ( "\r输入错误!请仔细检查!将在%d秒后返回" ,errortime);
Sleep(1000);
}
}
int main()
{ int key;
int Ex_key;
int Check_key;
char a[10];
if ((fp= fopen ( "txl.dat" , "ab" ))==NULL)
{
printf ( "文件操作错误,请检查是否有权限操作文件!" );
Sleep(3000);
exit (1);
}
fclose (fp);
FileLoading();
while (1){
ShowMenu();
gets (a);
key= atoi (a);
if (key==1)
{ system ( "cls" );
add();
}
else if (key==2)
{ system ( "cls" );
system ( "color 0E" );
while (1)
{
system ( "color 0E" );
CheckFace();
printf ( "请输入你的选择:\n" );
gets (a);
Check_key= atoi (a);
if (Check_key==1)
Selelctname()
;
else if (Check_key==2)
Selelctphone()
;
else if (Check_key==3)
Selelctall()
;
else if (Check_key==4)
break ;
else
ErrorShow();
system ( "cls" );
system ( "color 1F" );
getchar ();
}
}
else if (key==3) //2013级 耿。。
{ system ( "color 0E" );
system ( "cls" );
AllShow();
system ( "pause" );
}
else if (key==4)
{
system ( "color 0A" );
Change();
}
else if (key==5)
{
system ( "color 5F" );
system ( "cls" );
AllNum();
system ( "pause" );
}
else if (key==6)
{
system ( "cls" );
ExirShow();
Sleep(1000);
exit (0);
}
else
ErrorShow();
system ( "cls" );
system ( "color 1F" );
getchar ();
}
}
|
比较简单就是用到了链表和文件操作,其中统计联通和移动人数的那里其实只用一个循环就可以。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://blog.csdn.net/geng333abc/article/details/37988555