收藏 分销(赏)

通讯录管理系统设计思路:幻灯片.ppt

上传人:人****来 文档编号:8172458 上传时间:2025-02-06 格式:PPT 页数:19 大小:374KB 下载积分:8 金币
下载 相关
通讯录管理系统设计思路:幻灯片.ppt_第1页
第1页 / 共19页
通讯录管理系统设计思路:幻灯片.ppt_第2页
第2页 / 共19页


点击查看更多>>
资源描述
,*,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,通讯录管理系统设计思路:,首先对于通讯录中的各成员包含的信息序号、姓名、,TEL,、住址定义一个结构体。,对与通讯录重要实现的各种操作可以使用一张菜单清单进行任务选择使用,switch,语句执行,实验中定义一个结构体数组来储存成员,进行成员的插入,信息修改,删除操作,实验的数据输入包括选择功能数字,成员的联系信息,查找的成员姓名;输出成员的信息。,实验采用文件对学生数据的保存,提高操作效率,1,结构体模型,姓名,char name【】,结构体,Data Type,电话号码,char phone【】,住址,char addr【】,0-,选择进行建立一个通讯录,1-,列出成员的信息,2-,查找成员的信息,功能清单,3-,删除一个成员,4-,增加新的成员,5-,通讯录排序,6-,实现通讯录中的文件复制,7-,退出系统,2,实验主要用到的函数:,1,:,通讯建立函数,Enter(),2,:成员信息列出函数,List(),3:,成员删除函数,Delete(),4,:成员新增函数,Add(),5,:成员信息排序函数,Sort(),6,:文件复制函数,Copy(),7:,退出系统函数,Quit(),3,Main,函数的设置,void main(),int m;,do,printf(*MENU*n);,printf(0-Enter recordn);,printf(1-List the filen);,printf(2-Search record on namen);,printf(3-Delete a recordn);,printf(4-Add recordn);,printf(5-Sort to make new filen);,printf(6-copy the file to new filen);,printf(7-Quitn);,printf(*n);,4,printf(nEnter your choice(07):n);,scanf(%d,switch(m),case 0:enter();break;,case 1:list();break;,case 2:search();break;,case 3:Delete();break;,case 4:add();break;,case 5:sort();break;,case 6:copy();break;,case 7:exit(0);,default:printf(input error.n);break;,while(m!=7);,5,void enter(void)/,进入工作,初始化通讯录信息,FILE*fp;,int i,j;,for(i=0;iSIZE;i+)/,输入成员信息,printf(nInput score of student%d:n,i+1);,printf(NO.:);,scanf(%s,stui.num);,printf(name:);,scanf(%s,stui.name);,printf(phone:);,scanf(%s,stui.phone);,printf(%s,stui.addr);,if(fp=fopen(“stu.dat”,“wb”)=NULL)/,新建一个,stu.dat,文件储存信息,printf(Can not open the file.n);,exit(0);,for(i=0;iSIZE;i+)/,将信息写入文件中,if(fwrite(&stui,LEN,1,fp)!=1),printf(file write errorn);,fclose(fp);,6,void list(void)/,输出学生信息,FILE*fp;,int i,n;,if(fp=fopen(“stu.dat”,“rb”)=NULL)/,打开建立好的文件,stu.dat,printf(Can not open the file.n);,exit(0);,for(i=0;fread(/,统计能读取的数据的个数,i,n=i;/,将读取的数据个数赋予,n,for(i=0;in;i+)/,学生信息块都读取到结构体中,fread(,fclose(fp);,printf(*n);,printf(No.tnametphonen);,printf(*n);,for(i=0;in;i+),printf(%st%st%st%sn,stui.num,stui.name,stui.phone,stui.addr);,printf(*n);,7,void search(void)/,查找学生信息,int b;,do,printf(*MENU*n);,printf(8-search by number.n);,printf(9-search by name.n);,printf(10-exit.n);,printf(*n);,printf(“nEnter your choice(810):n”);/,查找的方法选择,scanf(“%d”,/,按名字或学号,switch(b),case 8:sea_num();break;,case 9:sea_name();break;,case 10:break;,default:printf(input error.n);break;,while(b!=10);,printf(exit.n);,8,void sea_num(void)/,以序号进行查找,FILE*fp;,int i,flag,n;,char num10;,if(fp=fopen(stu.dat,rb)=NULL)/,以二进制读的一个方式打开一个文件,printf(Can not open the file.n);,exit(0);,for(i=0;fread(/,统计文件中可读的数据个数,i,n=i;,for(i=0;in;i+),fread(/,查找前首先将数据全部提取出来,放到结构体中,fclose(fp);,printf(nInput num:);,scanf(%s,num);,for(flag=0,i=0;in;i+),if(strcmp(num,stui.num)=0)/,判断是否查找到信息,printf(*n);,printf(The record you search isn:);,9,printf(No.tnametphonen);,printf(%st%st%st%sn,stui.num,stui.name,stui.phone,stui.addr);,flag=1;,printf(*n);,if(flag!=1)printf(Not found the recordn);,10,void sea_name(void)/,按名字查找成员信息,FILE*fp;,int i,j,flag,n;,char name10;,if(fp=fopen(“stu.dat”,“rb”)=NULL)/,打开文件,stu.dat,printf(Can not open the file.n);,exit(0);,for(i=0;fread(,n=i;,for(i=0;in;i+),fread(,fclose(fp);,printf(nInput name:);,scanf(%s,name);,for(flag=0,i=0;in;i+),if(strcmp(name,stui.name)=0),printf(*n);,printf(The record you search isn:);,printf(No.tnametphonen);,11,printf(%st%st%st%sn,stui.num,stui.name,stui.phone,stui.addr);,flag=1;,printf(*n);,if(flag!=1)printf(Not found the recordn);,12,void sort(void)/,通讯录排序,FILE*fp;,int i,j,n;,struct student temp;,if(fp=fopen(stu.dat,rb)=NULL)/,二进制方式打开一文件,printf(Can not open the file.n);,exit(0);,for(i=0;fread(/,统计能读取的学生信息个数,i,n=i;,for(i=0;in;i+),fread(/,学生信息读取到结构体中,fclose(fp);,for(i=0;in;i+),for(j=i+1;j0),temp=stui;,stui=stuj;,stuj=temp;,13,printf(*n);,printf(No.tnametphonen);,for(i=0;in;i+),printf(%st%st%stn,stui.num,stui.name,stui.phone,stui.addr);,fp=fopen(stu.dat,wb);/,新创一个文件将排好序的文件写入新建的文件中,for(i=0;in;i+),fwrite(,printf(*n);,fclose(fp);,14,void add(void)/,追加新的学生信息,int i,j,n;,FILE*fp;,struct student s;,printf(NO.:);,scanf(%s,s.num);,printf(name:);,scanf(%s,s.name);,printf(phone:);,scanf(%s,s.phone);,printf(address:);,scanf(%s,s.addr);,if(fp=fopen(stu.dat,rb)=NULL),printf(nCan not open the file.n);,exit(0);,for(i=0;fread(,n=i;,for(i=0;in;i+),fread(,15,fclose(fp);,strcpy(stun.name,s.name);/,将新增人的信息复制到结构体数组中,strcpy(stun.num,s.num);,strcpy(stun.phone,s.phone);,strcpy(stun.addr,s.addr);,n=n+1;/n,记录成员的个数,新增时时,n,加一,printf(nNow the new list is:n);,printf(*n);,printf(No.tnametphonen);,printf(*n);,fp=fopen(stu.dat,wb);,for(i=0;in;i+),fwrite(/,将追加后的学生信息全部写入文件,printf(%st%st%st%sn,stui.num,stui.name,stui.phone,stui.addr);,fclose(fp);,16,void Delete(void)/,删除某人的信息,FILE*fp;,int i,j,n,flag;,char name10;,if(fp=fopen(“stu.dat”,“rb”)=NULL)/,打开储存文件,stu.dat,printf(nCan not open the file.n);,exit(0);,for(i=0;fread(,n=i;,printf(“nInput name deleted:”);/,输入待删除人的名字,scanf(%s,name);,for(flag=1,i=0;in;i+),if(strcmp(name,stui.name)=0)/,如果找到待删人的名字删除此人信息,for(j=i;jn-1;j+),strcpy(stuj.name,stuj+1.name);,strcpy(stuj.num,stuj+1.num);,strcpy(stuj.phone,stuj+1.phone);,strcpy(stun.addr,stuj+1.addr);,flag=0;,17,n=n-1;/,储存成员个数的变量,n,减一,printf(nNow the list is:n?);,fp=fopen(“stu.dat”,“wb”);/,追加的方式打开储存文件,stu.dat,for(i=0;in;i+),fwrite(/,将删除后的联系人信息从新写入文件中保存,fclose(fp);,fp=fopen(stu.dat,rb);,printf(*n);,printf(No.tnametphonen);,for(i=0;fread(i+)/,输出个联系人的信息,printf(%st%st%stn,stui.num,stui.name,stui.phone,stui.addr);,printf(*n);,if(flag),printf(nNot found the recordn);,fclose(fp);,18,void copy(void)/,文件复制,FILE*in,*out;/,定义两个文件指针,fp,if(in=fopen(“stu.dat”,“rb”)=NULL)/in,指向需要复制的文件,printf(Can not open the infile.n);,exit(0);,if(out=fopen(“stu2.dat”,“wb”)=NULL)/out,指向复制文件,printf(Can not open the outfile.n);,exit(0);,while(!feof(in)fputc(fgetc(in),out);/,学生信信息复制,printf(copy nown);,fclose(in);,fclose(out);,19,
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服