家谱管理系统数据结构

上传人:大米 文档编号:492262177 上传时间:2024-02-09 格式:DOCX 页数:9 大小:15.21KB
返回 下载 相关 举报
家谱管理系统数据结构_第1页
第1页 / 共9页
家谱管理系统数据结构_第2页
第2页 / 共9页
家谱管理系统数据结构_第3页
第3页 / 共9页
家谱管理系统数据结构_第4页
第4页 / 共9页
家谱管理系统数据结构_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《家谱管理系统数据结构》由会员分享,可在线阅读,更多相关《家谱管理系统数据结构(9页珍藏版)》请在金锄头文库上搜索。

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;

2、int 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();

3、void 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);temp=temp-lc-r

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

5、name)=0)count+;temp=(BiTree)malloc(sizeof(BiTNode);printf(请输入添加孩子的姓名:n);scanf(%s,temp-name);printf(请输入添加孩子的出生年月:(格式形如:2010-l-l)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;printf(孩子添加成功n);return;AddChild(T-

6、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(sizeof(BiTNode);fscanf(fp,%s %s %sn,na

7、metemp,birthdaytemp,addresstemp); fscanf(fp,%d,&leveltemp);if(strcmp(nametemp,n)=0)&(strcmp(birthdaytemp,n)=0)&(strcmp(addresstemp,n)=0) T=NULL; return T;elsestrcpy(T-name,nametemp);strcpy(T-birthday,birthdaytemp); strcpy(T-address,addresstemp);T-level=leveltemp+1; printf(读取成功 n);T-lc=CreateBiTree(f

8、p);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);printf(请重新输入正确选择:); fflush(stdin); switch(cho

9、ice)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)printf(没有这个人n);system(pause);break;case 4:sear

10、chmenu();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(请输入要查询人的姓名:);scanf(%s,searchname);if(strcmp(T-name,search

11、name)=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(%-10s%-10s%-10sn,temp-name,temp-birthday,temp-address);

12、temp = temp-rc;elsecount=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);break; default: printf(n-输入错误-n);break;printf(nn);printf(”按任意键继续!

13、”); 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 密码:”); gets(a); flag2=strcmp(password,a);if(flagl=0&flag2=0)printf(tttt 登录成功! nn);elseprintf(ttt用户名或密码错误! nn);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 建筑资料

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