简易家谱管理系统

#include<iostream>
#include<fstream>         //ifstream.open
#include<sstream>        //sin
#include<string>         //string
#include<cstring>            //strcmp
#include<stdio.h>           //清屏
#include<conio.h>           //getch()
using namespace std;

#define max 50
#define True  1
#define False  0


/*全局变量定义*/
char Name[max][max];
char Birth[max][max];
int  Marry[max] = { 0 }; // 1代表结婚  -1代表未婚
char Address[max][max];
int  Alive[max] = { 0 };  // 1代表健在  -1代表死亡
char Pass[max][max];  //死亡日期(若其已死亡)
int  Gene[max] = { 0 };  //第几
int  Num[max] = { 0 };  //孩子个数
int k = 0;  //文件读取计数
int m = 0;   //判定是否有成员在某天生日


typedef struct Node
{
	const char* name;      //姓名
	const char* birth;     //出生日期
	int   marry;           // 1代表结婚  -1代表未婚
	const char* address;   //地址
	int   alive;           // 1代表健在  -1代表死亡
	const char* pass;      //死亡日期(若其已死亡)
	int   gene;            //第几代
	int   num;             //孩子个数


	Node* child[max]; //指针指向孩子结点
	Node* parent;     //指针指向父亲结点
	Node();           //无参构造函数


}PedNode, * Tree;



Node::Node()                  //结点构造
{
	name = NULL;
	birth = NULL;
	address = NULL;
	marry = 0;
	alive = 0;
	pass = NULL;
	gene = 0;
	num = 0;
	*child = { NULL };
	parent = NULL;
}



/*功能函数声明*/
void MainMenu(); //家谱主菜单
void CreateTree(Tree tree); //调用子树构造函数 递归创建家谱树
void NewChildTree(Tree tree); //子树构造函数 
void ShowAll(Tree tree); //递归输出整个家谱信息
bool NameSearch(Tree tree, char Name[], Tree* DrawTree);  //在树中按照姓名进行查找
void ShowIn(Tree tree); //输出成员信息(包括本人,父母,孩子的信息)  服务于姓名查询
void All_n(Tree tree, int date);  //显示第n代所有人信息
void ShowAll_n(Tree tree); //查找第n代成员功能函数
void BirthSearch(Tree tree, char* date);//按照生日查询成员名单
void ShowBirthSearch(Tree tree); //生日查询输出功能
void Relation(Tree tree, char* name1, char* name2);//确定两人关系
Tree Delete(Tree tree); //删除树
void AddChild(Tree tree, char* name3); //某成员添加孩子
Tree deleteTree(Tree tree, char* aa); //传入要删除成员姓名
void Show(Tree tree);  //输出某一个节点的信息
void Change(Tree tree, char* name4); //修改信息

int main()
{
	int choice;    //菜单选择
	char namea[max], nameb[max], namec[max], named[max], namee[max];
	ifstream inf;
	inf.open("d://ped.txt");
	string line;
	int i = 0;
	while (getline(inf, line))
	{
		istringstream sin(line);
		sin >> Name[i] >> Birth[i] >> Marry[i] >> Address[i] >> Alive[i] >> Pass[i] >> Gene[i] >> Num[i];
		i++;
	}

	Node pednode;
	Tree pedtree = &pednode;
	CreateTree(pedtree);
	MainMenu();
	cout << endl;
	cout << "请输入相应功能前数字进行实现!" << endl;
	cin >> choice;
	for (; choice != 0;)
	{
		switch (choice)
		{
		case 1:
		{
			ShowBirthSearch(pedtree);

		}    break;
		case 2:
		{
			ShowAll_n(pedtree);

		}break;
		case 3:
		{
			ShowIn(pedtree);

		}break;
		case 4:
		{
			cout << "请输入想要输出关系的两个成员的姓名(中间用空格符间隔):" << endl;
			cin >> nameb >> namec;
			Relation(pedtree, nameb, namec);

		}break;
		case 5:
		{
			cout << "请输入添加孩子的父(母)姓名:" << endl;
			cin >> named;
			AddChild(pedtree, named);

		}break;
		case 6:
		{
			cout << "请输入想要删除的成员姓名:" << endl;
			cin >> namea;
			pedtree = deleteTree(pedtree, namea);

		} break;

		case 7:
		{

			cout << "请输入要修改信息的成员姓名:" << endl;
			cin >> namee;
			Change(pedtree, namee);

		}break;

		case 0:
		{

		}break;
		}


		cout << "请输入相应功能前数字进行实现!" << endl;
		fflush(stdin);//清除键盘缓冲区 

		cin >> choice;
		system("cls");
		MainMenu();
	}


	return 0;
}

