📄 fms.cpp
字号:
//家族管理系统.cpp
#include"familytree.h"
#include<fstream.h>
int main()
{
familytree family;
ifstream input;
int choice,c,g;
char n[10];
char *name,*father,*birth,*spouse;
int sex,marital_status,generation;
member *new_member,*new_member1;
while(1){
cout<<"---------------------------------Function menu----------------------------------";
cout<<"0.Read familytree"<<"\t1.Print the family "<<"\t2.Add new member\n"
<<"3.Delete familytree"<<"\t4.Show father or husband"<<"\t5.Show wife\n"
<<"6.Show child "<<"\t7.Show brothers or sister"<<"\t8.Show oneself\n"
<<"9.Exit\n"
<<"Input your choice:";
cin>>choice;
switch(choice)
{
case 0:
cout<<"\nReading complete!\n\n";
input.open("in.txt");
if(!input)
{
cout<<"ERROR! Can't find the \"in.txt\"!\n";
return 1;
}
int i;
member *temp;
for(i=0;i<20;i++)
{
name=new char[10];
father=new char[10];
birth=new char[10];
spouse=new char[10];
input>>name>>sex>>birth>>father>>marital_status>>spouse;
temp=new member(name,sex,birth,father,marital_status,spouse,0,NULL,NULL);
family.add(temp);
}
input.close();
break;
case 1:
cout<<"------------------------------Family information--------------------------------";
cout<<"name"<<" sex"<<" birthday"<<" father(husband)"<<" marital status"<<" spouse"<<" generation";
family.printf();
c=family.getcount();
g=family.getcountg();
cout<<"There are "<<c<<" members in this family.\n"
<<g<<" generations in total.\n";
break;
case 2:
name=new char[10];
father=new char[10];
birth=new char[10];
spouse=new char[10];
cout<<"please input the information of the new member:\n";
cout<<"name:";
cin>>name;
cout<<"sex(female=0,male=1):";
cin>>sex;
cout<<"birthday:";
cin>>birth;
cout<<"father or hunsband's name:";
cin>>father;
cout<<"marital status(single=0,married=1):";
cin>>marital_status;
if(marital_status==1){cout<<"spouse:";cin>>spouse;}
new_member=new member(name,sex,birth,father,marital_status,spouse,0,NULL,NULL);
family.add(new_member);
if((new_member->marital_status==1)&&(new_member->sex=1))
{
cout<<"please input the information of "<<new_member->name<<"'s wife:\n";
birth=new char[10];
cout<<"birthday:";
cin>>birth;
new_member1=new member(new_member->spouse,0,birth,new_member->name,1,new_member->name,0,NULL,NULL);
family.add(new_member1);
}
cout<<"Complete!\n";
break;
case 3:
cout<<"Complete!\n";
family.deletefamily();
break;
case 4:
cout<<"\tname:";
cin>>n;
family.showfather(n);
break;
case 5:
cout<<"\tname:";
cin>>n;
family.showwife(n);
break;
case 6:
cout<<"\tname:";
cin>>n;
family.showchilden(n);
break;
case 7:
cout<<"\tname:";
cin>>n;
family.showbrother(n);
break;
case 8:
cout<<"\tname:";
cin>>n;
family.showoneself(n);
break;
case 9:
cout<<"*************************************exit***************************************";
return 0;
default:
cout<<"Error! Please choose again!\n";
break;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -