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

📄 main.cpp

📁 数据结构课程设计——家谱管理系统设计与实现
💻 CPP
字号:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
#include "genealogy.h"


void main()
{
	GEnealogy ged;
	person pnode=new CSNode;
	person resultname=new CSNode;
	
	int choice1;
	char Name[max_char_num],tag[max_char_num];
	strcpy(tag,"-1");
	while(1)
	{
		//输出主画面选择菜单
		cout<<"***************************Genealogy System***************************"<<endl;
		cout<<"1.Build a new Genealogy "<<endl;
		cout<<"2.Read Genealogy Data from a binary dat file"<<endl;
		cout<<"3.Save Genealogy Data into disk"<<endl;
		cout<<"4.Add a person to the Genealogy"<<endl;
		cout<<"5.Modify a person in the Genealogy"<<endl;
		cout<<"6.Delete a person and his all offspring"<<endl;
		cout<<"7.Display the Genealogy in the tree form"<<endl;
		cout<<"8.Statistic a person status in the Genealogy"<<endl;
		cout<<"9.Find a person by his information"<<endl;
		cout<<"10.Find a person by relative relationshiop"<<endl;
		cout<<"0.Exit"<<endl;
		cin>>choice1;
		switch(choice1)
		{
		case 1:
			//选1,建立一个二叉树家谱,并输入根结点信息
		    system("cls");
			cout<<"*************Build a new Genealogy Operation*********************"<<endl;
			strcpy(pnode->data.parentname,tag);
			ged.NewGEnealogy();
			cout<<"Please input the information of the root person"<<endl;
			ged.InputData(pnode);
			ged.Add(NULL,pnode);
			break;
		
		case 2:
	        //选2,从文件读取数据建立二叉树
	     	ged.CreateGEnealogy();
			system("cls");
			cout<<"***********************Read Opertation***************************"<<endl;
			cout<<"Read successfully"<<endl;
			break;
		
		case 3:
			//选3,保存二叉树信息到文件
			
			system("cls");
			cout<<"***********************Save Opertation***************************"<<endl;
			ged.SaveGEnealogy();
			cout<<"Save successfully"<<endl;
			break;
		
		case 4:
			//选4,在二叉树添加结点
			system("cls");
			cout<<"***********************Add Child Opertation***************************"<<endl;
			if(ged.GetRoot())
				ged.AddOperation();//根结点非空,调用addoperation()添加结点
			else
			{
				//否则添加根结点
				ged.NewGEnealogy();
				cout<<"It's a null Genealogy,Please input the information of the root person"<<endl;
				ged.InputData(pnode);
				ged.Add(NULL,pnode);
			}
			break;
        
		case 5:
			//选5,修改树结点信息
			system("cls");
			cout<<"***********************Modify Opertation***************************"<<endl;
			cout<<"Please input the name of the person you want to modify"<<endl;
			cin>>Name;
			resultname=NULL;
			ged.FindByName(ged.GetRoot(),resultname,Name);
			if(resultname)
			{
				cout<<"Please input new information of the person"<<endl;
				ged.InputData(pnode);
				ged.Modify(resultname,pnode);
			}
			else
				cout<<"Input error"<<endl;
			break;
		
		case 6:
			//选6,删除某个结点以及他的所有孩子结点
			system("cls");
			cout<<"***********************Delete Opertation***************************"<<endl;
			cout<<"Please input the name of the person and his offspring you want to delete"<<endl;
			cin>>Name;
			resultname=NULL;
			ged.FindByName(ged.GetRoot(),resultname,Name);
			if(resultname)
			{
				ged.Delete(resultname);
				cout<<"Delete successfully"<<endl;
			}
			else 
				cout<<"Input error"<<endl;
			break;
		
		case 7:
			//选7,输出树型表
			system("cls");
			cout<<"***********************Display Opertation***************************"<<endl;
			if(ged.GetRoot())
				ged.DisplayTree(ged.GetRoot());
			else
                cout<<"Genealogy is NULL"<<endl;
			break;
		
		case 8:
			//选8,调用统计函数
			system("cls");
			cout<<"***********************Statistic Opertation***************************"<<endl;
			ged.Statistic();
			break;
		
		case 9:
			//选9,调用按基本信息查询函数
			system("cls");
			cout<<"***********************Inquie Opertation I***************************"<<endl;
			ged.Inquire();
			break;
		
		case 10:
			//选10,查询亲属关系
			system("cls");
			cout<<"***********************Inquie Opertation II***************************"<<endl;
			cout<<"Please input the name of the person you want to find about his relative"<<endl;
			cin>>Name;
			ged.FindByName(ged.GetRoot(),resultname,Name);
			if(resultname)
				ged.FindByRelationship(resultname);
			else
				cout<<"Input error"<<endl;
			break;
		
		case 0:
			//选0,退出
			system("cls");
			cout<<"Good Bye"<<endl;
			cout<<"THANK YOU FOR USING "<<endl;
			return;
			
		default:
			//其他,输入错误,重输
			cout<<"Input error,please reinput"<<endl;
			break;
		}
	}
}
			
				











⌨️ 快捷键说明

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