家谱管理系统数据结构_第1页
家谱管理系统数据结构_第2页
家谱管理系统数据结构_第3页
家谱管理系统数据结构_第4页
家谱管理系统数据结构_第5页
已阅读5页,还剩4页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#include#include#include#include#define MAXS 100#define Elemtype chartypedef struct BiTNodeint mark;int level;char name50;char birthday50;char addressMAXS;Elemtype data;struct BiTNode *lc,*rc;BiTNode,*BiTree;char nametemp50;/姓名char birthdaytemp50;/生日char addresstempMAXS;/地址char ch;int leveltemp;int

2、Nth;char searchdata50;char searchname50;int count;BiTree temp;BiTree CreateBiTree(FILE *fp);void PrintInfo(BiTree T);void PreOrderTS(BiTree T);void ShowNth(BiTree T);void SearchByName(BiTree T);void SearchByBirthday(BiTree T);void AddChild(BiTree T);void DeleteByName(BiTree T);void searchmenu();void

3、 menu();void insystem();void closefile();#includemy.hvoid SearchByName(BiTree T)/按照姓名查询,输出成员信息 if(T)if(T-lc) if(T-lc-rc) temp=T-lc-rc; while(temp) if(strcmp(temp-name,searchname)=0) count+; printf(n此人的信息为: n); PrintInfo(temp); printf(此人父兄的信息为: n); PrintInfo(T); if(temp-lc-rc) printf(此人孩子的信息为: n); te

4、mp=temp-lc-rc; while(temp) PrintInfo(temp); temp=temp-rc; return; else temp=temp-rc; SearchByName(T-lc);SearchByName(T-rc);elseprintf(请先建立家庭关系n);return;void SearchByBirthday(BiTree T)/按照出生日期查询成员名单 if(T) if(strcmp(T-birthday,searchdata)=0) PrintInfo(T); count+; void AddChild(BiTree T)/某成员添加孩子 if(T) i

5、f(strcmp(T-name,searchname)=0) count+; temp=(BiTree)malloc(sizeof(BiTNode); printf(请输入添加孩子的姓名:n); scanf(%s,temp-name); printf(请输入添加孩子的出生年月:(格式形如: 2010-1-1)n); scanf(%s,temp-birthday); printf(请输入添加孩子的家庭住址:n); scanf(%s,temp-address); temp-level=T-level+1; temp-rc=T-lc-rc; temp-lc=NULL; T-lc-rc=temp; p

6、rintf(孩子添加成功n); return; AddChild(T-lc);AddChild(T-rc);elseprintf(请先建立家庭关系n);return;void DeleteByName(BiTree T)/删除某成员(若其还有后代,则一并删除)if(T)if(strcmp(T-name,searchname)=0) count+; T=NULL; return; DeleteByName(T-lc);DeleteByName(T-rc);BiTree CreateBiTree(FILE *fp) if(!feof(fp)BiTree T; T=(BiTree)malloc(si

7、zeof(BiTNode); fscanf(fp,%s %s %sn,nametemp,birthdaytemp,addresstemp); fscanf(fp,%d,&leveltemp); if(strcmp(nametemp,n)=0)&(strcmp(birthdaytemp,n)=0)&(strcmp(addresstemp,n)=0) T=NULL; return T; else strcpy(T-name,nametemp); strcpy(T-birthday,birthdaytemp); strcpy(T-address,addresstemp);T-level=levelt

8、emp+1;printf(读取成功n); T-lc=CreateBiTree(fp); T-rc=CreateBiTree(fp); return T; elsereturn NULL;#includemy.hvoid main()BiTree T;int choice;FILE *fp;T=NULL;fp=fopen(F:family.txt,r);insystem();while(1)system(cls);menu();printf(请根据菜单进行选择所需操作:);while(scanf(%d,&choice)!=1)fflush(stdin);printf(n-输入错误-nn);pri

9、ntf(请重新输入正确选择:);fflush(stdin);switch(choice)case 1: T=CreateBiTree(fp); system(pause);break;case 2:count=0;printf(请输入要添加孩子父母的姓名:n);scanf(%s,searchname);AddChild(T);if(count=0)printf(没有这个人n);system(pause);break;case 3: count=0; printf(请输入要删除成员的姓名: ); scanf(%s,searchname); DeleteByName(T); if(count=0)

10、 printf(没有这个人n);system(pause);break;case 4: searchmenu(); printf(请输入选择:n);system(pause);break;case 5:PreOrderTS(T);system(pause);break;case 6:closefile();case 7:printf(请输入需要查询第几代人: ); count=0; scanf(%d,&Nth); ShowNth(T); if(count=0) printf(第%d代尚未有人。n,Nth);system(pause);break;case 8:printf(请输入要查询人的姓名

11、: ); scanf(%s,searchname); if(strcmp(T-name,searchname)=0) printf(此人为家谱的祖先,其信息为:n); printf(%-10s%-10s%-10sn,T-name,T-birthday,T-address);printf(他兄弟的信息为: n); printf(%-10s%-10s%-10s%n,T-lc-name,T-lc-birthday,T-lc-address); temp = T-lc; if(temp-rc) printf(他孩子的信息为:n); temp = temp-rc; while(temp) printf(

12、%-10s%-10s%-10sn,temp-name,temp-birthday,temp-address); temp = temp-rc; else count=0; SearchByName(T); if(count=0) printf(对不起,不能检测这个人的信息n); system(pause);break;case 9: printf(请输入要查询人的生日:); count=0; scanf(%s,searchdata); SearchByBirthday(T); if(count=0) printf(%s 没有人过生日。n,searchdata);system(pause);br

13、eak;default:printf(n-输入错误-n);break;printf(n-n);printf(按任意键继续!);getch();#includemy.hvoid insystem()int flag1,flag2;char name20=student;char password10=111111;char person20;char a10;printf(tt * 欢迎进入家谱管理系统!*nn);printf(ttt 用户登录 nn);printf(tttt用户名:);gets(person);flag1=strcmp(person,name);printf(tttt密码:);

14、gets(a);flag2=strcmp(password,a);if(flag1=0&flag2=0)printf(tttt 登录成功!nn);elseprintf(ttt 用户名或密码错误!nn);printf(ttt 您无权使用!nn);exit(0);#includemy.hvoid menu()printf(*欢迎使用家谱管理系统*nn); printf(tt1建立家族关系(并保存)n);printf(tt2添加家族成员n);printf(tt3删除家族成员n);printf(tt4查询家族成员n);printf(tt5显示家族关系n);printf(tt6退出系统n);printf(tt*n);void searchmenu()printf(tt7按姓名查询n);printf(tt8按出生日期查询n);void PrintInfo(BiTree T) printf(%10s %10s %10sn,T-name,T-birthday,T-address);void PreOrderTS

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论