版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、程序主要功能:电话薄管理系统要求实现一个电话薄系统的基本管理功能,包括1. 创建电话薄2. 分屏显示电话薄中的所有记录3. 向电话薄中插入一条记录4. 删除一条已经存在的记录项5. 根据用户输入的姓名查找符合条件的记录项6. 从文件读入已有的电话薄7. 将通讯录信息输出到文件8. 逆序存放9. 删除同名记录#. 统计人数*. 按首字母查询0. 退出分析:本题以链表为基础,而链表需用指针访问,故链表与指针便贯穿整个程序,成为整个程序最重要的部分。此外,看似对指针之前所学部分要求不高,但实际却也是此程序得以编写成功必不可少的先决条件。主要问题及解决方法:在程序编写过程中遇到了不少问题,特别是编译通
2、过后,却仍有部分功能未能很好实现。比如:1与4中对是否继续增加记录和是否删除的控制,程序中虽有scanf 语句,但运行时却总是自动跳过,并不执行此语句,经过反复阅读程序、思考,终于发现是前面的scanf 语句中输入的回车符被放入了输入缓冲区中,并在下一次scanf 语句中被自动输入,因而也就有了scanf语句被跳过的假象。一个 char m;m=getchar();便解决了这一问题。此外,还有从文件读入记录时,第一条记录总是难以被读入,后来发现原来是因为程序是从head-next开始读入,将之改为head即可。感想与体会:编写此程序,花费了不少的时间,但却也让我感受到了编写程序的乐趣,对于我来
3、说,这已经是一种享受。新增功能:除了习题册上的附加功能,还增加了统计人数和按首字母查询功能。源程序:#includestdio.h#includestring.h#includestdlib.h#includectype.hstruct studentchar name10;char sex5;char telenumber15;char email30;struct student *next;int menu_select()char i;dosystem(cls);printf(1.录入记录n);printf(2.显示所有记录n);printf(3.插入一条记录n);printf(4.删
4、除一条记录n);printf(5.查询n);printf(6.从文件读入记录n);printf(7.写入文件n);printf(8.逆序存放n);printf(9.删除同名记录n);printf(#.统计人数n);printf(*.按首字母查询n);printf(0.退出n);i=getchar();while(i9)&i!=#&i!=*);return(i-0);/*录入记录*/struct student *Create() struct student *Insert(struct student *,struct student *);struct student *p,*head=N
5、ULL;char c=Y,m;char stu_name10,stu_sex5,stu_telenumber15,stu_email20;while(c=Y|c=y) printf(请录入记录:n姓名t性别t电话t邮箱n);scanf(%s%s%s%s,stu_name,stu_sex,stu_telenumber,stu_email);p=(struct student *)malloc(sizeof(struct student);strcpy(p-name,stu_name); strcpy(p-sex,stu_sex); strcpy(p-telenumber,stu_telenumb
6、er); strcpy(p-email,stu_email);head=Insert(head,p);m=getchar();printf(是否继续录入记录?(Y/N)n);c=getchar();return head;/*显示所有记录*/void Display(struct student *head)int i;struct student *p;p=head;printf(输出如下:n);for(i=1;i+)if(p!=NULL)printf(%st%st%st%sn,p-name,p-sex,p-telenumber,p-email);p=p-next;elseprintf(输出
7、完毕n);break;if(i%10=0)system(pause);system(cls);struct student *Insert(struct student *head,struct student *p)struct student *p1,*p2;if(head=NULL)head=p;p-next=NULL;return (head);p2=p1=head;while(strcmp(p-name,p1-name)0&p1-next!=NULL)p2=p1;p1=p1-next;if(strcmp(p-name,p1-name)next=p1;if(head=p1)head=p
8、;elsep2-next=p;elsep1-next=p;p-next=NULL;return (head);/*插入一条记录*/struct student *Insert_a_record(struct student *head)struct student *p;p=(struct student *)malloc(sizeof(struct student);printf(请输入待插入记录:n姓名t性别t电话t邮箱n);scanf(%s%s%s%s,p-name,p-sex,p-telenumber,p-email);head=Insert(head,p);return (head)
9、;struct student *Delete(struct student *head,char s10)struct student *p1,*p2;if(head=NULL)printf(链表为空n);return (NULL);p1=head;while(strcmp(p1-name,s)!=0&p1-next!=NULL)p2=p1;p1=p1-next;if(strcmp(p1-name,s)=0)if(p1=head)head=p1-next;elsep2-next=p1-next;printf(记录%s删除成功!,s);elseprintf(记录%s不存在!,s);return
10、 (head); /*删除一条记录*/struct student *Delete_a_record(struct student *head)printf(请输入待删除记录的姓名.n);char m10;scanf(%s,m);printf(确认删除数据%s?(Y/N)n,m);char i,t;t=getchar(); i=getchar();if(i=Y|i=y)head=Delete(head,m);else printf(操作已取消n);return (head);struct student *Query(struct student *head,char s10)struct s
11、tudent *p;p=head;while(p!=NULL)if(strcmp(p-name,s)=0)printf(查找成功:%st%st%st%sn,p-name,p-sex,p-telenumber,p-email);return p;p=p-next;printf(查找失败:无此记录n);return NULL;/*查询*/void Query_a_record(struct student *head)printf(请输入待查找记录的姓名n);char m10;scanf(%s,m);Query(head,m);/*从文件读入记录*/struct student *AddfromT
12、ext(struct student *head)FILE *fp;fp=fopen(data.txt,r);if(fp=NULL)printf(无法打开文件!n);exit(1);char record100;dostruct student *p;p=(struct student *)malloc(sizeof(struct student);fscanf(fp,%s,p-name);fscanf(fp,%s,p-sex);fscanf(fp,%s,p-telenumber);fscanf(fp,%s,p-email);head=Insert(head,p);while(fgets(re
13、cord,100,fp)!=NULL);fclose(fp);return(head);/*写入文件*/void WritetoText(struct student *head)FILE *fp;fp=fopen(record.txt,w);if(fp=NULL)printf(无法打开文件!n);exit(1);struct student *p;p=head;while(p!=NULL)fprintf(fp,%st,p-name);fprintf(fp,%st,p-sex);fprintf(fp,%st,p-telenumber);fprintf(fp,%s,p-email);fprint
14、f(fp,n);p=p-next;fclose(fp);/*退出*/void Quit(struct student *head)struct student *p;while(head!=NULL)p=head;head=head-next;free(p);/*逆序存放*/struct student *Reverse(struct student *head)struct student *newhead=NULL,*p;while(head!=NULL)p=head;head=head-next;p-next=newhead;newhead=p;return newhead;/*删除同名
15、记录*/struct student *DeleteSame(struct student *head)struct student *p1,*p2,*p3;p1=head;while(p1-next)!=NULL)p2=p1-next;p3=p1;while(p2!=NULL)if(strcmp(p1-name,p2-name)=0&strcmp(p1-sex,p2-sex)=0&strcmp(p1-telenumber,p2-telenumber)=0&strcmp(p1-email,p2-email)=0)p3-next=p2-next;return(head);elsep3=p2; p
16、2=p2-next;p1=p1-next;return (head);/*统计人数*/void Count(struct student *head)struct student *p;p=head;int i;for(i=0;p!=NULL;i+)p=p-next;printf(您的电话薄中共有%d个联系人n,i);/*按首字母查询*/void Query_by_first_letter(struct student *head)struct student *p;p=head;char c2; printf(请输入要查找联系人姓名的首字母!n);scanf(%s,c);printf(查找如
17、下:n);while(p!=NULL)if(strncmp(p-name,c,1)=0)printf(%st%st%st%sn,p-name,p-sex,p-telenumber,p-email);p=p-next;void main()struct student *head=NULL;for(;)switch(menu_select()case 1:head=Create(); system(pause);break;case 2:Display(head);system(pause);break;case 3:head=Insert_a_record(head);system(pause
18、);break;case 4:head=Delete_a_record(head);system(pause);break;case 5:Query_a_record(head);system(pause);break;case 6:head=AddfromText(head);system(pause);break;case 7:WritetoText(head);system(pause);break;case 8:head=Reverse(head);system(pause);break;case 9:head=DeleteSame(head);system(pause);break;case -13:Count(hea
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- T/SXJP 046-2023煤矿用整芯阻燃输送带
- T/SXZX 012-2024绿色铸造专业镇评价通则
- T/DYZYXH 001-2024医养结合机构等级评定规范
- T/CI 1238-2025核电厂阀门阀杆密封组件检维修技术导则
- T/AIITRE 21011-2025能源企业数据开发能力建设与管理要求
- T/CNIDA 020-2024核电工程爆破振动监测技术规程
- 2025~2026学年河南濮阳市范县度人教版第一册一年级数学阶段学情自测卷【附答案】
- 2025~2026学年安徽滁州市天长市苏教版三年级下册期末数学试卷【附答案】
- 2025-2026学年江苏省宜兴市初中历史七年级期末下册自测经典测试题(附答案)
- PHP架构师面试题及详细答案(企业真实版)
- 2024年10月 财务管理学(00067)自考真题
- 自考13174概率论与数理统计(工)高频考点重点
- 2026全国广播电视播音员主持人资格考试(综合知识)历年参考题库含答案详解
- 2026 年冬季取暖防一氧化碳中毒课件
- 第7课《培养德智体美劳全面发展的社会主义建设者和接班人》课件
- 变电站舞动灾害应急演练脚本
- 2026年辅警考试时事政治练习题附答案
- 2025四川成都兴城投资集团有限公司招聘11人笔试历年典型考点题库附带答案详解
- 2026年中级注册安全工程师《建筑施工安全》押题宝典题库附答案详解AB卷
- 2025年股份制银行审计人员招聘考试真题(含答案)
- 汽车救援人员培训及考核规范
评论
0/150
提交评论