void MainMenu()
{
	cout << "* * * * * * * * * * * * * * * * * * * * *" << endl;
	cout << "*            家谱管理系统主菜单         *" << endl;
	cout << "*---------------------------------------*" << endl;
	cout << "*            1:查询某天出生的成员名单  *" << endl;
	cout << "*            2:显示第n代所有人信息     *" << endl;
	cout << "*            3:按照姓名查询成员信息    *" << endl;
	cout << "*            4:确定两人关系            *" << endl;
	cout << "*            5:添加孩子                *" << endl;
	cout << "*            6:删除某成员              *" << endl;
	cout << "*            7:修改某成员信息          *" << endl;
	cout << "*            0:退出程序                *" << endl;
	cout << "* * * * * * * * * * * * * * * * * * * * *" << endl;
}




void NewChildTree(Tree childtree)             //创建子树 递归调用
{
	for (int e = 0; e < childtree->num; e++)
	{
		Tree ChildTree = new Node;
		childtree->child[e] = ChildTree;
		ChildTree->name = Name[k];
		ChildTree->birth = Birth[k];
		ChildTree->marry = Marry[k];
		ChildTree->address = Address[k];
		ChildTree->alive = Alive[k];
		ChildTree->pass = Pass[k];
		ChildTree->gene = Gene[k];
		ChildTree->num = Num[k];
		k++;
		ChildTree->parent = childtree;
		NewChildTree(ChildTree);
	}
}



void CreateTree(Tree tree)            //创建家谱树
{
	tree->name = Name[k];
	tree->birth = Birth[k];
	tree->marry = Marry[k];
	tree->address = Address[k];
	tree->alive = Alive[k];
	tree->pass = Pass[k];
	tree->gene = Gene[k];
	tree->num = Num[k];
	tree->parent = NULL;
	int p = tree->num;
	k++;
	for (int b = 0; b < p; b++)
	{
		Tree ChildTree = new Node;
		tree->child[b] = ChildTree;
		ChildTree->name = Name[k];
		ChildTree->birth = Birth[k];
		ChildTree->marry = Marry[k];
		ChildTree->address = Address[k];
		ChildTree->alive = Alive[k];
		ChildTree->pass = Pass[k];
		ChildTree->gene = Gene[k];
		ChildTree->num = Num[k];
		k++;
		ChildTree->parent = tree;
		NewChildTree(ChildTree);
	}

}



void ShowAll(Tree tree)     //输出整个家谱树
{

	Show(tree);
	for (int f = 0; f < tree->num; f++)
	{
		cout << tree->name << "的第" << f + 1 << "个子女:" << endl;
		ShowAll(tree->child[f]);
	}
}



void Show(Tree tree)   //输出家谱中某个成员的信息
{
	if (tree->name == "0")
	{
		cout << "该成员已被删除" << endl;
		cout << endl;
	}
	else
	{
		cout << "姓名:" << tree->name << endl;
		cout << "出生日期: " << tree->birth << endl;
		if (tree->marry == 1)
			cout << "婚否:已婚" << endl;
		else
			cout << "婚否:未婚" << endl;
		cout << "住址:" << tree->address << endl;


		if (tree->alive == 1)
			cout << "健在状况:健在" << endl;
		else
		{
			cout << "健在状况:死亡" << endl;
			cout << "死亡日期:" << tree->pass << endl;
		}
		cout << "宗族代数:第" << tree->gene << "代" << endl;
		cout << endl;
	}
}



void ShowIn(Tree tree)    //姓名查找的输出函数
{
	Tree temptree = NULL;
	cout << "请输入要查找人的姓名:" << endl;
	char namea[max];
	cin >> namea;
	bool g = NameSearch(tree, namea, &temptree);
	if (g)
	{
		cout << "查找成功!" << endl;
		cout << "-----本人信息为------" << endl;
		Show(temptree);
		if (temptree->parent != NULL)
		{
			cout << "父(母)亲姓名为:" << temptree->parent->name << endl;
		}
		cout << endl;
		if (temptree->num == 0)
		{
			cout << "该成员无孩子" << endl;
		}
		else
		{
			for (int h = 0; h < temptree->num; h++)
			{
				cout << "孩子姓名为:";
				cout << temptree->child[h]->name << endl;
			}
		}
	}
	else
		cout << "家谱中不存在该人信息" << endl;
}




bool NameSearch(Tree tree, char Name[], Tree* DrawTree)//在树中按照姓名查找 
{
	if (strcmp(tree->name, Name) == 0)
	{
		*DrawTree = tree;
		return true;
	}
	else
	{
		for (int g = 0; g < tree->num; g++)
		{
			if (NameSearch(tree->child[g], Name, DrawTree))
				return true;
		}
		return false;
	}
}




void All_n(Tree tree, int dai) //寻找第n代所有人信息
{
	if (tree->gene == dai)
	{
		Show(tree);
		cout << endl;
	}
	else
	{
		for (int j = 0; j < tree->num; j++)
		{
			All_n(tree->child[j], dai);
		}
	}

}


void  ShowAll_n(Tree tree)    //查找第n代成员功能函数
{
	cout << "请输入想要查询的代数" << endl;
	int dai;
	cin >> dai;
	cout << "*****************************" << endl;
	All_n(tree, dai);
	cout << "第" << dai << "代成员输出完毕!" << endl;
	cout << "*****************************" << endl;
}




void BirthSearch(Tree tree, char* date)    //按照生日查询成员名单
{
	if (strcmp(tree->birth, date) == 0)
	{
		cout << tree->name << endl;
		m += 1;
	}
	else
	{
		for (int j = 0; j < tree->num; j++)
		{
			BirthSearch(tree->child[j], date);
		}
	}



}


void ShowBirthSearch(Tree tree)        //生日查询输出功能
{
	char  date[max];
	cout << "**********************************************************" << endl;
	cout << "输入想要查询的出生日期:(输入格式示例:2000-06-27)" << endl;

	cin >> date;
	cout << "在" << date << "出生的成员名单为:" << endl;
	BirthSearch(tree, date);
	if (m == 0)
	{
		cout << "无" << endl;
		cout << "没有成员在这一天生日!" << endl;
	}
	cout << endl;
	cout << "生日查询结束!" << endl;
	cout << "***********************************************************" << endl;
}



Tree  Delete(Tree tree) //删除树
{

	if (tree)
	{
		for (int n = 0; n < tree->num; n++)
			tree->child[n] = Delete(tree->child[n]);
		tree->alive = 0;
		tree->gene = 0;
		tree->name = "0";
		tree->num = 0;
		tree->birth = "0";
		tree->pass = "0";
		tree->marry = 0;
		tree->address = "0";
	}
	return tree;
}


Tree deleteTree(Tree tree, char* aa)    //传入要删除成员姓名
{

	Tree tempTree = NULL;
	if (NameSearch(tree, aa, &tempTree))
	{
		Delete(tempTree);
		cout << "删除成功!" << endl;
		return tree;
	}
	else
	{
		cout << "家族中没有该成员!" << endl;
		return tree;
	}
}




void Relation(Tree tree, char* name1, char* name2)    //确定两人关系
{
	Tree temptree1 = NULL, temptree2 = NULL;
	bool o = NameSearch(tree, name1, &temptree1);
	bool p = NameSearch(tree, name2, &temptree2);

	if (o && p)                 //两个人均查找成功
	{

		if (temptree1->parent == temptree2)
		{
			cout << name2 << "是" << name1 << "的父(母)亲" << endl;
		}
		else if (temptree2->parent == temptree1)
		{
			cout << name1 << "是" << name2 << "的父(母)亲" << endl;
		}
		else if (temptree1->parent == temptree2->parent)
		{
			cout << name1 << "和" << name2 << "是兄弟姐妹关系" << endl;
		}
		else if (temptree1->parent->parent == temptree2 && temptree1->parent->parent != NULL)
		{
			cout << name2 << "是" << name1 << "的祖辈" << endl;
		}
		else if (temptree2->parent->parent == temptree1 && temptree1->parent->parent != NULL)
		{
			cout << name1 << "是" << name2 << "的祖辈" << endl;
		}
		else if ((temptree1->parent != temptree2->parent) && (temptree1->parent->parent == temptree2->parent->parent) && temptree1->parent->parent != NULL && temptree2->parent->parent != NULL)
		{
			cout << name1 << "和" << name2 << "互为表兄弟(表姐妹/堂兄弟/堂姐妹)" << endl;
		}

		else if ((temptree1->parent->parent == temptree2->parent) && temptree1->parent != temptree2 && temptree1->parent->parent != NULL)
		{
			cout << name1 << "的父母和" << name2 << "是兄弟姐妹" << endl;
		}
		else if ((temptree2->parent->parent == temptree1->parent) && (temptree2->parent != temptree1))
		{
			cout << name2 << "的父母和" << name1 << "是兄弟姐妹" << endl;
		}
		else
		{
			cout << name1 << "和" << name2 << "无明显近亲关系" << endl;
		}
	}
	else
	{
		cout << "未在家谱中查找到这两名成员" << endl;
	}

}


void AddChild(Tree tree, char* name3)     //某成员添加孩子
{
	Tree temptree4 = NULL;
	bool q = NameSearch(tree, name3, &temptree4);
	Tree ChildTree = new Node;
	temptree4->child[temptree4->num] = ChildTree;
	temptree4->num += 1;
	char name5[max];
	cout << "请输入孩子姓名:" << endl;
	cin >> name5;
	ChildTree->name = name5;
	char adress[max];
	cout << "请输入地址:" << endl;
	cin >> adress;
	ChildTree->address = adress;
	char bir[max];
	cout << "请输入孩子的出生日期:(示例:2021-02-12)" << endl;
	cin >> bir;
	ChildTree->birth = bir;
	ChildTree->alive = 1;
	ChildTree->num = 0;
	ChildTree->marry = -1;
	ChildTree->gene = (temptree4->gene) + 1;
	cout << "添加孩子成功!" << endl;
}



