完整word版家谱管理系统的源代码_第1页
完整word版家谱管理系统的源代码_第2页
完整word版家谱管理系统的源代码_第3页
完整word版家谱管理系统的源代码_第4页
完整word版家谱管理系统的源代码_第5页
已阅读5页,还剩32页未读 继续免费阅读

下载本文档

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

文档简介

1、#include#include#include#include struct perint data;char name20; char brith20; char marry;char address20; char live;char dietime20; char parent20; int generation;int child10; int numberchild;per()for(int i=0;i20;i+) namei=0;for(i=0;i20;i+)brithi=0;for(i=0;i20;i+) addressi=0;for(i=0;i20;i+) dietimei=

2、0;for(i=0;i10;i+) childi=0;for(i=0;i20;i+) parenti=0;live=0; marry=0; data=-10; generation=0;numberchild=0;void setupinfo(per person);void display(per person,int&);void displayhome(per person,int&); void displayinfo(per person,int&);void namesearch(per person,int&);void birtfdaysearch(per person,int

3、&); void addchild(per person,int&);void editmember(per person,int&);void sortbirthday(per person,int&);void main()per person36;int count=0;fstreaminputFile(person.txt,ios:in|ios:out|ios:binar y);if(!inputFile)cout 文件不存在 !endl; exit(0); inputFile.read(char*)&personcount,sizeof (personcount);/ 从文件中读取指

