1、家谱图程序家谱系统程序宁波大红鹰学院#include#include#includetypedef struct TreeNode char name20; char sex10; char spousename20; TreeNode *brother; TreeNode *child; TreeNode *parent;TreeNode,*TreeNodeP;TreeNodeP treehead;void InterFace();TreeNodeP Inite();void CreateFamily(TreeNodeP tree);TreeNodeP AddBrother(TreeNode
2、P tree,TreeNodeP bother);TreeNodeP AddChild(TreeNodeP tree,TreeNodeP parents);TreeNodeP FindNode(TreeNodeP tree,char *tt);void FindPeople(TreeNodeP tree);void PrintfFamily(TreeNodeP tree);void PrintfNode(TreeNodeP tree);void PrintfAllChildren(TreeNodeP tree);void AddMember(TreeNodeP tree);void Modif
3、ication(TreeNodeP tree);void Help();void InterFace() int choice; printf(n-菜单-n); printf( 1.创建一个家谱 n); printf( 2.输出家谱中所有人 n); printf( 3.查找某个人的信息 n); printf( 4.查找某人所有孩子 n); printf( 5.在家谱中添加成员 n); printf( 6.在家谱中修改资料 n); printf( 7.与某人断绝关系 n); printf( 8.系统使用帮助 n); printf( 9.退出系统 n); printf(-n); printf(-n
4、); printf(输入你的选择:); scanf(%d,&choice); while(choice8) printf(请输入范围内的数字:); scanf(%d,&choice); switch(choice) case 1:CreateFamily(treehead);break; case 2:PrintfFamily(treehead);break; case 3:FindPeople(treehead);break; case 4:PrintfAllChildren(treehead);break; case 5:AddMember(treehead);break; case 6:
5、Modification(treehead);break; case 7:DelPerson(treehead);break; case 8:Help();break; case 9:exit(0);break; TreeNodeP Inite() TreeNodeP p; char *s=sdf; p=(TreeNodeP)malloc(sizeof(TreeNode); printf(正在初始化一个家谱。n); printf(n请输入家谱顶端祖先的姓名:); scanf(%s,p-name); strcpy(p-sex,man); printf(n请输入顶端祖先配偶姓名:); scanf(
6、%s,p-spousename); p-child=NULL; p-brother=NULL; p-parent=NULL; system(cls); return p;void CreateFamily(TreeNodeP tree) char flag; fflush(stdin); printf(nt给%s添加后代.,tree-name); tree-child=AddChild(tree-child,tree); TreeNodeP AddBrother(TreeNodeP tree,TreeNodeP brother) char flag; tree=(TreeNodeP)mallo
7、c(sizeof(TreeNode); tree-parent=brother-parent; printf(n请输入%s弟弟或妹妹的姓名:,brother-name); scanf(%s,tree-name); printf(n请输入%s的性别F/M:,tree-name); scanf(%s,tree-sex); fflush(stdin); printf(n请输入%s的是否有配偶Y/N:,tree-name); scanf(%c,&flag); if(flag=y|flag=Y) printf(n请输入%s的配偶姓名:,tree-name); scanf(%s,tree-spousena
8、me); fflush(stdin); printf(n请输入%s是否添加孩子Y/N:,tree-name); scanf(%c,&flag); if(flag=y|flag=Y) tree-child=AddChild(tree-child,tree); else tree-child=NULL; else strcpy(tree-spousename,); tree-child=NULL; fflush(stdin); printf(n请输入%s是否添加弟弟妹妹Y/N:,tree-name); scanf(%c,&flag); if(flag=y|flag=Y) tree-brother=
9、AddBrother(tree-brother,tree); else tree-brother=NULL; return tree;TreeNodeP AddChild(TreeNodeP tree,TreeNodeP parents) char flag; tree=(TreeNodeP)malloc(sizeof(TreeNode); tree-parent=parents; printf(n请输入%s第一个孩子的姓名:,parents-name); scanf(%s,tree-name); printf(n请输入%s的性别F/M:,tree-name); scanf(%s,tree-s
10、ex); fflush(stdin); printf(n请输入%s的是否有配偶Y/N:,tree-name); scanf(%c,&flag); if(flag=y|flag=Y) printf(n请输入%s的配偶姓名:,tree-name); scanf(%s,tree-spousename); fflush(stdin); printf(n请输入%s是否添加孩子Y/N:,tree-name); scanf(%c,&flag); if(flag=y|flag=Y) tree-child=AddChild(tree-child,tree); else tree-child=NULL; else
11、 strcpy(tree-spousename,); tree-child=NULL; fflush(stdin); printf(n请输入%s是否添加弟弟妹妹Y/N:,tree-name); scanf(%c,&flag); if(flag=y|flag=Y) tree-brother=AddBrother(tree-brother,tree); else tree-brother=NULL; return tree;void PrintfNode(TreeNodeP tree) if(tree!=NULL) printf(n孩子:%s 性别:%s ,tree-name,tree-sex);
12、 if(strcmp(tree-spousename,)!=0) printf(配偶:%s,tree-spousename); else printf(配偶:未婚); if(tree-brother!=NULL) PrintfNode(tree-brother); printf(n-); if(tree-child!=NULL) PrintfFamily(tree); void PrintfFamily(TreeNodeP tree) if(tree!=NULL) printf(n姓名:%s ,tree-name); if(strcmp(tree-spousename,)!=0) printf
13、(n配偶:%s,tree-spousename); else printf(n配偶:未婚); if(tree-parent!=NULL) printf(n此人父母:%s和%s,tree-parent-name,tree-parent-spousename); PrintfNode(tree-child); TreeNodeP FindNode(TreeNodeP tree,char *tt) TreeNodeP p=NULL; if(tree!=NULL) if(strcmp(tree-name,tt)=0|strcmp(tree-spousename,tt)=0)p=tree; else p
14、=FindNode(tree-child,tt); if(p!=NULL)return p; else p=FindNode(tree-brother,tt); if(p!=NULL)return p; else return NULL;void FindPeople(TreeNodeP tree) char tt20; TreeNodeP T; printf(n请输入要查找的人的姓名:); scanf(%s,tt); T=FindNode(tree,tt); if(T!=NULL) printf(n姓名:%s,T-name); printf(n性别:%s,T-sex); if(strcmp(
15、T-spousename,)!=0) printf(n配偶:%s,T-spousename); else printf(n配偶:未婚!); else printf(查不到此人!); void PrintfAllChildren(TreeNodeP tree) char tt20; TreeNodeP T; printf(n请输入:); scanf(%s,tt); T=FindNode(tree,tt); if(T!=NULL) printf(n姓名:%s,T-name); printf(n性别:%s,T-sex); if(strcmp(T-spousename,)!=0) printf(n配偶
16、:%s,T-spousename); else printf(n配偶:未婚!); if(T=T-child)!=NULL) printf(n孩子:%s 性别:%s ,T-name,T-sex); if(strcmp(T-spousename,)!=0) printf(配偶:%s,T-spousename); else printf(配偶:未婚); while(T=T-brother)!=NULL) printf(n孩子:%s 性别:%s ,T-name,T-sex); if(strcmp(T-spousename,)!=0) printf(配偶:%s,T-spousename); else p
17、rintf(配偶:未婚); else printf(查不到此人!); void AddMember(TreeNodeP tree) char tt20,choice; TreeNodeP T; printf(n请输入在哪儿添加姓名:); scanf(%s,tt); fflush(stdin); T=FindNode(tree,tt); if(T!=NULL) printf(n姓名:%s,T-name); printf(n性别:%s,T-sex); if(strcmp(T-spousename,)!=0) printf(n配偶:%s,T-spousename); else printf(n配偶:
18、未婚!); else printf(n没有此人!); return; printf(n添加成员与此人关系-); printf(nt1.父子(女)关系); printf(nt2.兄弟(姐妹)关系); printf(n-); printf(n请选择:); scanf(%d,&choice); while(choice2) printf(请输入范围内的数字:); scanf(%d,&choice); if(choice = 1) if(strcmp(T-spousename,)!=0) if(T-child!=NULL) T=T-child; while(T-brother!=NULL) T=T-b
19、rother; T-brother=AddBrother(T-brother,T); else T-child=AddChild(T-child,T); else printf(n此人未婚!); else if(choice = 2) T-brother = AddBrother(T-brother,T); void Modification(TreeNodeP tree) char tt20,flag; TreeNodeP T; printf(n请输入要修改的人的姓名:); scanf(%s,tt); T=FindNode(tree,tt); if(T!=NULL) printf(n修改前-
20、); printf(n姓名:%s,T-name); printf(n性别:%s,T-sex); if(strcmp(T-spousename,)!=0) printf(n配偶:%s,T-spousename); else printf(n配偶:未婚!); else printf(n没有此人!); return; printf(n修改后-); printf(n姓名:); scanf(%s,T-name); printf(n性别F/M:); scanf(%s,T-sex); fflush(stdin); printf(n请输入该人是否有配偶(Y/N):); scanf(%c,&flag); if(
21、flag=y|flag=Y) printf(n配偶:); scanf(%s,T-spousename); else strcpy(T-spousename,); void DelPerson(treehead) void Help() system(cls); printf(n本系统使用指南:); printf(n-n); printf(n1、使用本系统前,请仔细阅读本系统使用指南。); printf(n2、严格遵守本系统使用规则。); printf(n3、本系统使用规则:); printf(n 根据常识,在家谱中重名的情况很少,); printf(n 所以我们输入的姓名一般也不要重名。如); printf(n 果有重名情况,则可以在姓名中做标记再输入。); printf(n 本系统没有考虑以下几种情况:); printf(n 1.再婚(夫妻一方去世)。); printf(n 2.离异(若有孩子,孩子跟外性配偶)。); printf(n 3.重名(若有重名,可做标记存储)); printf(n-nn);int main() treehead=Inite(); while(1) InterFace();
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1