void Change(Tree tree, char* name4) //修改信息
{
	cout << "**********************************************************" << endl;
	cout << "若某项信息不需要修改,输入0跳过此项" << endl;
	Tree temptree5 = NULL;
	bool r = NameSearch(tree, name4, &temptree5);
	if (r)
	{
		char name6[max];
		cout << "姓名变更为:" << endl;
		cin >> name6;
		if (strcmp(name6, "0") == 1)
			temptree5->name = name6;
		char adr[max];
		cout << "住址变更为:" << endl;
		cin >> adr;
		if (strcmp(adr, "0") == 1)
			temptree5->address = adr;
		char bi[max];
		cout << "出生日期变更为:" << endl;
		cin >> bi;
		if (strcmp(bi, "0") == 1)
			temptree5->birth = bi;
		int ma;
		cout << "婚姻状态变更为:(1代表已婚  -1代表未婚)" << endl;
		cout << "请输入1或-1修改婚姻状态!或输入0跳过此步骤" << endl;
		cin >> ma;
		if (ma == 1 || ma == -1)
			temptree5->marry = ma;
		int al;
		cout << "健在状态变更为:(1代表健在  -1代表死亡)" << endl;
		cin >> al;
		if (al == 1 || al == -1)
			temptree5->alive = al;
		char pa[max];
		cout << "死亡日期变更为:" << endl;
		cin >> pa;
		if (strcmp(pa, "0") == 1)
			temptree5->pass = pa;

		cout << endl;
		cout << "变更结束!" << endl;
		cout << "变更后的成员信息为:" << endl;
		Show(temptree5);

	}
	else
		cout << "未在家族中发现此人信息!" << endl;
	cout << "变更功能结束!" << endl;
	cout << "***********************************************" << endl;
}

  • 4
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
家谱软件是应海峡姓氏研究之约开发的族谱管理软件。 该软件是最新开发和上市的族谱管理软件,经过专业人士的指导和专业团队的开发,是目前国内性价比很高的专业族谱管理软件。 该软件具有管理大家族的能力,扩充能力在千万、亿级别,适合修全国统谱。可以谱修全国各个姓氏的族谱,对管理姓氏无限制。在同一软件上可以管理本家族和其他家族的资料,例可以管理外亲等家族的同步资料。 经过近三年的专业团队开发已经具有完善的族谱管理功能,可以帮助专业的谱修人士完成建谱、调谱、出谱等复杂的工作。该软件已经经过专业人士的测试,指导,能够完成大部分人的修谱需求。 该软件采用最先进的开发技术,采用国外最强大的单机版数据库技术,具有无限扩充能力和功能完善能力,该数据库支持的是上亿级别的数据处理。其技术为微软的开发平台支持,是其他族谱软件所无法比拟的平台和技术支撑。采用微软的visual studio开发技术,该技术是微软的最先进开发技术,从微软创办至今一直完善的一个技术支撑。 单机版本,数据库为单一文件,不是其他族谱软件的一堆数据文件。该数据库文件可以自己备份管理,可以拷贝到其他机器硬盘等来备份。 该程序可以脱网来使用,不需要上网,完全属于自己的软件,放心,安全,不受任何网络和第三方的控制。 该软件是目前市场上唯一直接对树操作的族谱管理软件,可以在树世系图上任意增加族人,选择某一族人后可以增加兄弟或子女。增加族人人数无限制。使用鼠标右键操作,符合大家的操作习惯。可以任意修改族人在树上的位置,方便在填错父亲的情况下将其修改回原来在树上的位置。在树上的位置可以整个分支改挂到另外一个分支,调整族人分支很方便。适合先建族人后修改父亲等需求。 该软件一改以往修谱软件的特点,增加了输出word文档的功能,方便在打印前对出谱资料的二次修改,具有很强的可修改性。另外,可以将族人图形资料输出到word文档,和族人资料一起一并打印。可以打印输出族人的图形等可见信息。 可以在数据库内保存家族和族人的语音、视频、扫描资料等重要资料,由于保存在数据库内,所以具有保密性。家谱资料在数据库内可以删除、查看,方便整个家族资料的管理和完备性。 可以将世系树的结构输出到文本文档,对于家族的分支结构在树上得到很好的诠释。由于文本文档不具有格式性, 所以可以输出无限大的世系图,可以将整个家族的世系图完整输出 。 具有输出部分世系图分支的功能,可以分段输出世系图,便于将世系图分段保存和管理。配合整个世系图和分段世系图,对于某一分支可以了解自家分支的世系全貌。 可以管理多个配偶信息,配偶信息的输出是附加在族人后面,对于家庭的完整性得到很好的体现。配偶信息资料全,可以了解配偶在自家的排行、兄弟姐妹等情况。 自定义家谱输出格式,方便输出古代的五代格式。五代输出按大排行方式输出,符合大家的排行习惯。 族人输出按照大排行的顺序输出,例子老大的儿子输出要排在老二儿子的前边, 老大的孙子输出也要排在老二孙子的前边,以此类推。 可以管理家族的历史事件,历史人物,可以任意增加历史事件和历史人物,来阐述家族曾经出得辉煌。增加的人物和事件无限制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值