4、定大小的 字节函数read(),读取字节函数while(!inputFile.eof()/当文件没有读取完毕,进行循环if(0!=0)/ 当 名 字 不为空时count+; / 统计人数inputFile.read(char*)(person+count),sizeof(*person);inputFile.close();/ 关闭文件if(count1) /如果家谱图里面没人cout 家谱不存在 ,请你 建立一个家谱 !endl;setupinfo(person); display(person,count);void setupinfo(per person

5、36)/ 创建信息int i,j,k;fstream outputfile(person.txt,ios:in|ios:out|ios:bina ry|ios:app); / 打开文件for(i=0;i5;i+)cout 姓名 : ;cin.getline(,20);coutH.生日 (日期样式为 xxxx/xx/xx) :cin.getline(personi.brith,20);coutpersoni.marry;while(toupper(personi.marry)!=Y&toup per(personi.marry)!=N)你输入错误 ,请你重新 cout 输

6、入 !endl;coutpersoni.marry; cin.ignore();cout 地址cin.getline(personi.address,20);coutpersoni.live;/ 是否死亡while(toupper(personi.live)!=Y&toupper(personi.live)!=N)你输入错误 ,请你重新 cout 输入 !endl;coutpersoni.live; cin.ignore();if(toupper(personi.live)=N)cout 死 亡 日 期 (日 期 样 式 为 xxxx/xx/xx) :;cin.getline(personi.

7、dietime,20);/ 输 入死亡日期coutpersoni.generation; cin.ignore();if(personi.generation!=1)/ 不是第代cout 他(她)的父亲 : ; cin.getline(personi.parent,20);/cin.getline 是读取字符串函数 20 是读取 字符串的个数coutendl;for(j=0;ji;j+)if(personj.generation=1) personj.data=-1;/*for(j=0;ji;j+)for(k=0;ki;k+)if(strcmp(personj.parent,personk.n

8、ame)= =0) /比较 2 个字符串是否相同,实质是找 某个人的父亲personj.data=k;for(j=0;ji;j+)for(k=0;ki;k+)if(strcmp(personj.parent,)=0)personk.childpersonk.numberchild=j;personk.numberchild+; / 找某个人的孩子for(j=0;ji;j+)outputfile.write(char*)(person+j),sizeof(*person); / 写文件outputfile.close(); /关闭文件夹system(cls);void d

9、isplay(per person36,int &n1) int choice;while(1)/循环式一直进行的coutendlendlendl;couttt 家族关系查询系统 endl;couttt1. 显示家谱 endl; couttt2. 显示第 n 代人的所有信息 endl; couttt3.的信息 endl;couttt4.员名单 endl;couttt5.endl;couttt6.endl;couttt7.按照姓名查询某成员按照出生日期查询成某成员添加孩子修改某成员信息按生日日期对家谱中的所有人进行排序 endl;退出系统 endl;输入选择:couttt8.couttt end

10、l;couttt数choice;while(choice!=1&choice!=2&choice!=3&choi ce!=4&choice!=5&choice!=6&choice!= 7&choice!=8)coutyou enter wrong!endl; coutplease enter again!choice;/ 跳过一个字符 ,cin.ignore(1,n);含义是忽略一行system(cls);switch(choice)case 1: displayhome(person,n1); break; case 2: displayinfo(person,n1);break;case

11、3: namesearch(person,n1);casebreak;4: birtfdaysearch(person,n1);break;case 5: addchild(person,n1); break; case 6: editmember(person,n1); break; case 7: sortbirthday(person,n1); break;displayhome(per person36,int &n2)case 8: exit(0);void/调用函数的参数 传递的是一个参数地址int i,j,max;char again;coutendlendl;for(i=0;i

12、n2-1;i+)max=personi.generation;for(j=i+1;jn2;j+)if(personi.generationpersonj.generation )max=personj.generation;/找出最大的代数for(i=1;i=max;i+)cout第i代的成员有:;for(j=0;jn2;j+)/Hif(personj.generation=i) 输出每一代的人coutendl;coutendlendl;coutagain;if(toupper(again)=Y) / 就是判断输入 得是否为 y 或 Ysystem(cls);r

13、eturn;if(toupper(again)=N)exit(0); /终止程序的执行 void displayinfo(per person36,int &n2) /显示代数int i,gen,j=0;char again;coutendlendl;coutgen;coutendl;/ 换行for(i=0;in2;i+)if(personi.generation!=gen) j+;if(j=n2)/判断是否找到cout 你 要 查 的 代 数 还 没 有!!vve ndlvve ndl;for(i=0;in2;i+)if(personi.generation=gen)姓名coutvvvvpe

14、vvendl生日期第几代vv出vvpersoni.brithvv vvpersoni.generationvvendlvv 婚否 : vvpersoni.marryvv地址:vvpersoni.addressvvendlvv是 否 健 在vvpersoni.livevvendl;if(personi.live=N|personi.live=n) cout 死 亡 日 期 personi.dietimeendl; coutendlendl;coutagain;if(toupper(again)=Y)system(cls);return;if(toupper(again)=N)

15、exit(0);void namesearch(per person36,int &n2)int i,j=0,k;char again,name20;coutvvendlvvendl;coutvv 请你输入你想要查询的人的 姓名 : ;cin.getline(name,20);for(i=0;in2;i+)if(strcmp(,name)!=0)j+;coutendlendl;if(j=n2)cout 你 要 查 询 的 人 没有!!vve ndlvve ndl;for(i=0;in2;i+)if(strcmp(,name)=0)姓名coutvv

16、vvendl生日期第几代vv出vvpersoni.brithvv vvpersoni.generationvvendlvv 婚否 : vvpersoni.marryvv地址:vvpersoni.addressvvendlvv是 否 健 在personi.liveendl;if(personi.live=N|personi.live=n) cout 死 亡 日 期 personi.dietimeendl; coutendlendl;if(personi.generation=1)cout 他是这个家的根, 没有 父亲 !endlendl;else他 (她)父亲的信息

17、:coutendl;姓名endl日期cout出生personpersoni.data.brith 第 几 代personpersoni.data.generationendl 婚 否personpersoni.data.marryvv地址 :vvpersonpersoni.data.addressvvendlvv是 否 健 在 :vvpersonpersoni.data.livevvendl;if(personpersoni.data.live=N|personpersoni.data.live=n)cout 死 亡 日 期personperson

18、i.data.dietimeendl;coutendlendl;if(personi.numberchild=0)cout 他 没 有 孩子!!vve ndlvve ndl;elsecoutvv他 有vvpersoni.numberchildvv 个孩子 ,他们的 信息 :vvendlvvendl;for(k=0;kpersoni.numberchild;k+)cout 姓 名 endl 日期出生personpersoni.childk.brith 第 几 代 personpersoni.childk.generationen dl婚 否 :p

19、ersonpersoni.childk.marry 地 址 :personpersoni.childk.addresse ndl是否健在personpersoni.childk.live;if(personpersoni.childk.live=N|personpersoni.childk.live=n)cout 死 亡 日 期personpersoni.childk.dietimeendl; coutendlendl;coutagain;if(toupper(again)=Y)system(cls);return;if(toupper(again)=N)exit(0);void birtfd

20、aysearch(per person36,int &n2)char begbir20,endbir20,again;int i,flag=0;coutendlendl;cout 请你输入两个时间,格式为 */*/*!endl;cout起始时间是 : ;cin.getline(begbir,20);cout终止时间是 : ;cin.getline(endbir,20);coutendlendl;for(i=0;i=0&strcmp(personi.brith,endbir)=0)姓名;生日coutpersoni.brith;flag=1;coutendl;cou

21、tendlendl;if(flag=0)cout 在这段时间内没有人 生日 !endlendl;coutagain;if(toupper(again)=Y)system(cls);return;if(toupper(again)=N)exit(0);void addchild(per person36,int &n2) int i;char again;fstreamfile(person.txt,ios:in|ios:out|ios:binary|ios: app);coutendlendl;cout 请 输 入 孩 子 的 信 息!vve ndlvve ndlvve ndl;cout 姓名

22、 : ;cin.getline(,20);coutH.生日 (日期样式为 xxxx/xx/xx) :cin.getline(personn2.brith,20);coutpersonn2.marry;while(toupper(personn2.marry)!=Y&to upper(personn2.marry)!=N)你输入错误 , 请你重新 cout 输入 !endl;coutpersonn2.marry;cin.ignore();cout 地址 : ;cin.getline(personn2.address,20);coutpersonn2.live;while

23、(toupper(personn2.live)!=Y&toup per(personn2.live)!=N)你输入错误 , 请你重新cout输入 !endl;coutpersonn2.live;cin.ignore();if(toupper(personn2.live)=N)cout 死 亡 日 期 ( 日 期 样 式 为 xxxx/xx/xx) :;cin.getline(personn2.dietime,20);coutpersonn2.generation; cin.ignore();if(personn2.generation!=1)cout 他(她)的父亲 : ; cin.getli

24、ne(personn2.parent,20);coutendl;for(i=0;in2;i+)if(strcmp(personn2.parent,)=0)personn2.data=i;break;file.write(char*)&personn2,sizeof(personn2);file.close();file.open(person.txt,ios:in|ios:out|ios:bin ary);file.seekp(i*sizeof(per),ios:beg); personi.childpersoni.numberchild=n2; personi.num

25、berchild+; file.write(char*)&personi,sizeof(per); file.close();n2+;coutagain;if(toupper(again)=Y)system(cls); return; if(toupper(again)=N) exit(0);void editmember(per person36,int &n2)int i,flag=0,choice;char name20,again;fstreamfile(person.txt,ios:in|ios:out|ios:binary);coutendlendl;cout 请你输入你想修改的成

26、员的 名字 : ;cin.getline(name,20);coutendlendl;for(i=0;in2;i+)if(strcmp(,name)=0) flag=1; break;中没有这个 if(flag=0) cout 家 谱人!vve ndlvve ndlvve ndl;if(flag=1) coutvvtt 请 你 选 择 你 要 修 改 的 项!vve ndl;姓名 endl;地址 endl;婚否 endl;生日 endl; 是否死亡 endl;coutvvtt 1. coutvvtt 2.coutvvtt 3.coutvvtt 4.coutvvtt 5.

27、死亡日期 choice;while (choice!=1&choice!=2&choice!=3&choi ce!=4&choice!=5&choice!=6)coutyou enter wrong!endl; coutplease enter again!choice;cin.ignore(1,n);switch(choice)case 1: coutendl 请你输入新名字cin.getline(,20);file.seekp(i*sizeof(per),ios:beg);.H./ file.write(char*)&personi,sizeof(per);break;case 2: coutendl 请输入新 的地址 : ;cin.getline(personi.address,20); file.seekp(i*sizeof(per),ios:beg);/file.write(char*)&personi,sizeof(per); break;case 3: coutendlpersoni.marry;file.seekp(i*si

温馨提示

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

评论

0/150

提交评论