本文实例为大家分享了C语言实现通讯录管理系统的具体代码,供大家参考,具体内容如下
工具:Visual C++6.0
说明:
本系统基于C语言实现班级通讯录管理系统,为大一时学习C语言刚入门所做的课程设计。功能包括增、删、查、改等,非常适合初学者练手。通讯录包括的个人信息有姓名、学号、性别、籍贯、政治面貌、手机号、QQ号、宿舍等。主要用到了指针、结构体、遍历链表、文件读取等知识点。
运行效果:
代码:
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
|
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
typedef struct student //定义结构体
{
char name[20]; //姓名
char num[15]; //学号
char sex[10]; //性别
char from[20]; //籍贯
char political[10]; //政治面貌
char phone[15]; //手机号
char QQ[15]; //QQ号
char dorm[10]; //宿舍
struct student *next; //结构体指针
}stu;
stu *head;
void print() //主菜单
{
system ( "cls" );
printf ( "\n\n\n" );
printf ( " ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n" );
printf ( " ***********************************************************\n" );
printf ( " \t\t\t班级通讯录管理系统\n" );
printf ( "\n" );
printf ( " \t\t1. 输入数据" );
printf ( "\t\t2. 显示数据\n" );
printf ( " \t\t3. 插入数据" );
printf ( "\t\t4. 删除数据\n" );
printf ( " \t\t5. 查看数据" );
printf ( "\t\t6. 修改数据\n" );
printf ( " \t\t7. 保存数据" );
printf ( "\t\t8. 返回主菜单\n" );
printf ( " ***********************************************************\n" );
printf ( " ~~~~~退~~~~~~~~~~出~~~~~~~~~~请~~~~~~~~~~按~~~~~~~~~~9~~~~~\n" );
printf ( " -----------------------------------------------------------\n\n" );
}
void input(stu *p1) //输入相关数据
{
printf ( "姓名:" );
scanf ( "%s" ,&p1->name);
printf ( "学号:" );
scanf ( "%s" ,&p1->num);
printf ( "性别:" );
scanf ( "%s" ,&p1->sex);
printf ( "籍贯:" );
scanf ( "%s" ,&p1->from);
printf ( "政治面貌:" );
scanf ( "%s" ,&p1->political);
printf ( "手机号:" );
scanf ( "%s" ,&p1->phone);
printf ( "QQ号:" );
scanf ( "%s" ,&p1->QQ);
printf ( "宿舍:" );
scanf ( "%s" ,&p1->dorm);
}
stu * inputdata() //数据输入的函数
{
stu *p1,*p2;
int i=1;
p1=(stu *) malloc ( sizeof (stu));
if (p1!=NULL)
{
head=p1;
printf ( "\n\t\t\t☆☆☆输入数据☆☆☆\n" );
printf ( "------------------------------------------------------------------\n" );
printf ( "在姓名处输入“ok”代表输入数据结束\n" );
while (i)
{
printf ( "姓名:" );
scanf ( "%s" ,&p1->name);
if ( strcmp (p1->name, "ok" )==0)
{
printf ( "\n输入完毕!\n" );
printf ( "========================================================================\n" );
i=0;
p2->next=NULL;
free (p1);
p1=p2;
}
else
{
printf ( "学号:" );
scanf ( "%s" ,&p1->num);
printf ( "性别:" );
scanf ( "%s" ,&p1->sex);
printf ( "籍贯:" );
scanf ( "%s" ,&p1->from);
printf ( "政治面貌:" );
scanf ( "%s" ,&p1->political);
printf ( "手机号:" );
scanf ( "%s" ,&p1->phone);
printf ( "QQ号:" );
scanf ( "%s" ,&p1->QQ);
printf ( "宿舍:" );
scanf ( "%s" ,&p1->dorm);
printf ( "=====================================\n" );
p2=p1;
p1=(stu *) malloc ( sizeof (stu));
if (p1!=NULL)
{
p2->next=p1;
}
}
}
return (p1->next);
}
}
stu * lookdata(stu *p1) //查看数据的函数
{
printf ( "\n\t\t\t☆☆☆显示数据☆☆☆\n" );
printf ( "----------------------------------------------------------------------\n" );
while (p1!=NULL)
{
printf ( "姓名:%s\n" ,p1->name);
printf ( "学号:%s\t" ,p1->num);
printf ( "性别:%s\t" ,p1->sex);
printf ( "籍贯:%s\t" ,p1->from);
printf ( "政治面貌:%s\t" ,p1->political);
printf ( "手机号:%s\t" ,p1->phone);
printf ( "QQ号:%s\t" ,p1->QQ);
printf ( "宿舍:%s\n" ,p1->dorm);
printf ( "======================================================================\n" );
p1=p1->next;
}
return p1;
}
void insert() //插入数据
{
int i;
char named[20];
stu *p1,*p2,*p3;
p1=head;
p3=(stu *) malloc ( sizeof (stu));
p3->next=NULL;
printf ( "\n\t\t\t☆☆☆插入数据☆☆☆\n" );
printf ( "----------------------------------------------------------------------\n" );
printf ( "请输入插入者的资料:\n" );
input(p3);
printf ( "\n插入选项\n" );
printf ( "1.首位置插入\t2.尾位置插入\t3.前插\n" );
printf ( "请输入你的选择:" );
scanf ( "%d" ,&i);
switch (i)
{
case 1:p3->next=p1;
head=p3;
break ;
case 2: while (p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
p1->next=p3;
break ;
case 3: printf ( "请输入姓名(前插):" );
scanf ( "%s" ,named);
while ( strcmp (named,p1->name)!=0)
{
p2=p1;
p1=p1->next;
}
p2->next=p3;
p3->next=p1;
break ;
}
printf ( "插入成功!\n" );
printf ( "======================================================================\n" );
return ;
}
void deleted() //删除数据
{
stu *p1,*p2;
char Name[20]; //想要删除的人的姓名
printf ( "\n\t\t\t☆☆☆删除数据☆☆☆\n" );
printf ( "----------------------------------------------------------------------\n" );
printf ( "请输入要删除的姓名:" );
scanf ( "%s" ,Name);
p1=head;
if (head==NULL)
{
printf ( "内存空空神马都没有!\n" );
printf ( "======================================================================\n" );
return ;
}
if ( strcmp (Name,p1->name)==0)
{
head=p1->next;
printf ( "删除成功!\n" );
printf ( "======================================================================\n" );
return ;
}
while (p1!=NULL&&( strcmp (Name,p1->name)!=0))
{
p2=p1;
p1=p1->next;
}
if (p1==NULL)
{
printf ( "此人不存在!\n" );
printf ( "======================================================================\n" );
return ;
}
if (p1->next!=NULL)
{
p1=p1->next;
p2->next=p1;
printf ( "删除成功!\n" );
printf ( "======================================================================\n" );
return ;
}
else
{
p2->next=NULL;
printf ( "删除成功!\n" );
printf ( "======================================================================\n" );
return ;
}
}
find(stu *p2) //通过姓名查找查看数据的函数
{
char name[20];
int b=0;
printf ( "\n\t\t\t☆☆☆查看数据☆☆☆\n" );
printf ( "----------------------------------------------------------------------\n" );
printf ( "请输入您想查找人的姓名:" );
scanf ( "%s" ,name);
while (p2!=NULL)
{
if ( strcmp (name,p2->name)==0)
{
printf ( "你要找到的数据\n" );
printf ( "姓名:%s\n" ,p2->name);
printf ( "学号:%s\t" ,p2->num);
printf ( "性别:%s\t" ,p2->sex);
printf ( "籍贯:%s\t" ,p2->from);
printf ( "政治面貌:%s\t" ,p2->political);
printf ( "手机号:%s\t" ,p2->phone);
printf ( "QQ号:%s\t" ,p2->QQ);
printf ( "宿舍:%s\n" ,p2->dorm);
printf ( "======================================================================\n" );
b=1;
}
p2=p2->next;
}
if (b==0)
{
printf ( "\n您要查找的人不存在!\n" );
}
}
update(stu *p2) //通过姓名查找修改数据
{
char name[20];
int b=0,i;
printf ( "\n\t\t\t☆☆☆修改数据☆☆☆\n" );
printf ( "----------------------------------------------------------------------\n" );
printf ( "请输入将要修改人的姓名:" );
scanf ( "%s" ,name);
while (p2!=NULL)
{
if ( strcmp (name,p2->name)==0)
{
printf ( "该同学的基本信息\n" );
printf ( "姓名:%s\n" ,p2->name);
printf ( "学号:%s\t" ,p2->num);
printf ( "性别:%s\t" ,p2->sex);
printf ( "籍贯:%s\t" ,p2->from);
printf ( "政治面貌:%s\t" ,p2->political);
printf ( "手机号:%s\t" ,p2->phone);
printf ( "QQ号:%s\t" ,p2->QQ);
printf ( "宿舍:%s\n" ,p2->dorm);
printf ( "\n请选择要修改的信息\n" );
printf ( "\t1.姓名\t2.学号\t3.性别\t4.籍贯\n\t5.政治面貌\t6.手机号\t7.QQ\t8.宿舍\n" );
printf ( "\n您的选择是(1~8):" );
scanf ( "%d" ,&i);
printf ( "请输入修改之后的内容\n" );
switch (i)
{
case 1: printf ( "姓名:" );
scanf ( "%s" ,&p2->name);
break ;
case 2: printf ( "学号:" );
scanf ( "%s" ,&p2->num);
break ;
case 3: printf ( "性别:" );
scanf ( "%s" ,&p2->sex);
break ;
case 4: printf ( "籍贯:" );
scanf ( "%s" ,&p2->from);
break ;
case 5: printf ( "政治面貌:" );
scanf ( "%s" ,&p2->political);
break ;
case 6: printf ( "手机号:" );
scanf ( "%s" ,&p2->phone);
break ;
case 7: printf ( "QQ:" );
scanf ( "%s" ,&p2->QQ);
break ;
case 8: printf ( "宿舍:" );
scanf ( "%d" ,&p2->dorm);
break ;
}
printf ( "\n修改成功!\n" );
printf ( "=========================================================================\n" );
b=1;
}
p2=p2->next;
}
if (b==0)
{
printf ( "没有找到该人的资料!\n" );
}
}
save(stu *p2) //保存数据
{
FILE *fp;
char file[15];
printf ( "\n\t\t\t☆☆☆保存数据☆☆☆\n" );
printf ( "----------------------------------------------------------------------\n" );
printf ( "输入文件名:" );
scanf ( "%s" ,file);
if ((fp= fopen (file, "w" ))==NULL)
{
printf ( "cannot open this file\n" );
exit (0);
}
fprintf (fp, "姓名\t学号\t性别\t籍贯\t政治面貌\t手机号\tQQ号\t宿舍\n" );
while (p2!=NULL)
{
fprintf (fp, "%s\t" ,p2->name);
fprintf (fp, "%s\t" ,p2->num);
fprintf (fp, "%s\t" ,p2->sex);
fprintf (fp, "%s\t" ,p2->from);
fprintf (fp, "%s\t" ,p2->political);
fprintf (fp, "%s\t" ,p2->phone);
fprintf (fp, "%s\t" ,p2->QQ);
fprintf (fp, "%s\n" ,p2->dorm);
p2=p2->next;
}
printf ( "\n保存成功!\n" );
printf ( "======================================================================\n" );
fclose (fp);
}
void screen()
{
int i;
char s[251]={ "欢迎使用由ZM制作班级通讯录管理系统,\n\n\t\t\t本系统用于通讯录管理----排序,打印\n\n\n\t\tWelcome to use produced by ZM class address book\n\n\t\t management system,sorting,printing" };
printf ( "\n================================================================================\n" );
printf ( "\n\n\n\t\t\t" );
for (i=0;s[i]!=NULL;i++)
{
Sleep(30);
printf ( "%c" ,s[i]);
}
printf ( "\n\n\n\n\n\n\n\n\t\t ~ Hi~ o(* ̄▽ ̄*)ブ~ ~ ~祝您旅途愉快~ ~\n" );
printf ( "================================================================================\n" );
}
void main()
{
int i;
system ( "color 4e" );
screen();
Sleep(3000);
print();
while (1)
{
printf ( "请输入你的选择(1~9):" );
loop: scanf ( "%d" ,&i);
if (i<1||i>9)
{
printf ( "输入有误,请在1~9中进行选择:" );
goto loop;
}
switch (i)
{
case 1:
inputdata();
break ;
case 2:
lookdata(head);
break ;
case 3:
insert();
break ;
case 4:
deleted();
break ;
case 5:
find(head);
break ;
case 6:
update(head);
break ;
case 7:
save(head);
break ;
case 8:
print();
break ;
case 9:
exit (1);
break ;
}
}
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://www.cnblogs.com/wyuzm/p/9588052.html