南京航空航天大学C语言课程设计报告

上传人:飞*** 文档编号:37406578 上传时间:2018-04-15 格式:DOC 页数:14 大小:56.50KB
返回 下载 相关 举报
南京航空航天大学C语言课程设计报告_第1页
第1页 / 共14页
南京航空航天大学C语言课程设计报告_第2页
第2页 / 共14页
南京航空航天大学C语言课程设计报告_第3页
第3页 / 共14页
南京航空航天大学C语言课程设计报告_第4页
第4页 / 共14页
南京航空航天大学C语言课程设计报告_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《南京航空航天大学C语言课程设计报告》由会员分享,可在线阅读,更多相关《南京航空航天大学C语言课程设计报告(14页珍藏版)》请在金锄头文库上搜索。

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、于我来说,这已经是一种享受。新增功能:除了习题册上的附加功能,还增加了统计人数和按首字母查询功能。源程序:#include“stdio.h“#include“string.h“#include“stdlib.h“#include“ctype.h“struct 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.插

4、入一条记录n“);printf(“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)return(i-0);/*录入记录*/struct student *Create() struct student *Insert(struct student *,struct student *);

5、struct student *p,*head=NULL;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);st

6、rcpy(p-telenumber,stu_telenumber);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-telenum

7、ber,p-email);p=p-next;elseprintf(“输出完毕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)0p1=p1-next;if(strcmp(p-name,p1-name)next=

8、p1;if(head=p1)head=p;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=

9、Insert(head,p);return (head);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)!=0p1=p1-next;if(strcmp(p1-name,s)=0)if(p1=head)head=p1-next;elsep2-next=p1-next;printf(“记录%s 删除成功!“,s);elseprintf(“记录%s

10、不存在!“,s);return (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 *

11、head,char s10)struct student *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);/*从文件

12、读入记录*/struct student *AddfromText(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“

13、,p-email);head=Insert(head,p);while(fgets(record,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);fpri

14、ntf(fp,“%st“,p-telenumber);fprintf(fp,“%s“,p-email);fprintf(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;h

15、ead=head-next;p-next=newhead;newhead=p;return newhead;/*删除同名记录*/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)=0return(head);elsep3=p2;p2=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)

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 企业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号