当前位置:文档之家› (完整版)通讯录管理系统数据结构毕业课程设计(C语言)

(完整版)通讯录管理系统数据结构毕业课程设计(C语言)

湖南工程学院课程设计报告通讯录管理系统姓名:李任学院:计算机与通讯学院专业:计算机科学与技术班级:计算机0803班指导教师:刘长松目录1.第一章:前言 (2)2.第二章:概述 (3)3.第三章:算法分析 (5)4.第四章:主要流程图 (12)5.第五章:程序源代码 (13)6.第六章:测试及输出结果 (20)7.第七章:课程设计体会 (23)8.第八章:参考文献 (24)第一章:前言通过一个学期的学习,我认为要学好C语言程序这门课程,不仅要认真阅读课本知识,更重要的是要通过上机实践才能增强和巩固我的知识。

而C语言课程设计则对我们有以下几点帮助:1. 进一步掌握和利用C语言进行程序设计的能力;2. 进一步理解和运用结构化程序设计的思想和方法;3. 初步掌握开发一个小型实用系统的基本方法;4. 学会调试一个较长程序的基本方法;5. 学会利用流程图或N-S图表示算法;6. 掌握书写程设计开发文档的能力 (书写课程设计报告) 。

第二章:概述一、本课程设计的目的和意义本课程设计可加深对课堂理论学习的理解,增强动手能力,以培养学生合作的能力,为毕业设计作好实践环节上的准备。

通讯录系统是在学校常见的计算机信息管理系统。

它的主要任务是对学生信息进行管理,如学生信息的输入、查询、修改、增加、删除,迅速准确地完成各种学生信息的统计和查询。

二、本课程设计主要内容本系统有分7个功能:(1)写入数据(2)读取数据(3)追加数据(4)查找数据(5)备份数据(6)删除数据(7)还原数据。

其主要利用结构类型,指针,数组,函数等C语言知识来实现。

第三章:算法分析整个系统共分为8模块,主函数加7个子函数,从而实现7大功能:写入数据,读取数据,追加数据,查找数据,备份数据,删除数据,还原数据;各个程序的算法分析如下:(1)主函数main():利用for( ; ; )和switch()实现主界面的显示与各选项的连接;流程图如下:(2)写入函数void input1():利用文件的fwrite()语句来实现数据的保存;流程图如下:(3)读取数据void read1():利用文件的fread()语句来实现数据的读取;流程图如下(4)追加数据void append1():利用fread()来读出文件里的数据,从而确定数据的数量,再在最后一条数据后通过fopen(“文件名”,”ab”)来实现追加;流程图如下:(5)查找数据void find1()通过strcmp()==0来实现数据的查找;流程图如下:(6)备份数据void backup1():通过将数据复制到另一个文件里的方法来实现备份功能;流程图如下:(7)删除数据void delete1():通过将后一行数据覆盖前一行数据的方法来实现删除功能;流程图如下:(8)还原数据comeback1():通过将已备份的数据复制到原来的这个文件里的方法来实现还原的流程图如下:第四章:主要流程图系统功能模块结构图:各模块功能的分析:(1)主函数:可让用户选择用系统的哪个功能,从而去连接到相应的子函数;(2)写入数据:让用户输入通讯录里的内容,并将内容保存好;(3)读取数据:显示通讯录里已保存的数据;(4)追加数据:让用户在通讯录原有数据中,再加上新的数据;(5)查找数据:通过用户输入需要找的名字来找到相关资料;(6)备份数据:将已有数据进行备份;(7)删除数据:让用户删除想要删除的资料;(9)还原数据:使通讯录里的数据恢复到备份时的模样。

第五章:程序源代码#include <stdio.;printf("Be careful!!!Do you sure to input?(yn):\7\7\7\n");n=getchar();n=getchar();if(n!='y')return;{fp=fopen("txl","wb");for(i=0;i<N;i++){printf("Input the name(Input exit return):\n");scanf("%s",stu[i].name);if(strcmp(stu[i].name,"exit")==0)return;else{printf("Input the city:\n");scanf("%s",stu[i].city);printf("Input the email:\n");scanf("%s",stu[i].email);printf("Input the phone:\n");scanf("%ld",&stu[i].phone);printf("Input the zip:\n");scanf("%ld",&stu[i].zip);fwrite(&stu[i],sizeof(struct address),1,fp);}}fclose(fp);}}void read1(){FILE *fp;int i;if((fp=fopen("txl","rb"))==NULL){printf("Can not to open the txl.\n");return;}printf("====================================================== ==========================\n");printf(" Name City Email Phone Zip \n");printf("====================================================== ==========================\n");for(i=0;fread(&stu[i],sizeof(struct address),1,fp)!=0&&i<N;i++){printf("%15s%15s%20s%15ld%10ld\n",stu[i].name,stu[i].city,stu[i].email,stu[i].phone,stu[i].zip);}getch();fclose(fp);}void append1(){FILE *fp;int i,sum=0;if((fp=fopen("txl","rb"))==NULL){printf("Can not to open the txl.\n");return;}for(i=0;fread(&stu[i],sizeof(struct address),1,fp)!=0&&i<N;i++) sum+=1;fclose(fp);if((fp=fopen("txl","ab"))==NULL){printf("Can not to open the txl.\n");return;}for(i=sum;i<N;i++){printf("Input the name(Input exit return):\n");scanf("%s",stu[i].name);if(strcmp(stu[i].name,"exit")==0)return;else{printf("Input the city:\n");scanf("%s",stu[i].city);printf("Input the email:\n");scanf("%s",stu[i].email);printf("Inpute the phone:\n");scanf("%ld",&stu[i].phone);printf("Inpute the zip:\n");scanf("%ld",&stu[i].zip);fwrite(&stu[i],sizeof(struct address),1,fp);}}fclose(fp);}void find1(){FILE *fp;int i,j;char s[16];printf("Input the name:\n");scanf("%s",s);if((fp=fopen("txl","rb"))==NULL){printf("Can not to open the txl.\n");return;}for(i=0;fread(&stu[i],sizeof(struct address),1,fp)!=0&&i<N;i++) if(strcmp(stu[i].name,s)==0){printf("====================================================== ==========================\n");printf(" Name CityEmail Phone Zip \n");printf("====================================================== ==========================\n");printf("%15s%15s%20s%15ld%10ld",stu[i].name,stu [i].city,stu[i].email,stu[i].phone,stu[i].zip);getch();}fclose(fp);}void backup1(){FILE *fp1,*fp2;int i;if((fp1=fopen("txl","rb"))==NULL){printf("Can not to open the txl.\n");return;}fp2=fopen("txl2","wb");for(i=0;fread(&stu[i],sizeof(struct address),1,fp1)!=0&&i<N;i++) fwrite(&stu[i],sizeof(struct address),1,fp2);fclose(fp1);fclose(fp2);printf("The backup was done!\n");getch();}void delete1(){FILE *fp;int i,j,n=0;char s[16];printf("Input the name:\n");scanf("%s",s);if((fp=fopen("txl","rb"))==NULL){printf("Can not to open the txl.\n");return;}for(i=0;fread(&stu[i],sizeof(struct address),1,fp)!=0&&i<N;i++) {if(strcmp(stu[i].name,s)==0){for(j=i+1;fread(&stu[j],sizeof(structaddress),1,fp)!=0&&j<N;j++){strcpy(stu[j-1].name,stu[j].name);strcpy(stu[j-1].city,stu[j].city);strcpy(stu[j-1].email,stu[j].email);strcpy(stu[j-1].phone,stu[j].phone);strcpy(stu[j-1].zip,stu[j].zip);}}n+=1;}fclose(fp);fp=fopen("txl","wb");for(i=0;i<n-1;i++){fwrite(&stu[i],sizeof(struct address),1,fp);}fclose(fp);printf("The date was delete.");getch();}comeback1(){FILE *fp,*fp1;int i;if((fp1=fopen("txl2","rb"))==NULL){printf("Can not to open the txl.\n");return;}fp=fopen("txl","wb");for(i=0;fread(&stu[i],sizeof(struct address),1,fp1)!=0&&i<N;i++) fwrite(&stu[i],sizeof(struct address),1,fp);fclose(fp1);fclose(fp);printf("The comback was done!\n");getch();}main(){int a;for(;;){printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * * * *\n");printf(" * * * *\n");printf(" * * (1)Input the data * *\n");printf(" * * (2)Read the txl * *\n");printf(" * * (3)Append the data * *\n");printf(" * * (4)Find the data * *\n");printf(" * * (5)Backup the data * *\n");printf(" * * (6)Delete the data * *\n");printf(" * * (7)Comeback the data * *\n");printf(" * * * *\n");printf(" * * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * * * *\n");printf(" * * (0)Exit * *\n");printf(" * * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" % % % % % % % % % % % % % % % % % % %\n");printf(" % %\n ");printf(" % This program is make for Wu Feng! %\n");printf(" % %\n ");printf(" % % % % % % % % % % % % % % % %% % %\n");printf("Input 0-7:");scanf("%d",&a);switch (a){case 1: input1();break;case 2: read1();break;case 3: append1();break;case 4: find1();break;case 5: backup1();break;case 6: delete1();break;case 7: comeback1();break;case 0:printf("* * * * * * * * * * * * * * * * * * ** *\n");printf("**\n");printf("* Good by~~~*\n");printf("**\n");printf("* * * * * * * * * * * * * * * * * * ** *\n");getch();exit();break;default: printf("The number is not in 0-7!\n");getch();break;}}}第六章:测试及输出结果写入数据函数测试:在主界面输入:1屏幕输出:Be careful!!!Do you sure to input?(yn):输入:y屏幕输出:Input the name(Input exit return):输入:liang屏幕输出:Input the city:输入:zhuhai屏幕输出:Input the email:屏幕输出:Input the phone:输入:123456屏幕输出:Input the zip:输入:519055屏幕输出:Input the name(Input exit return):输入:exit回到主界面;读取数据函数测试:在主界面输入:2屏幕输出:按下任意键回到主函数;追加数据函数测试:在主界面输入:3屏幕输出:Input the name(Input exit return): 输入:li屏幕输出:Input the city:输入:zhuhai屏幕输出:Input the email:屏幕输出:Input the phone:输入:654321屏幕输出:Input the zip:输入:519055屏幕输出:Input the name(Input exit return): 输入:exit回到主界面,输入:2屏幕输出:按任意键回到主函数;查找数据函数测试:在主界面输入:4屏幕输出:Input the name:输入:liang屏幕输出:按任意键返回主界面;备份数据函数测试:在主界面输入:5屏幕输出:The backup was done! 按任意键返回主界面;删除数据函数测试:在主界面输入:6屏幕输出:Input the name:输入:li屏幕输出:The date was delete.按任意键返回主界面,输入:2屏幕输出:按任意键返回主界面;还原数据函数测试:在主界面输入:7屏幕输出:The comback was done! 按任意键返回主界面,输入2屏幕输出:按任意键返回主界面;退出程序:在主界面输入:0屏幕输出:按任意键退出程序。

相关主题