⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.cpp

📁 家谱用于记录某家族历代家族成员的情况与关系。现编制一个家谱资料管理软件
💻 CPP
字号:
#include"DefineStruct.h"
void AddBrother(int OID,int NID,family * member,int total)//增加兄弟函数,是一个迭代
{
	if(member[OID].BrotherID==0)
	{
		member[OID].BrotherID=NID;
		
		return;
	}
	else
	{
		AddBrother(member[OID].BrotherID,NID,member,total);

		return;
	}
};

int AddChild(int PID,int SID,family * member,int total)//增加孩子
{
	if(member[PID].ChildID==0)//本来没有孩子
	{
		member[PID].ChildID=SID;

		member[member[PID].LoverID].ChildID=SID;
	}
	else
	{
		AddBrother(member[PID].ChildID,SID,member,total);//增加兄弟函数,无返回类型
	}

	return member[PID].GenID;//返回父母代数
};

int FindName(char * name,family *member,int total)//若找到,就返回对应的ID,若找不到,可返回0
{
	int i;

	for(i=1;i<=total;i++)
	{
		if(strcmp(name,member[i].name)==0) return i;
	}

	return 0;
}

void ShowBrother(int ID,family * member,int total)//展示对应ID的兄弟姓名
{
	if(member[ID].BrotherID==0) return;

	cout<<member[member[ID].BrotherID].name<<"\t";

	if(member[member[ID].BrotherID].BrotherID!=0)  ShowBrother(member[ID].BrotherID,member,total);

	return;
}

void ShowChild(int ID,family * member,int total)//展示对应ID的孩子姓名
{
	if(member[ID].ChildID==0) return;

	cout<<member[member[ID].ChildID].name<<"\t";

	if(member[member[ID].ChildID].BrotherID!=0)
	{
		ShowBrother(member[ID].ChildID,member,total);
	}
}

void ShowDate(int date)
{
	cout<<date/10000<<"年"<<(date-date/10000*10000)/100<<"月"<<date/1000000<<"日";
}

void show(int ID,family * member,int total)//显示对应的ID资料
{
	cout<<"姓名:"<<member[ID].name<<"\t";
	
	if(member[ID].sex==0) cout<<"性别:男";
		else cout<<"性别:女";

	if(member[ID].IsMember==0) cout<<"\n不是家族成员";
	else cout<<"\n是家族成员";

	if(member[ID].DadID!=0)
	{
		cout<<"\n父亲为:"<<member[member[ID].DadID].name;
	}

	if(member[ID].MumID!=0)
	{
		cout<<"\n母亲为:"<<member[member[ID].MumID].name<<endl;
	}

	if(member[ID].ChildID!=0)
	{
		cout<<"\n孩子名称为:";
	
		ShowChild(ID,member,total);//展示孩子函数
	}
	
	if(member[ID].BrotherID!=0)
	{
		cout<<"\n兄弟名称为:";

		ShowBrother(ID,member,total);//展示兄弟函数
	}

	cout<<"\n在家族中是第"<<member[ID].GenID<<"代";

	cout<<"\n身高为:"<<member[ID].height<<"cm";

	cout<<"\n出生地点:"<<member[ID].WhereBirth;

	cout<<"\n出生日期:";ShowDate(member[ID].BirthDate);//显示日期函数ShowDate(int)

	if(member[ID].DeathDate!=0)
	{
		cout<<"\t死亡日期为:";ShowDate(member[ID].DeathDate);
	}

	cout<<"\n学历为:"<<member[ID].schooling
		<<"\t职业为:"<<member[ID].occupation
		<<"\t职称为:"<<member[ID].title<<endl;

	return ;
};

int CinDate()//输入日期函数
{
	
	int y;

	cout<<"\n年?";

	cin>>y;

	int m;

	cout<<"月?";

	cin>>m;

	int d;

	cout<<"日?";

	cin>>d;

	return y*10000+m*100+d;//尚欠加入判断年月日有效值的函数

}

void ShowAll(family * member,int total)//用于显示成员资料
{
a:	cout<<"家族成员列表\n";
		
	ShowAllName(member,total);

	cout<<"\n请输入你需要查找资料的成员名字:";

	char name[10];

	cin>>name;

	int LID=FindName(name,member,total);

	if(LID==0)
	{
		cout<<"*********************"<<endl<<"没有此人!!"<<endl<<"*********************"<<endl;
		
		goto a;
	}

	show(LID,member,total);

	cout<<endl<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -