C语言简易手机号码管理系统
- 格式:doc
- 大小:539.00 KB
- 文档页数:25
C程序课程设计报告--手机通讯录管理系统**:**学院:珠宝学院学号:649班级:141082一课程设计目的和内容概述1.目的:加深对《C语言》课程所学知识的理解,进一步巩固C语言编程方法。
学会编制结构清晰、风格良好、数据结构适当的C语言程序,从而具备解决综合性实际问题的能力,加强动手能力。
2.内容:设计一个简易的手机通讯录管理系统。
该题目要求在熟练掌握C语言的基本知识:数据类型(整形、实型、字符型、指针、数组、结构等);运算类型(算术运算、逻辑运算、自增自减运算、赋值运算等);程序结构(顺序结构、判断选择结构、循环结构);大程序的功能分解方法(即函数的使用)等。
进一步掌握各种函数的应用,包括时间函数、、绘图函数,以及文件的读写操作等。
其中结构体,函数的调用,算法的设计是尤为重要的。
二题目手机通讯录管理系统。
[问题描述]该系统模拟手机通讯录管理系统,实现对手机中的通讯录进行管理[基本要求]要能提供以下几种功能:(1)查看功能:选择此功能时,列出下列三类选择:A:办公类B:个人类C:商务类(2)当选中某类时,显示出此类所有数据中的姓名和电话号码(3)添加数据功能:能录入新数据,每个结点包括:姓名,电话号码,分类(可能选项有:w为办公类p为个人类b为商务类),电子邮件。
例如:杨春商务类当录入重复的姓名和电话号码时,则提示数据录入重复并取消录入;当通讯录中超过15条信息时,存储空间已满,不能再录入新数据;录入的新数据能按递增的顺序自动进行条目编号。
(4)修改功能:选中某个人的姓名时,可对此人的相应数据进行修改。
(5)删除功能:选中某个人的姓名时,可对此人的相应数据进行删除,并自动调整后续条目的编号。
三程序设计1.总体设计首先,因为每个个体有多种信息,所以要建立结构体来储存和整合各个信息。
然后利用模块来分别实现程序的各个功能。
各个模块用函数来实现。
在通过通过主函数来判断输入字母,从而调动函数,实现所需功能。
#include <stdio.h>#include <string.h>#include <conio.h>#include <stdlib.h>#define bool int#define true 1#define false 0FILE *fp;struct tongxunlu /*定义通讯录结构体变量*/{char xingming[20]; /*定义输入名字的数组*/ char dianhua[20]; /*定义输入电话号码的数组*/ char dizhi[40]; /*定义输入地址的数组*/char shouji[11];//手机号码char youxiang[20];/*定义输入邮箱的数组*/char beizhu[40];/*定义输入备注的数组*/char xuehao[10];/*定义输入学号的数组*/char yunying[20];} txl[100]; //默认100个数据int n=0;//记录数据联系人数量int x,y,z,*p;char ch;bool judge=true;typedef struct{char user[20];char code[20];}USER;USER pe;void zhuce();void denglu();void panduan(int i);void zengjia();void writefile();void redfile();void write();void caozuo();void chazhao();void chazhao_xingming();void chazhao_dianhua();void xianshi();void xiugai();void xiugai_xingming();void xiugai_dianhua();void shanchu();void shanchu_quanbu();void shanchu_dange();void main(){printf(" ****************欢迎使用联系人管理系统****************\n");printf("\t\t1.用户登陆2.用户注册3.退出");ch=getch();if(ch=='1'||ch=='2'){switch(ch){case '1' : system("cls");denglu();break;case '2' : system("cls");zhuce();break;default : printf("error!");}}if(ch=='1'||ch=='2')writefile();else printf("\n\t\tBye^_^");exit(0);}void caozuo(){printf("\n\t\t1.添加联系人2.查找3.修改4.删除5.保存退出6.不保存退出7.保存并注销8.注销不保存");ch=getch();switch(ch){case '1' : system("cls");zengjia();break;case '2' : system("cls");chazhao();break;case '3' : system("cls");xiugai();break;case '4' : system("cls");shanchu();break;case '5' : system("cls");writefile();break;case '6' : printf("\n\t\tBye^_^");exit(0);case '7' : printf("\n\t\t正在保存,请稍后......\n\t\t注销成功");writefile();break;case '8' : fclose(fp);printf("\n\t\t注销成功");return main();break;default : printf("\n\t\terror!");return caozuo();}}void write() /*用户信息写入*/{if((fp=fopen(er,"w"))==NULL){printf("\n\t\t文件打开失败");}else if(fwrite(&pe,sizeof(USER),1,fp)!=1){printf("\n\t\t写入文件错误");}}void writefile() /*联系人写入文件*/{int i;if ((fp=fopen(er,"a"))==NULL){printf("\n\t\t文件打开失败");}for (i=0;i<n;i++){if (fwrite(&txl[i],sizeof(struct tongxunlu),1,fp)!=1){printf("\n\t\t写入文件错误!\n");}}fclose(fp); /*关闭文件*/printf("\n\t------------------------------------------------------");printf("\n\t\t联系人文件已保存");printf("\n\t\t谢谢使用,欢迎再次使用!\n");printf("\t\t如果对本软件有疑问,请给我们提出您的问题,我们将为您解答.\n");printf("\t\t我们的软件有不足之处,请与我们反映,我们将努力改正!");printf("\n\t\t按任意键退出程序\n\t\t");exit(0);printf("\n\t------------------------------------------------------");}void readfile(){fseek(fp,0,2);if(ftell(fp)>0){rewind(fp);fseek(fp,sizeof(USER),1);for(n=0;!feof(fp)&&fread(&txl[n],sizeof(struct tongxunlu),1,fp);n++);}else{rewind(fp);fseek(fp,sizeof(USER),1);printf("\t\t联系人为空");}printf("\n\t欢迎使用,按任意键进入");}void zhuce(){char temp[20],txt[100],cha;do{printf("\t\t\t\t用户注册");printf("\n\t\t1.直接注册2.阅读用户手册");cha=getch();if(cha=='2'){if((fp=fopen("使用说明.txt","r"))==NULL){printf("\n\t\t打开失败");exit(0);}fread(txt,2,20,fp);printf("\n\t\t%s",txt);/*txt=fgets(txt,100,fp);printf("%s",txt);*/}printf("\n\t\t按任意键继续");getch();system("cls");printf("\t\t\t\t用户注册");printf("\n\t\t用户名:");scanf("%s",er);printf("\n\t\t密码:");scanf("%s",pe.code);printf("\n\t\t确认密码:");scanf("%s",temp);if(strcmp(pe.code,temp)!=0)printf("\n\t\t两次密码不一致,请重新输入");}while(strcmp(pe.code,temp)!=0);fp=fopen(er,"r");if(fp==NULL){fp=fopen(er,"w");if(fp==NULL){printf("\n\t注册失败\n");exit(0);}else {system("cls");printf("\n\t注册成功");write();judge = false;denglu();}}else{printf("\n\t该用户名已存在");fclose(fp);printf("\n\t继续注册?(Y/N)");if(getch()=='Y') return zhuce();else return denglu();}}void denglu(){char u[20],c[20],temp[20];printf("\n\t\t\t\t用户登录");printf("\n\t\t用户名:");scanf("%s",u);fp=fopen(u,"r+");temp[0]='0';if(fp==NULL){printf("\n\t\t用户不存在,请注册");printf("\n\t\t1.注册 2.重新登陆");temp[0]=getch();if(temp[0]=='1'){system("cls");zhuce();}else return denglu();}do{if(judge==true) fread(&pe,sizeof(USER),1,fp);printf("\t\t密码:");scanf("%s",c);if(strcmp(pe.code,c)!=0){printf("\n\t\t密码错误(1.退出2.重新输入)");temp[0]=getch();printf("\n");if(temp[0]=='1'){fclose(fp);return main();}}}while(temp[0]=='2');readfile();getch();caozuo();}void zengjia(){char temp,temp2;printf("\n\t\t------------------请输入联系人信息--------------------\n");do{if(temp=='2') system("cls");printf("\n\t\t输入联系人姓名:");scanf("%s",txl[n].xingming); /*键盘输入*/printf("\n\t\t输入联系人电话号码:");scanf("%s",txl[n].dianhua);printf("\n\t\t输入联系人地址:");scanf("%s",txl[n].dizhi);panduan(n);printf("\n\t\t是否确定?(1.确定2.重输3.取消)");getch();temp=getch();}while(temp=='2');if(temp=='1'){n++; /*统计个数*/printf("\n\t\t是否继续添加联系人?(Y/N):"); /*是否继续输入联系人.*/temp2=getch();if (temp2=='Y'||temp2=='y')zengjia();}printf("\n");return caozuo();}void panduan(int i){char *str1="China Mobile",*str2="China Unicom",*str3="China Telicom",*str4="Virtual network operator";bool judge=true;do{do{printf(("\n\t\t输入手机号码:"));scanf("\n\t\t%s",txl[i].shouji);if(txl[i].shouji[10]=='\0'||txl[i].shouji[11]!='\0') printf("Error! Again\n");}while(txl[i].shouji[10]=='\0'||txl[i].shouji[11]!='\0');x=txl[i].shouji[1];x-=48;y=txl[i].shouji[2];y-=48;z=x*10+y;if((z>=34&&z<=39)||(z>=47&&z<=152)||(z>=157&&z<=159)||z==178||(z>=183&&z<=188)) {printf("\n\t\t%s\n",str1);strcpy(txl[i].yunying,str1);}elseif((z>=30&&z<=32)||z==145||z==155||z==156||z==171||z==175||z==176||z==185||z==186) {printf("\n\t\t%s\n",str2);strcpy(txl[i].yunying,str2);}else if(z==33||z==49||z==53||z==73||z==77||z==80||z==81||z==89){printf("\n\t\t%s\n",str3);strcpy(txl[i].yunying,str3);}else if(z==70) {printf("%s\n",str4);strcpy(txl[i].yunying,str4);}else{printf("Error! Check again\n");judge=false;}}while(judge==false);}///查询联系人函数开始模块四----------------------------------------------------void chazhao(){char c;system("cls");printf("\n\t\t-------------------显示和查询联系人------------------");printf("\n\t\t| 1-逐个显示所有2-按姓名查询|");printf("\n\t\t| 3-按电话查询4-返回主菜单|");printf("\n\t\t|------------------------------------------------------");printf("\n\t\t请选择您所所要的服务:");c=getch();switch (c){case '1':xianshi();break; /*显示所有号码*/case '2':chazhao_xingming();break; /*调用按姓名查询函数*/case '3':chazhao_dianhua();break; /*调用按号码查询函数*/case '4':caozuo();break; /*主菜单*/}}void xianshi()//显示所有联系人函数{int i;system("cls");//清楚屏幕if(n!=0){printf("\n\t\t----------欢迎您查询通讯录所有联系人信息-------------");for (i=0;i<n;i++) /*依次序显示*/{printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t手机: %s (%s)",txl[i].shouji,txl[i].yunying);printf("\n\t\t--------------------------------------------------");if (i+1<n){printf("\n\t\t-----------------------");system("pause");//返回错误信息}}printf("\n\t\t---------------------------------------------");}else /*无联系人*/printf("\n\t\t通讯录中无任何纪录");printf("\n\t\t按任意键返回主菜单:");getch();return caozuo();}//按号码查询函数void chazhao_dianhua(){int mark=0;int i;char phone[15];printf("\n\t\t-------------------按电话查找-------------------------");do{printf("\n\t\t请输入电话号码或手机号码:");scanf("%s",phone);if(phone[10]=='\0'||phone[11]!='\0') printf("Error! Again\n");}while(phone[10]=='\0'||phone[11]!='\0');for(i=0;i<n;i++){if (strcmp(txl[i].dianhua,phone)==0||strcmp(txl[i].shouji,phone)==0)//对比查找函数{printf("\n\t\t------------以下是您查找的学生信息------------");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t手机: %s (%s)",txl[i].shouji,txl[i].yunying);printf("\n\t\t------------------------------------------------");printf("\n\t\t按任意键返回主菜单:");mark++;getch();return caozuo();}}if (mark==0){printf("\n\t\t没有找到联系人的信息");printf("\n\t\t按任意键返回主菜单");getch();return caozuo();}}void chazhao_xingming()//按姓名查询{int mark=0;int i;char name[20];printf("\n\t\t----------------按姓名查找--------------------");printf("\n\t\t请输入您要查找的姓名:");scanf("%s",name);for(i=0;i<n;i++){if (strcmp(txl[i].xingming,name)==0){printf("\n\t\t------------以下是您查找的联系人信息---------------");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t手机: %s (%s)",txl[i].shouji,txl[i].yunying);printf("\n\t\t---------------------------------------------------");mark++;getch();return chazhao();}}if (mark==0){printf("\n\t\t没有找到联系人的信息");printf("\n\t\t按任意键返回主菜单");getch();return caozuo();}}////查询联系人函数结束-----------------------------------------------------////删除联系人函数部分开始-------------------------------------------------void shanchu(){char c;if(n==0) /*如果通讯录中没有一个记录输出以下部分*/{printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();return caozuo();}system("cls"); /*清屏*/printf("\n\t\t-----------------删除菜单----------------------");printf("\n\t\t| 1-删除所有2-删除单个|");printf("\n\t\t| 3-返回主菜单|");printf("\n\t\t|-------------------------------------------------");printf("\n\t\t请选择您所所要的服务:");c=getch(); /*输入的赋予choice*/switch (c){case '1':shanchu_quanbu();break;case '2':shanchu_dange();break;case '3':caozuo();break;default:caozuo();break;}}void shanchu_quanbu()//删除所有联系人{printf("\n\t\t确认删除?(y/n)");if (getch()=='y'){fclose(fp);if ((fp=fopen("通讯录.txt","w"))==NULL) /*文件空输出*/{printf("\n\t\t不能打开文件,删除失败");readfile();}n=0;printf("\n\t\t纪录已删除,按任意键返回主菜单");getch();return caozuo();}elsereturn caozuo();}void shanchu_xingming()//按姓名删除联系人{int i,m,mark=0,a=0;char name[20];printf("\n\t\t请输入要删除联系人姓名:");scanf("%s",name); /*键盘输入姓名*/for (i=a;i<n;i++){if (strcmp(txl[i].xingming,name) == 0) //对比字符串查找到要删除的联系人{printf("\n\t\t以下是您要删除的联系人纪录:");printf("\n\t\t--------------------------------");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t手机: %s (%s)",txl[i].shouji,txl[i].yunying);printf("\n\t\t--------------------------------");printf("\n\t\t是否删除?(y/n)");if (getch()=='y') // 实现删除功能{for (m=i;m<n-1;m++)txl[m]=txl[m+1]; /*将通讯录的向前移*/n--;mark++;printf("\n\t\t删除成功");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')shanchu_xingming(); /*继续调用删除函数*/return caozuo();}elsereturn shanchu_xingming();}continue;}if (mark==0){printf("\n\t\t没有该联系人的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')shanchu_xingming();return caozuo();}}void shanchu_dianhua()//按电话号码删除联系人{int i,m,mark=0; /*变量定义*/char phone[20];do{printf("\n\t\t请输入要删除联系人电话号码或手机号码:");scanf("%s",phone);if(phone[10]=='\0'||phone[11]!='\0') printf("Error! Again\n");}while(phone[10]=='\0'||phone[11]!='\0');if(n==0){printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();return caozuo();}for (i=0;i<n;i++){if (strcmp(txl[i].dianhua,phone)==0||strcmp(txl[i].shouji,phone)==0){printf("\n\t\t以下是您要删除的联系人纪录:");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t手机: %s (%s)",txl[i].shouji,txl[i].yunying);printf("\n\t\t是否删除?(y/n)");if (getch()=='y'){for (m=i;m<n-1;m++) //递推替换实现删除txl[m]=txl[m+1];n--;mark++; //记录删除次数printf("\n\t\t删除成功");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')shanchu_dianhua();return caozuo();}elsereturn shanchu_dianhua();}continue;}if (mark==0){printf("\n\t\t没有该联系人的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')return caozuo();}}void shanchu_dange()//删除单个联系人{char c;printf("\n\t----------------------------------------------------------");printf("\n\t\t 1-按姓名删除2-按电话或手机号码删除");printf("\n\t\t请选择您所所要的服务:");printf("\n\t----------------------------------------------------------");c=getch();switch (c){case '1':shanchu_xingming();break;case '2':shanchu_dianhua();break;}}///删除函数部分结束--------------------------------------------------------///修改联系人函数开始--------------------------------------------------void xiugai() /*修改函数*/{char c;if(n==0){printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();return caozuo();}system("cls");printf("\n\t\t-----------------修改联系人菜单-----------------------");printf("\n\t\t| 1-按姓名修改2-按电话或手机号码修改|");printf("\n\t\t| 任意键-按返回主菜单|");printf("\n\t\t------------------------------------------------------");c=getch();switch(c){case '1':xiugai_xingming();break;case '2':xiugai_dianhua();break;default:caozuo();break;}}void xiugai_xingming(){char c;int i,mark=0;char name[20];printf("\n\t\t请输入要修改的联系人姓名:");scanf("%s",name);if(n==0){printf("\n\t\t文件中无任何联系人");printf("\n\t\t按任意键返回主菜单");getch(); mark++;return caozuo();}for(i=0;i<n;i++){if(strcmp(txl[i].xingming,name)==0){printf("\n\t\t以下是您要修改的联系人信息");printf("\n\t\t姓名: %s",txl[i].xingming);printf("\n\t\t电话: %s",txl[i].dianhua);printf("\n\t\t地址: %s",txl[i].dizhi);printf("\n\t\t手机: %s (%s)",txl[i].shouji,txl[i].yunying);printf("\n\t\t是否修改(y/n)");if(getch()=='y'){printf("\n\t------------请选择修改信息---------------");printf("\n\t 1-修改姓名2-修改电话");printf("\n\t 3-修改地址4-修改手机号码");printf("\n\t-----------------------------------------");printf("\n\t请选择您所所要的服务:");scanf("%c",&c);switch(c){case '1': printf("\n\t请输入新姓名:");scanf("%s",txl[i].xingming);break;case'2':printf("\n\t请输入新电话:");scanf("%s",txl[i].dianhua);break;case'3':printf("\n\t请输入新地址: ");scanf("%s",txl[i].dizhi);break;case'4':do{printf("\n\t请输入新手机号码:");scanf("%s",txl[i].shouji);if(txl[i].shouji[10]=='\0'||txl[i].shouji[11]!='\0') printf("Error! Again\n");}while(txl[i].shouji[10]=='\0'||txl[i].shouji[11]!='\0');break;}}}}if(mark==0){printf("\n\t\t没有找到联系人信息");printf("\n\t是否继续修改?(Y/N):");if(getch()=='y')xiugai_xingming();return caozuo();}}void xiugai_dianhua(){char c,phone[15];int i,mark=0;do{printf("\n\t\t请输入要修改联系人的电话号码或手机:");scanf("%s",phone);if(phone[10]=='\0'||phone[11]!='\0') printf("Error! Again\n");}while(phone[10]=='\0'||phone[11]!='\0');if(n==0){printf("\n\t\t文件中无任何联系人");printf("\n\t\t按任意键返回主菜单");getch();mark++;return caozuo();}for(i=0;i<n;i++){if(strcmp(txl[i].dianhua,phone)==0||strcmp(txl[i].shouji,phone)==0){printf("\n\t\t以下是您要修改的联系人信息");printf("\n\t\t姓名: %s",txl[i].xingming);printf("\n\t\t电话: %s",txl[i].dianhua);printf("\n\t\t地址: %s",txl[i].dizhi);printf("\n\t\t手机: %s (%s)",txl[i].shouji,txl[i].yunying);printf("\n\t\t是否修改(y/n)");if(getch()=='y'){printf("\n\t------------请选择修改信息---------------");printf("\n\t 1-修改姓名2-修改电话");printf("\n\t 3-修改地址4-修改手机号码");printf("\n\t-----------------------------------------");printf("\n\t请选择您所所要的服务:");scanf("%c",&c);switch(c){case'1': printf("\n\t请输入新姓名:");scanf("%s",txl[i].xingming);break;case'2':printf("\n\t请输入新电话:");scanf("%s",txl[i].dianhua);break;case'3':printf("\n\t请输入新地址: ");scanf("%s",txl[i].dizhi);break;case'4':do{printf("\n\t请输入新手机号码:");scanf("%s",txl[i].shouji);if(txl[i].shouji[10]=='\0'||txl[i].shouji[11]!='\0') printf("Error! Again\n");}while(txl[i].shouji[10]=='\0'||txl[i].shouji[11]!='\0');break;}}}}if(mark==0){printf("\n\t没有该联系人信息");printf("\n\t是否继续修改?(Y/N):");if(getch()=='y')xiugai_dianhua();return caozuo();}}。
c语言课程设计 通讯录管理系统一、课程目标知识目标:1. 理解C语言中结构体的概念和使用方法,掌握利用结构体创建复杂数据结构的能力;2. 学会使用数组存储结构体数据,实现对通讯录信息的有效管理;3. 掌握基本的文件操作,能够实现通讯录数据的存储和读取。
技能目标:1. 能够运用结构体和数组设计并实现一个简单的通讯录管理系统;2. 掌握在C语言中进行简单的输入输出操作,实现用户界面的友好交互;3. 学会使用调试工具进行程序调试,提高解决问题的能力。
情感态度价值观目标:1. 培养学生对编程的兴趣,激发其主动探索和创新的欲望;2. 培养学生的团队协作意识,学会在项目开发中与他人合作;3. 引导学生关注信息技术在生活中的应用,认识到编程对解决实际问题的重要性。
课程性质:本课程为实践性较强的课程,要求学生在掌握C语言基础知识的基础上,运用所学知识设计并实现一个通讯录管理系统。
学生特点:学生具备一定的C语言基础,对编程有一定的兴趣,但可能缺乏实际项目经验。
教学要求:通过本课程的学习,使学生能够将所学知识应用于实际项目中,提高其编程能力和解决实际问题的能力。
将课程目标分解为具体的学习成果,以便在教学过程中进行有效指导和评估。
二、教学内容1. 结构体和结构体数组的概念及应用- 课本章节:第五章 结构体与共用体- 内容:结构体的定义、结构体成员的访问、结构体数组的创建与使用。
2. 文件操作基础- 课本章节:第六章 文件- 内容:文件的打开与关闭、文件的读写操作、文件的定位。
3. 通讯录管理系统设计- 内容:系统需求分析、功能模块划分、系统设计、实现与测试。
4. 用户界面设计- 内容:菜单设计、命令行用户输入输出、简单的人机交互流程。
5. 项目实践与团队协作- 内容:项目分组、任务分配、代码共享与协作、项目评审。
教学进度安排:第一周:复习结构体和结构体数组相关知识,讲解通讯录管理系统需求。
第二周:学习文件操作基础,设计通讯录数据存储与读取功能。
学生通讯录管理系统C语言编程简介学生通讯录管理系统是一个帮助学生管理通讯录信息的应用程序。
通过该系统,学生可以添加、删除、查询和修改通讯录中的联系人信息,从而更好地组织和管理自己的通讯录信息。
功能需求1. 添加联系人学生可以通过输入联系人的姓名、电话号码、邮箱等信息,将联系人添加到通讯录中。
2. 删除联系人学生可以根据联系人的姓名或电话号码,从通讯录中删除指定的联系人信息。
3. 查询联系人学生可以通过姓名或电话号码查询通讯录中的联系人信息,并将查询结果显示出来。
4. 修改联系人学生可以修改通讯录中指定联系人的信息,如电话号码、邮箱等。
技术实现通讯录管理系统将使用C语言进行编程实现。
以下是系统的基本设计思路:1. 数据结构设计通讯录信息可以用结构体来表示,包含联系人的姓名、电话号码、邮箱等字段。
struct Contact {char name[50];char phone[20];char email[50];};2. 功能模块划分•添加联系人模块:用于添加新的联系人信息。
•删除联系人模块:用于删除指定联系人信息。
•查询联系人模块:用于根据姓名或电话号码查询联系人信息。
•修改联系人模块:用于修改指定联系人的信息。
3. 用户界面设计系统将使用控制台界面,通过菜单来实现各个功能模块的调用。
开发步骤1. 定义数据结构首先定义联系人结构体,包含姓名、电话号码、邮箱等字段。
2. 实现功能模块分别实现添加联系人、删除联系人、查询联系人、修改联系人等功能模块的具体代码。
3. 编写主程序编写主程序,通过调用功能模块来实现整体通讯录管理系统的运行。
总结学生通讯录管理系统C语言编程是一个实用的项目,通过这个项目,学生可以熟练掌握C语言编程的基本知识,并且实践项目开发的流程。
通过不断调试和完善,学生可以提升自己的编程能力和项目实现能力。
希望学生能够在这个项目中学到更多的知识,提升自己的编程技能。
通讯录管理系统(C语⾔)/** 对通讯录进⾏插⼊、删除、排序、查找、单个显⽰功能*/#include <stdio.h>#include <malloc.h>#include <string.h>#include <stdlib.h>int n;typedef struct _Address_List{char name[30]; //名字char work[30]; //职业char handset[20]; //⼿机号码char email[30]; //电⼦邮件char address[30]; //地址struct _Address_List *next;}address_List;#define LEN sizeof(address_List)address_List *Release(address_List *head);//创建⼀个通讯录address_List *Create(void){address_List *head,*p1,*p2;char name[30];n = 0;p1 = (address_List *)malloc(LEN);p2 = p1;printf("请输⼊通讯录的内容!\n姓名输⼊为0时表⽰创建完毕!\n");printf("请输⼊姓名:");gets(name);if(strcmp(name,"0")!=0){strcpy(p1->name,name);printf("请输⼊职业:");gets(p1->work);printf("请输⼊⼿机:");gets(p1->handset);printf("请输⼊电⼦邮件:");gets(p1->email);printf("请输⼊通讯地址:");gets(p1->address);head = NULL;while(1){n = n+1;if(n == 1){head = p1;}else{p2->next = p1;}p2 = p1;printf("请输⼊姓名:");gets(name);if(strcmp(name,"0") == 0){break;}else{p1 = (address_List *)malloc(LEN);strcpy(p1->name,name);printf("请输⼊职业:");gets(p1->work);printf("请输⼊⼿机:");gets(p1->handset);printf("请输⼊电⼦邮件:");gets(p1->email);printf("请输⼊通讯地址:");gets(p1->address);}}return head;}else{return0;}}//打印整个通讯录void print(address_List *head){address_List *p;if(head != NULL){p = head;printf("本通讯录现在共有%d⼈;\n",n);printf("---姓名---------职业----------⼿机--------Email-------------通讯地址\n");printf("====================================================================\n");do{printf("=%s\t\t",p->name);printf("=%s\t\t",p->work);printf("=%s\t\t",p->handset);printf("=%s\t\t",p->email);printf("=%s\n",p->address);p = p->next;}while(p != NULL);printf("==================================================================\n"); }else{printf("通讯录为空,⽆法输出!\n");}}//在通讯录插⼊address_List *insert(address_List *head){address_List *p0,*p1,*p2;char name[20];p1 = head;printf("请输⼊增加的内容:\n");printf("请输⼊姓名:");gets(name);if(strcpy(name,"0") == 0){printf("姓名不能为0,增加失败!\n");return head;}else{p0 = (address_List *)malloc(LEN);strcpy(p0->name,name);printf("请输⼊职业:");gets(p1->work);printf("请输⼊⼿机:");gets(p1->handset);printf("请输⼊电⼦邮件:");gets(p1->email);printf("请输⼊通讯地址:");gets(p1->address);n = n+1;if(head == NULL){head = p0;p0->next = NULL;return head;}else{while(strcmp(p0->name,p1->name) > 0 && (p1->next != NULL)){p2 = p1;p1 = p1->next;}if(strcmp(p0->name,p1->name) <0 || strcmp(p0->name,p1->name) == 0){if(head == p1){head = p0;}else{}p0->next = p1;}else{p1->next = p0;p0->next = NULL;}return head;}}}//删除通讯录中某个⼈address_List *delete_txl(address_List *head){address_List *p,*q;char name[30];if(head == NULL){printf("通讯录为空,⽆法删除!\n");return head;}p = head;printf("请输⼊需要删除的⼈姓名:");gets(name);if(strcmp(head->name,name) == 0){head = head->next;free(p);printf("删除操作成功!\n");return head;}else{q = head;p = head->next;while(p != NULL){if(strcmp(p->name,name) == 0){q->next = p->next;free(p);printf("删除操作成功!\n");return head;}p = p->next;q = q->next;}}}//显⽰通讯录中某个⼈address_List *display(address_List *head){address_List *p1,*p2;char name[30];int m;if(head == NULL){printf("通讯录为空,⽆法显⽰!\n");return head;}p1 = head;m = 0;printf("请输⼊要显⽰⼈的姓名:");gets(name);while(p1 != NULL){while(strcmp(p1->name,name) != 0 && p1->next != NULL){p2 = p1;p1 = p1->next;}if(strcmp(p1->name,name) == 0){m++;printf("%s的通讯内容如下:\n",name);printf("---姓名---------职业----------⼿机--------Email-------------通讯地址\n");printf("====================================================================\n"); printf("=%s=\t\t",p1->name);printf("=%s=\t\t",p1->work);printf("=%s=\t\t",p1->handset);printf("=%s=\n",p1->address);printf("====================================================================\n"); }p1 = p1->next;}if(m == 0){printf("此⼈不在通讯录中!\n");}return head;}//对通讯录进⾏排序操作address_List *Sort(address_List *head){address_List *p1,*p2;int i,j;typedef struct _Address_List1{char name[30]; //名字char work[30]; //职业char handset[20]; //⼿机号码char email[30]; //电⼦邮件char address[30]; //地址}address_List1;address_List1 Sort[200];address_List1 temp;if(head == NULL){printf("通讯录为空,⽆法排序!\n");return head;}p1 = head;for(i = 0;i < n,p1 != NULL; i++){strcpy(Sort[i].name,p1->name);strcpy(Sort[i].work,p1->work);strcpy(Sort[i].handset,p1->handset);strcpy(Sort[i].email,p1->email);strcpy(Sort[i].address,p1->address);p2 = p1;p1 = p1->next;}head = Release(head);for(j = 0; j < n-1; j++){for(i = j+1; i < n; i++){if(strcmp(Sort[i].name,Sort[j].name) < 0){Sort[i] = temp;temp = Sort[j];Sort[j] = temp;}}}p1 = (address_List *)malloc(LEN);p2 = p1;strcpy(p1->name,Sort[0].name);strcpy(p1->work,Sort[0].work);strcpy(p1->handset,Sort[0].handset);strcpy(p1->email,Sort[0].email);strcpy(p1->address,Sort[0].address);head = p1;for(i = 1; i < n; i++){p1 = (address_List *)malloc(LEN);strcpy(p1->name,Sort[i].name);strcpy(p1->work,Sort[i].work);strcpy(p1->handset,Sort[i].handset);strcpy(p1->email,Sort[i].email);strcpy(p1->address,Sort[i].address);p2->next = p1;p2 = p1;}p2->next = NULL;printf("按姓名排序后的结果是:\n");print(head);return head;}address_List *Search_name(address_List *head){address_List *p1,*p2;int m;char name[30];if(head == NULL){printf("通讯录为空,⽆法查找!\n");return head;}p1 = head;printf("**************************\n");printf("****请输⼊要查找的姓名:**\n");printf("**************************\n");m = 0;gets(name);while(p1 != NULL){while(strcmp(p1->name,name) != 0 && (p1->next != NULL)){p2 = p1;p1 = p1->next;}if(strcmp(p1->name,name) == 0){m++;printf("你查找的内容是:\n");printf("++++++++++++++++++++++++++++++++\n");printf("++ %s\t%s\t%s\t%s\t%s ++",p1->name,p1->work,p1->handset,p1->email,p1->address); printf("++++++++++++++++++++++++++++++++\n");}p1 = p1->next;if(m == 0){printf("你查找的姓名不在通讯录中!\n");}break;}return head;}//释放整个通讯录address_List *Release(address_List *head){address_List *p;while(head != NULL){p = head;head = head->next;free(p);}return head;}//保存(以⽂件的形式保存)void save(address_List *head){FILE *fp;address_List *p;char Filename[30]; //保存后的⽂件名if(head ==NULL){printf("待保存的通讯录为空,⽆法保存!\n");return ;}printf("请输⼊保存后的⽂件名:");gets(Filename);fp = fopen("Filename.txt","w");if(fp == NULL){printf("⽆法打开⽂件!\n");return ;}p = head;fprintf(fp,"姓名\t职业\t⼿机\tEmail\t地址\n");for(;p != NULL;){fprintf(fp,"姓名\t职业\t⼿机\tEmail\t地址",p->name,p->work,p->handset,p->email,p->address);p = p->next;}printf("保存完毕!\n");}//⽂件读出函数address_List *Load(address_List *head){FILE *fp;char Filename[30];address_List *p1,*p2;printf("请输⼊要输出的⽂件名:");gets(Filename);fp = fopen("Filename.txt","r");if(fp == NULL){printf("此通讯录不存在,⽆法输出!\n");return head;}else{head = Release(head);}p1 = (address_List *)malloc(LEN);fscanf(fp,"%s%s%s%s%s",p1->name,p1->work,p1->handset,p1->email,p1->address);if(feof(fp) != 0){printf("⽂件为空,⽆法打开!\n");return head;}else{rewind(fp);p2 = p1;head = p1;n = 0;while(feof(fp) == 0){fscanf(fp,"%s%s%s%s%s",p1->name,p1->work,p1->handset,p1->email,p1->address);if(feof(fp) != 0){break;}p2->next = p1;p2 = p1;p1 = (address_List *)malloc(LEN);n = n+1;}p2->next = NULL;p1 = head;head = head->next;n = n-1;free(p1);print(head);printf("打开完毕!\n");return head;}fclose(fp);}//菜单选择函数address_List *menu(address_List *head){char num[10];while(1){printf("*******************************\n");printf("*****1. 姓名查找 **********\n");printf("*****2. 单个显⽰ **********\n");printf("*****3. 增加 **********\n");printf("*****4. 退出 **********\n");printf("*******************************\n");printf("请输⼊你选择的操作:");gets(num);switch(*num){case'1':{head = Search_name(head);print(head);}break;case'2':{head = display(head);break;case'3':{head = insert(head);print(head);}break;case'4':return head;default:printf("操作有误,此项不存在!\n");break;}if(strcmp(num,"6") == 0){break;}}return head;}//主函数int main(void){address_List *head = NULL;char num[10];printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"); printf("*=*=*=*=*=*=*= 程序说明 *=*=*=*=*=*=*\n");printf("*=*=*=*=*=*=*= 请及时保存创建完毕的通讯录内容 *=*=*=*=*=*=*\n");printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"); while(1){printf("*******************************\n");printf("****** 1. 创建通讯录 *******\n");printf("****** 2. 按名字排序 *******\n");printf("****** 3. 综合操作 *******\n");printf("****** 4. 保存 *******\n");printf("****** 5. 打开 *******\n");printf("****** 6. 删除 *******\n");printf("****** 7. 退出 *******\n");printf("*******************************\n");printf("请输⼊你选择的操作:");gets(num);switch(*num){case'1':{if(head == NULL){head = Create();print(head);}else{head = Release(head);head = Create();print(head);}}break;case'2':{head = Sort(head);}break;case'3':{head = menu(head);}break;case'4':{save(head);print(head);}break;case'5':{head = Load(head);}break;case'6':{print(head);}break;case'7':{head = Release(head);}break;default:{printf("操作有误,此项不存在!\n"); }break;}if(strcmp(num,"7") == 0){break;}}return0;}。
C语言课程设计___手机通讯录管理系统-CAL-FENGHAI-(2020YEAR-YICAI)_JINGBIANC语言课程设计手机通信录管理系统院系:姓名:学号:班号:指导教师:2014年12月目录一题目要求 ....................................................................................................错误!未定义书签。
二需求分析 ....................................................................................................错误!未定义书签。
三总体设计 ....................................................................................................错误!未定义书签。
四详细设计 ....................................................................................................错误!未定义书签。
1.主函数..................................................................................................错误!未定义书签。
2.各功能模块设计..................................................................................错误!未定义书签。
(1)查看模块..............................................................................错误!未定义书签。
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>#define N 100void input();//添加新用户void amend();//修改用户信息void delete_client();//删除用户信息void search_client();//用户信息查询void collect_telephone();//所有用户信息void save_client(struct telephone message);//保存void search_name();//按用户名查询void search_telephone();//按电话号码查询void goodbye();//退出提示struct telephone{char client_name[20];char client_address[30];char client_telephone[15];};void main(){char choice[10]="";int len=0;while (choice[0]!='7'){system("cls");printf(" ◢◤〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓◥◣");printf("\n ◢◤〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓◥◣");printf("\n █===┏┯┓┏┯┓┏┯┓┏┯┓┏┯┓┏┯┓┏┯┓┏┯┓┏┯┓┏┯┓===█");printf("\n █===┠欢┨┠迎┨┠使┨┠用┨┠电┨┠话┨┠管┨┠理┨┠系┨┠统┨===█");printf("\n █===┗┷┛┗┷┛┗┷┛┗┷┛┗┷┛┗┷┛┗┷┛┗┷┛┗┷┛┗┷┛===█");printf("\n ◥◣〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓◢◤");printf("\n ◥◣〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓◢◤\n");printf(" ★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★≈★");printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");printf(" ┃| | | ┃\n");printf(" ┃ 1、 | 用户信息查询 | 2、 | 所有用户信息┃\n");printf(" ┃| | | ┃\n");printf(" ┃=========|════════════|========|════════════┃\n");printf(" ┃| | | ┃\n");printf(" ┃ 3、 | 删除用户信息 | 4、 | 添加用户┃\n");printf(" ┃| | | ┃\n");printf(" ┃=========|════════════|========|════════════┃\n");printf(" ┃| | | ┃\n");printf(" ┃ 5、 | 修改用户信息 | 6、 | 退出系统┃\n");printf(" ┃| | | ┃\n");printf(" 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");printf("\n 请选择(1-6):");scanf("%s",choice);len=strlen(choice);if (len>1){printf("\n 请输入1-6之间的整数\n");printf("\n 按回车键返回主菜单\n");getchar();getchar();continue;}switch (choice[0]){case '1':search_client();break;case '2':collect_telephone();break;case '3':delete_client();break;case '4':input();break;case '5':amend();break;case '6':goodbye();break;default:break;}}}//添加新用户void input(){struct telephone message;char reply='y';char save='y';while (reply=='y'){system("cls");printf("\n 用户姓名:");scanf("%s",message.client_name);printf("\n 家庭住址:");scanf("%s",message.client_address);printf("\n 电话号码:");scanf("%s",message.client_telephone);printf("\n 要保存吗?(y/n):");scanf(" %c",&save);if (save=='y'){save_client(message);}printf("\n 是否继续?(y/n):");scanf(" %c",&reply);}printf("\n 按回车键返回主菜单\n");getchar();getchar();}//保存void save_client(struct telephone message){FILE *fp;fp=fopen("message.dat","a+");if (fp!=NULL){fwrite(&message,sizeof(struct telephone),1,fp);}else{printf("\n 打开文件时出现错误,按回车键返回\n");getchar();return;}fclose(fp);}//修改用户信息void amend(){struct telephone message;FILE *fp;char amend_name[20];char reply='y';char found='y';char save='y';int size=sizeof(struct telephone);while (reply=='y'){found='n';fp=fopen("message.dat","r+w");if (fp!=NULL){system("cls");printf("\n 请输入你要修改的姓名:");scanf("%s",amend_name);while ((fread(&message,size,1,fp))==1){if ((strcmp(amend_name,message.client_name))==0){found='y';break;}}if (found=='y'){printf("\n 修改用户信息\n");printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓");printf("\n ┃用户姓名┃ %-16s┃",message.client_name);printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃家庭地址┃ %-16s┃",message.client_address);printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃电话号码┃ %-16s┃",message.client_telephone);printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");printf("\n 修改用户信息:\n");printf("\n 用户姓名:");scanf("%s",message.client_name);printf("\n 家庭住址:");scanf("%s",message.client_address);printf("\n 电话号码:");scanf("%s",message.client_telephone);printf("\n 是否保存?(y/n):");scanf(" %c",&save);if(save=='y'){fseek(fp,-size,1);fwrite(&message,sizeof(struct telephone),1,fp);}}else{printf("\n 无此信息!\n");}}else{printf("\n 打开文件时出现错误,按回车键返回\n");getchar();return;}fclose(fp);printf("\n 是否继续?(y/n):");scanf(" %c",&reply);}printf("\n 按回车键返回主菜单\n");getchar();getchar();}//删除用户信息void delete_client(){struct telephone message[N];struct telephone temp_str;struct telephone delete_str;int i=0,j=0;char reply='y';char found='y';char confirm='y';char delete_name[20];FILE *fp;while (reply=='y'){system("cls");fp=fopen("message.dat","r");if (fp!=NULL){i=0;found='n';printf("\n 请输入你要删除的姓名:");scanf("%s",delete_name);while ((fread(&temp_str,sizeof(struct telephone),1,fp))==1){if((strcmp(delete_name,temp_str.client_name))==0){found='y';delete_str=temp_str;}else{message[i]=temp_str;i++;}}}else{printf("\n 无此信息,按回车键返回\n");getchar();return;}fclose(fp);if (found=='y'){printf("\n 用户信息");printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓");printf("\n ┃用户姓名┃ %-16s┃",delete_str.client_name);printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃家庭地址┃ %-16s┃",delete_str.client_address);printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃电话号码┃ %-16s┃",delete_str.client_telephone);printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");}else{printf("\n 无此信息,按回车键返回\n");getchar();break;}printf("\n 确定要删除?(y/n):");scanf(" %c",&confirm);if (confirm=='y'){fp=fopen("message.dat","w");if (fp!=NULL){for(j=0;j<i;j++){fwrite(&message[j],sizeof(struct telephone),1,fp);}printf("\n 记录已删除\n");}else{printf("\n 打开文件时出现错误,按回车键返回\n");getchar();return;}fclose(fp);}printf("\n 是否继续?(y/n):");scanf(" %c",&reply);}getchar();}//用户信息查询void search_client(){int choice=1;while (choice!=3){system("cls");printf("\n 电话查询菜单\n");printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓");printf("\n ┃ 1 ┃按用户姓名查询┃");printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃ 2 ┃按电话号码查询┃");printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃ 3 ┃返回主菜单┃");printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");printf("\n 请选择(1-3):");scanf("%d%*c",&choice);if (choice>3){printf("\n 请输入1-3之间的整数(1-3)\n");printf("\n 按回车键返回");getchar();continue;}if (choice==1){search_name();}else if (choice==2){search_telephone();}}}//按用户名查询void search_name(){struct telephone message;FILE *fp;char amend_name[20];char reply='y';char found='y';while (reply=='y'){found='n';fp=fopen("message.dat","r+w");if (fp!=NULL){system("cls");printf("\n 请输入你要查的姓名:");scanf("%s",amend_name);while ((fread(&message,sizeof(struct telephone),1,fp))==1){if ((strcmp(amend_name,message.client_name))==0){found='y';break;}}if (found=='y'){printf("\n 用户信息\n");printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓");printf("\n ┃用户姓名┃ %-16s┃",message.client_name);printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃家庭地址┃ %-16s┃",message.client_address);printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃电话号码┃ %-16s┃",message.client_telephone);printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");}else{printf("\n 无此信息\n");}}else{printf("\n 打开文件时出现错误,按回车键返回\n");getchar();return;}fclose(fp);printf("\n 是否继续?(y/n):");scanf(" %c",&reply);}printf("\n 按回车键返回主菜单\n");getchar();getchar();}//按电话号码查询void search_telephone(){struct telephone message;FILE *fp;char telephone[20];char reply='y';char found='y';while (reply=='y'){found='n';fp=fopen("message.dat","r+w");if (fp!=NULL){system("cls");printf("\n 请输入你要查的电话号码:");scanf("%s",telephone);while ((fread(&message,sizeof(struct telephone),1,fp))==1){if ((strcmp(telephone,message.client_telephone))==0){found='y';break;}}if (found=='y'){printf("\n 用户信息\n");printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓");printf("\n ┃用户姓名┃ %-16s┃",message.client_name);printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃家庭地址┃ %-16s┃",message.client_address);printf("\n ┃━━━━━━━━┃━━━━━━━━━━━━┃");printf("\n ┃电话号码┃ %-16s┃",message.client_telephone);printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");}else{printf("\n 无此电话号码信息\n");}}else{printf("\n 打开文件时出现错误,按回车键返回\n");getchar();return;}fclose(fp);printf("\n 是否继续?(y/n):");scanf(" %c",&reply);}printf("\n 按回车键返回主菜单\n");getchar();}//显示所有用户信息函数void collect_telephone(){struct telephone message;FILE *fp;fp=fopen("message.dat","r");if (fp!=NULL){system("cls");printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓");printf("\n ┃用户姓名┃家庭地址┃电话号码┃");printf("\n 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");while ((fread(&message,sizeof(struct telephone),1,fp))==1){printf(" ┃%-16s┃%-16s┃%-16s┃",message.client_name,message.client_address,message.client_telephone);printf("\n ┃━━━━━━━━┃━━━━━━━━┃━━━━━━━━┃\n");}}else{printf("\n 打开文件时出现错误,按回车键返回\n");getchar();return;}fclose(fp);printf("\n 按回车键返回主菜单\n");getch();}//退出函数void goodbye(){char c;printf(" 真的退出?(y/n):");getchar();if(c=='y'||c=='Y'){system("cls");exit(0);}elseif(c=='n'||c=='N'){printf("\n 按回车键返回\n");getch();}}。
目录1 问题定义 (3)2 系统设计 (3)2.1 总体设计 (4)2.2 详细设计 (4)2.2.1 数据结构设计 (5)2.2.2 主控流程 (6)2.2.3 输入记录模块 (6)2.2.4 查询记录模块 (6)2.2.5 更新记录模块 (6)2.2.6 输出记录模块 (7)2.2.7 数据功能描述 (8)3 系统实现 (8)3.1 编码 (8)3.1.1 程序预处理 (9)3.1.2 主函数main() (9)3.1.3 主菜单界面 (10)3.1.4 删除用户记录 (11)3.1.5 查询用户记录 (12)3.1.6 插入用户记录 (15)3.1.7 保存用户数据 (17)3.1.8 从文件读数据 (18)3.1.9 追加学生记录 (19)3.1.10 排序用户记录 (21)3.2 测试与调试 (21)3.2.1 概述 (21)3.2.2 程序测试 (22)4 系统维护 (24)5 归纳总结 (25)5.1 开发经验 (25)5.2 实训中遇到的问题及解决方法 (25)5.3 设计中的不足之处 (25)5.4 感想和心得体会 (26)6 参考资料 (26)简易手机号码管理系统本题目设计目的是训练用户的基本编程能力,了解管理信息系统的开发流程,熟悉C语言的文件和单链表的各种基本操作。
本程序中涉及结构体、单链表、文件及各种语句的运用如for();switch();if….else等方面的知识。
通过本程序的训练,使用户能对C语言的文件操作有一个更深刻的了解,初步掌握链表的一些结构及构成。
掌握利用单链表存储结构实现对用户成绩管理的原理,为进一步开发出高质量的管理信息系统打下坚实的基础。
1、问题定义创建一个简易手机号码管理系统。
假设系统中每个号码记录包括电话号码,姓名,话费,地址,是否挂失。
2,剩余金额3,手机缴费,挂失,发信息,注销,保存。
及用户信息,课程信息,用户信息的修改、删除和查询等程序的运行效果如下图所示,选择任意菜单后,实现相应功能。
在问题定义阶段要考虑题目的可行性和需求分析,接下来进入开发阶段,完成系统设计和系统实现的任务。
2、系统设计2.1 总体设计采用模块化的程序设计方法,即将较大的任务按照一定的原则分为一个个较小的任务,然后分别设计各个小任务。
需要注意的是划分出来的模块应该相对独立但又相关,且容易理解。
可以用模块化层次结构图(即模块图)来分析其任务的划分,一般从上到下进行,最上面一层是主模块,下面各层是其上一层模块的逐步细化描述。
图2.1简易手机号码管理系统功能模块图本号码管理系统要求采用单链表实现,如图2.1所示,它由如下四大功能模块组成:●输入记录模块。
完成将数据存入单链表的工作。
记录可以从以二进制形式存储的数据文件中读入,也可从键盘逐个输入客户记录。
客户记录由客户的基本信息和话费使用信息字段构成。
当从数据文件中读入记录时,也就是把在以记录为单位存储的数据文件中,将记录逐条复制到单链表中。
●查询记录模块。
完成在单链表中查找满足相关条件的客户记录。
在此号码管理系统中,用户可以按照自己的号码或姓名在单链表中进行查找。
若找到该用户的记录,则返回指向该用户的记录的指针。
否则返回一个值为NULL的空指针,并打印出未找到该用户记录的提示信息。
●更新记录模块。
完成对用户记录的维护。
在此手机号码管理系统中,它实现了对用户记录的追加、删除、插入和排序操作,并将追加后的数据存入源数据文件。
●输出记录模块。
一是实现对用户记录的存盘,即将记录写入数据文件中;二是实现将记录信息以表格的形式在屏幕上打印出来。
2.2 详细设计2.2.1数据结构设计单链表node结构体struct arr /*定义数据结构*/{char PhoneNumber[40];char name[40];float telephonefare;char address[40];int ok;int xinxi;}caller[100];这样就定义了一个单链表的结构,结构体struct arr 将用于存储用户的基本信息,它将作为单链表的数据结构。
2.2.2 主控main()函数执行流程本手机号码管理系统执行主流程如图2.2所示。
它先以可读写的方式打开数据文件,此文件默认为“C:\”,若该文件不存在,则新建此文件。
当打开文件操作成功后,从文件中一次读出一条记录,添加到新建的单薄链表中,然后执行显示主菜单和进入主循环操作,调用do—while函数。
图2.2 主控函数执行流程图在判断键值时,有效的输入为本0至6之间的任意数值,其他输入都被视为错误按键。
若输入为0,它会跳出系统操作。
若选择1,则调用input_message()函数,执行输入用户信息操作;若选择2,则调用find_message(caller)函数,执行查找用户记录操作;若选择3,则调用delete_all(caller)函数,执行将用户记录全部删除;若选择4,则调用modify(caller)函数,执行查询用户记录及修改信息,缴费,挂失等操作;若选择5,则调用write(caller)函数,执行将用户记录存入数据文件的操作;若选择6,则调用read1(caller)函数,执行读文件操作,读出用户信息;2.2.3输入记录模块输入记录模块主要实现将数据存入单链表中。
当从数据文件中读出记录时,调用fread(p,sizeof(caller),1,fp)文件读取函数,执行一次从文件中读取一条用户使用记录信息存入指针变量p所指的节点中的操作,并且该操作在main()函数中执行,即当手机号码管理系统进入显示菜单界面时,该操作已经执行了。
若该文件中没有数据,系统会提示单链表为空,没有任何用户记录可操作,此时,用户应选择1,调用input_message()函数,进行用户记录的输入,即完成在单链表l中添加记录的操作。
值得一提的是,这里的字符串和数值的输入分别采用了函数来实现,在函数中完成输入数据任务,并对数据进行条件判断,直到满足条件为止,这样一来,大大减少了代码的重复和冗余,符合模块化程序设计的特点。
2.2.4查询记录模块查询记录模块主要实现了在单链表中按电话号码或姓名查找满足相关条件的用户记录。
在用户选择2,调用查询函数find_message(caller)中,根据提示输入,就可以查到信息,如果输入错误,小河会让你从新输入直到输入正确为止,若找到该记录,则返回指向该节点的指针;否则,返回一个空指针。
2.2.5更新记录模块此模块主要实现了对用户记录的追加、删除、插入和排序操作。
因为用户记录是以单链表的结构形式存储的,所以这些操作都在单链表中完成。
下面分别介绍着4个功能模块。
①追加记录。
该操作需要对单链表中目标节点的数据域中的值进行追加,它分两步完成。
第一步,追加要输入的电话号码,输入后调用modify(caller)函数,把该用户的电话号码和姓名及花费金额输入;第二步,若输入该用户记录,追加除电话号码字段之外的各字段值,并将存盘标记变量save(),表示已经对记录进行了追加,但还未执行存盘操作。
②删除记录。
该操作完成删除指定电话号码或姓名的用户记录,它也分两步完成。
第一步,输入要删除的电话号码或姓名,输入后调用删除函数delete all(),在单链表中逐个对节点数据域中电话号码或姓名字段的值进行比较,直到找到该电话号码或姓名的用户记录,则返回指向该用户记录的节点指针;第二步,若找到该用户记录,将该用户记录所在节点的前驱节点的指针域,指向目标节点的后继节点,则系统会显示你已成功删除的电话号码或姓名。
③排序记录。
有关排序的算法很多,如冒泡排序、插入排序等。
针对单链表结构的特点,我们采用插入排序算法实现按总分的从高到低对用户记录进行排序,排序完成之后,即可按顺序给名次字段赋值。
在单链表中,实现插入排序的基本步骤如下:1)新建一个单链表l,用来保存排序结果,其初始值为待排序单链表中的头节点。
2)从待排序单链表中取出下一个节点,将其总分字段值与单链表l中的各节点中总分字段的值进行比较,直到在链表l中找到总分小于它的节点。
若找到此节点,系统将待排序链表中取出的节点插入此节点前,作为其前驱。
否则,将取出的节点放在单链表l的尾部。
3)重复第二步,直到从待排序链表中取出的节点的指针域为NULL,即此节点为链表的尾部节点,排序完成。
2.2.6输出记录模块当把记录输出至文件时,调用FILE *fp;函数,将p指针所指节点中的各字段值,写入文件指针fp所指的文件。
当把记录输出至屏幕时,用户记录信息以表格的形式在屏幕上打印出来。
2.2.7函数功能描述●void delete_all(struct arr f4[])/*注销手机用户信息*/delete_all(])函数用于先在单链表l中找到满足条件的用户记录的节点,然后删除该节点。
●save()函数原型:void save()save()函数用于将单链表l中的数据写入磁盘中的数据文件。
●void read1(struct arr f6[]);函数原型:read1(;read1(struct arr f6[]);函数用于在单链表l中读出用户记录。
●find_message(struct arr f3[])find_message(struct arr f3[])函数用于菜单的查找。
函数用于查找用户的电话号码或姓名,从而找到该用户的信息。
●void input_message();input_message();函数用于用户输入信息。
●主函数main()整个手机号码管理系统控制部分,其详细说明可参考图二。
完成在上述系统设计后,即可着手进行系统实现的工作,开始程序代码的编写。
3、系统实现3.1 编码3.1.1 程序预处理包括加载头文件,定义结构体、常量和变量,并对它们进行初始化工作。
#include<stdio.h>/*主函数*/#include<string.h>#include<stdlib.h>int i,w,j=0;/*定义全局变量*/struct arr{char PhoneNumber[40];char name[40];float telephonefare;char address[40];int ok;int xinxi;}caller[100];void input_message();/*添加手机用户信息*/void find_message(struct arr f3[]); /*查找信息*/void delete_all(struct arr f4[]); /*注销信息*/void modify(struct arr f5[]); /*修改手机用户信息及缴费及挂失*/void read1(struct arr f6[]); /**/void save();main(){int a,z=1;/*int a为你要输入的数字*/do{printf("\t*************************************************************\n");printf("\t\t\t\t手机用户信息管理系统\n\n");printf("已有的客户人数:%d \n",j);printf("\t功能选择:\n\t\t\t1.添加手机用户信息\n\t\t\t2.查找手机用户信息\n\t\t\t3.注销\n\t\t\t4.手机缴费,信息修改,挂失,发信息\n\t\t\t5.保存信息\n\t\t\t6.读入用户信息\n\t\t\t0.退出\t\n");printf("\t*************************************************************\n");printf("\n\n\n请输入0,1,2,3,4,5,6选择:");scanf("%d",&a);switch (a){case 0: z=0;break;/*退出*/case 1: input_message();break;/*添加手机用户信息*/case 2: find_message(caller);break;/*查找手机用户信息*/case 3: delete_all(caller);break;/*删除手机用户信息*/case 4: modify(caller);break;/*修改手机用户信息*/case 5: write(caller);break;case 6: read1(caller);break;default:{printf("你的输入有误,请重新输入!!\n");z=1;}}system("cls");}while(z==1);}3.1.2 主函数main()main()函数主要实现了对整个程序的运行控制,以及相关功能模块的调用。