




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、 項(xiàng)目實(shí)訓(xùn)二 項(xiàng)目名稱(chēng) _ 家譜管理系統(tǒng)_ 姓名_ _ 班級(jí) _ _學(xué)號(hào)_ _指導(dǎo)教師 _ _ _ 2018.1問(wèn)題描述:家譜用于記錄某家族歷代家族成員的情況與關(guān)系?,F(xiàn)編制一個(gè)家譜資料管理系統(tǒng),實(shí)現(xiàn)對(duì)一個(gè)家族所有的資料進(jìn)行收集整理。實(shí)現(xiàn)對(duì)家庭成員信息的建立、查找、插入、修改、增加、刪除、更新、統(tǒng)計(jì)等等功能。目的和要求:目的:1、 能根據(jù)具體問(wèn)題的具體情況,結(jié)合數(shù)據(jù)結(jié)構(gòu)課程中的基本理論和基本算法,分析并正確確定數(shù)據(jù)的邏輯結(jié)構(gòu),合理地選擇相應(yīng)的存儲(chǔ)結(jié)構(gòu),并能設(shè)計(jì)出解決問(wèn)題的有效算法。2、 提高程序設(shè)計(jì)和調(diào)試能力。通過(guò)上機(jī)學(xué)習(xí),驗(yàn)證自己設(shè)計(jì)的算法的正確性。學(xué)會(huì)有效利用基本調(diào)試方法。3、 初步掌握軟件
2、開(kāi)發(fā)過(guò)程中問(wèn)題分析、系統(tǒng)設(shè)計(jì)、程序編碼、測(cè)試等基本方法和技能。4、 培養(yǎng)根據(jù)選題需要選擇學(xué)習(xí)書(shū)籍,查閱文獻(xiàn)資料的自學(xué)能力。要求: 用于記錄某家族歷代家族成員的情況與關(guān)系?,F(xiàn)編制一個(gè)家譜資料管理系統(tǒng),實(shí)現(xiàn)對(duì)一個(gè)家族所有的資料進(jìn)行收集整理。支持對(duì)家譜的增加,刪除,更新,統(tǒng)計(jì)等。軟件環(huán)境:Microsoft Visual Studio 2010流程設(shè)計(jì):開(kāi)始Main函數(shù)Menu函數(shù)FamilyTree函數(shù)Getroot函數(shù)Case 1Case 2Case 3Case 4Case 5Case 6Case 7Case 8Case 9Case10defeault結(jié)束Creat函數(shù)函數(shù)遞歸調(diào)用Menu函數(shù)P
3、reOrder函數(shù)函數(shù)InOrder函數(shù)函數(shù)PostOrder函數(shù)函數(shù)Generation函數(shù)函數(shù)NumberOfPeople函數(shù)函數(shù)LifeNum函數(shù)函數(shù)Message函數(shù)函數(shù)AddNewPeople函數(shù)數(shù)DeletePeople函數(shù)SetNewName函數(shù)FindChild函數(shù)SaveToFile函數(shù)FileToFamilyTree函數(shù)遞歸調(diào)用遞歸調(diào)用遞歸調(diào)用PrintMessage函數(shù)函數(shù)SetNode函數(shù)函數(shù)函數(shù)PreFindFather函數(shù)函數(shù)PreFindBrother函數(shù)函數(shù)PreFindFather函數(shù)函數(shù)PreFindBrother函數(shù)函數(shù)PrintMessage函數(shù)函數(shù)模塊
4、劃分:1、 統(tǒng)計(jì)模塊(1) 統(tǒng)計(jì)家族總?cè)藬?shù)、健在人數(shù)、幾代人(2) 主要函數(shù):int Generation(Node *root); /這個(gè)家族共有幾代人int NumberOfPeople( ); /家族的總?cè)藬?shù)int LifeNum( ); /健在人數(shù)(3) 實(shí)現(xiàn)方法:靜態(tài)成員變量(4) 實(shí)現(xiàn)結(jié)果:2、 更新模塊(1) 創(chuàng)建家譜、增加成員、刪除成員、成員改名(2) 主要函數(shù):Node* Creat( ); /構(gòu)造函數(shù)調(diào)用void AddNewPeople(Node *root,string FatherName,string NAme); /增加新的家族成員int DeletePeople
5、(Node *root,string FatherName,string Deletepeople); /刪除家族成員int SetNewName(Node *root,string NAme,string NewName); /更改姓名(3) 實(shí)現(xiàn)方法:創(chuàng)建家譜和成員改名主要通過(guò)遞歸調(diào)用;增加成員和刪除成員主要通過(guò)棧的非遞歸調(diào)用。(4) 實(shí)現(xiàn)結(jié)果:3、 查詢(xún)模塊(1) 查詢(xún)成員詳細(xì)信息、查詢(xún)成員的孩子以及孩子的詳細(xì)信息(2) 主要函數(shù):int Message(Node *root,string Name); /顯示該成員的基本信息int FindChild(Node *root,string
6、 NAme); /顯示孩子信息(3) 實(shí)現(xiàn)方法:通過(guò)遞歸調(diào)用,找到成員,輸出相應(yīng)的信息(4) 實(shí)現(xiàn)結(jié)果:4、 顯示模塊(1) 前序、中序、后序遍歷家譜(2) 主要函數(shù):void PreOrder(Node *root); /前序遞歸遍歷輸出家譜void InOrder(Node *root); /中序遞歸遍歷輸出家譜void PostOrder(Node *root); /后序遞歸遍歷輸出家譜(3) 實(shí)現(xiàn)方法:遞歸遍歷(4) 實(shí)現(xiàn)結(jié)果:5、 文件模塊(1) 保存到文件、從文件讀?。?) 主要函數(shù):void SaveToFile(Node *root); /保存到文件void FileToFam
7、ilyTree( Node *root) ; /從文件中讀取(3) 實(shí)現(xiàn)方法:文件流(4) 實(shí)現(xiàn)結(jié)果:數(shù)據(jù)結(jié)構(gòu)實(shí)現(xiàn):1、 生日結(jié)構(gòu)體struct BirthDay int year;int month;int day;friend istream& operator>>(istream &is,BirthDay &b);friend ostream& operator<<(ostream &os,const BirthDay &b);2、 信息結(jié)構(gòu)體(家族成員的基本信息)struct Informationstring n
8、ame; /姓名string birthPlace; /出生地BirthDay birthDay; /生日string sex; /性別string education; /學(xué)歷string job; /工作string father; /父親string spouse; /配偶char life; /是否健在;3、 二叉樹(shù)結(jié)點(diǎn)結(jié)構(gòu)體struct NodeInformation data; /個(gè)人信息Node* child; /第一個(gè)孩子Node* brother; /兄弟;4、 家譜類(lèi)(二叉樹(shù)結(jié)構(gòu)、左孩子,右兄弟)class FamilyTreeprivate:Node* root;Node
9、* Creat( ); /構(gòu)造函數(shù)調(diào)用void Release(Node *root); /析構(gòu)函數(shù)調(diào)用static int Numberofpeople; /計(jì)算總?cè)藬?shù),NumberOfPeople()調(diào)用static int LifePeopele; /計(jì)算健在人數(shù),LifeNum()調(diào)用public:FamilyTree(); /構(gòu)造函數(shù),初始化一棵樹(shù),其前序序列由鍵盤(pán)輸入FamilyTree(); /析構(gòu)函數(shù),釋放鏈表中各結(jié)點(diǎn)的存儲(chǔ)空間void SetNode(Node *root); /設(shè)置結(jié)點(diǎn)信息Node* Getroot(); /獲取根結(jié)點(diǎn)void PreOrder(Node *
10、root); /前序遞歸遍歷輸出家譜void InOrder(Node *root); /中序遞歸遍歷輸出家譜void PostOrder(Node *root); /后序遞歸遍歷輸出家譜int Generation(Node *root); /這個(gè)家族共有幾代人int NumberOfPeople( ); /家族的總?cè)藬?shù)int LifeNum( ); /健在人數(shù)void PrintMessage(Node *root ); /輸出基本信息int Message(Node *root,string Name); /顯示該成員的基本信息Node* PreFindFather(Node *root
11、,string FatherName); /給定元素值查找父親結(jié)點(diǎn)指針位置并返回其指針,此方法采用的先序遍歷 Node* PreFindBrother(Node *root,string FatherName); /給定元素值查找兄弟結(jié)點(diǎn)指針位置并返回其指針,此方法采用的先序遍歷 void AddNewPeople(Node *root,string FatherName,string NAme); /增加新的家族成員int DeletePeople(Node *root,string FatherName,string Deletepeople); /刪除家族成員int SetNewName
12、(Node *root,string NAme,string NewName); /更改姓名int FindChild(Node *root,string NAme); /顯示孩子信息void SaveToFile(Node *root); /保存到文件void FileToFamilyTree( Node *root) ; /從文件中讀取;調(diào)試分析:1、 問(wèn)題:在創(chuàng)建家譜時(shí),詢(xún)問(wèn)用戶(hù)是否需要繼續(xù)添加成員,只要用戶(hù)不輸入”#”就繼續(xù)添加。解決方案:增加if語(yǔ)句判斷條件,只要輸入的不是”Y”,”y”,”#”,就請(qǐng)用戶(hù)重新輸入。2、 問(wèn)題:計(jì)算總?cè)藬?shù)和健在人數(shù),因?yàn)榇嬖谠黾雍蛣h除函數(shù),多次調(diào)用計(jì)算
13、函數(shù)。解決方案:在家譜類(lèi)中使用靜態(tài)成員變量3、 問(wèn)題:在輸入和輸出成員信息中的生日,生日使用的是生日結(jié)構(gòu)體變量,輸入輸出包括年、月、日。解決方案:使用友元輸入輸出重載4、 問(wèn)題:在輸入生日時(shí),輸入數(shù)字程序正常運(yùn)行,輸入其他字符,程序會(huì)出現(xiàn)死循環(huán)。解決方案:cin.fail()判斷輸入是否正確,cin.clear()為了使輸入錯(cuò)誤能重新輸入,將錯(cuò)誤標(biāo)識(shí)符改為0,cin.sync()清空流。5、 問(wèn)題:在輸入一些信息是,詢(xún)問(wèn)用戶(hù)是否確認(rèn)一些信息時(shí),請(qǐng)用戶(hù)輸入y、n,但是用戶(hù)有時(shí)會(huì)輸入大寫(xiě)。解決方案:使用toupper()函數(shù),將用戶(hù)輸入的確認(rèn)信息轉(zhuǎn)換成大寫(xiě)字母。6、 問(wèn)題:在增加孩子時(shí),只能添加長(zhǎng)
14、子,添加第二個(gè)孩子、第三個(gè)等等,會(huì)出現(xiàn)錯(cuò)誤。解決方案:添加一個(gè)尋找兄弟指針的函數(shù),如果要添加孩子的成員,已經(jīng)有了孩子,則通過(guò)調(diào)用兄弟指針函數(shù)來(lái)增加孩子。7、 問(wèn)題:保存到文件和讀取文件時(shí),會(huì)出現(xiàn)輸入路徑錯(cuò)誤的情況。解決方案:通過(guò)調(diào)用_access()函數(shù),判斷輸入路徑是否正確。8、 問(wèn)題:讀取文件時(shí),cin的>>重載會(huì)跳過(guò)空白字符,包括回車(chē)符。解決問(wèn)題:使用cin.get()函數(shù)接收回車(chē)。9、 問(wèn)題:刪除成員時(shí),刪除能夠成功,但會(huì)出現(xiàn)空指針錯(cuò)誤。解決方案:在delete該成員時(shí),需要將指向該成員的指針置空。10、 問(wèn)題:在主函數(shù)中,通過(guò)請(qǐng)用戶(hù)輸入數(shù)字,來(lái)選擇相應(yīng)的操作,當(dāng)用戶(hù)誤輸入
15、的為選擇以外的字符時(shí),會(huì)結(jié)束程序運(yùn)行。解決方案:與解決方案4相同。實(shí)驗(yàn)結(jié)果及分析1、 創(chuàng)建家譜2、 保存到文件3、 讀取文件4、 增加成員5、 基本信息6、 查詢(xún)成員信息7、 成員改名8、 遍歷家譜9、 查詢(xún)孩子信息10、 刪除成員收獲: 本次實(shí)訓(xùn)在我們?yōu)槠趦芍艿臅r(shí)間里進(jìn)行,通過(guò)自己的不斷學(xué)習(xí)、請(qǐng)教和老師的指導(dǎo),完成了關(guān)于家譜資料管理的設(shè)計(jì)。前期主要是準(zhǔn)備階段,運(yùn)用哪些技術(shù),中期實(shí)踐階段,通過(guò)幾天的上機(jī)編寫(xiě)代碼,然后完成,后期完善階段,對(duì)一些難點(diǎn)和重點(diǎn)再細(xì)化,和做一些數(shù)據(jù)輸入時(shí)的異常處理。最后進(jìn)行答辯階段。通過(guò)這次實(shí)訓(xùn)的互相幫助學(xué)習(xí)的過(guò)程,自己看書(shū)學(xué)習(xí)的經(jīng)驗(yàn),以及從網(wǎng)上以及其他各種途徑獲得信息
16、和知識(shí)的經(jīng)驗(yàn)。理論與實(shí)際相結(jié)合的設(shè)計(jì),鍛煉了我綜合運(yùn)用所學(xué)的基礎(chǔ)知識(shí),解決實(shí)際問(wèn)題的能力,同時(shí)也提高我查閱文獻(xiàn)資料、對(duì)程序整體的把握等其他能力水平。而且通過(guò)對(duì)整體的掌控,對(duì)局部的取舍,以及對(duì)細(xì)節(jié)的斟酌處理,都使我的能力得到了鍛煉,我的各方面經(jīng)驗(yàn)都得到了極大的豐富。附錄 全部代碼Familytree.h#ifndef FAMILYTREE_H#define FAMILYTREE_H#include <iostream>#include <string>#include <cctype> #include <io.h> #include <io
17、manip>#include <fstream>using namespace std;struct BirthDay int year;int month;int day;friend istream& operator>>(istream &is,BirthDay &b);friend ostream& operator<<(ostream &os,const BirthDay &b);struct Informationstring name;string birthPlace;BirthDay b
18、irthDay;string sex; string education; string job;string father;string spouse;char life; ;struct NodeInformation data;Node* child; Node* brother; ;class FamilyTreeprivate:Node* root;Node* Creat( );void Release(Node *root);static int Numberofpeople;static int LifePeopele; public:FamilyTree(); FamilyTr
19、ee();void SetNode(Node *root); Node* Getroot();void PreOrder(Node *root);void InOrder(Node *root);void PostOrder(Node *root);int Generation(Node *root);int NumberOfPeople( );int LifeNum( ); void PrintMessage(Node *root ); int Message(Node *root,string Name);Node* PreFindFather(Node *root,string Fath
20、erName); Node* PreFindBrother(Node *root,string FatherName); void AddNewPeople(Node *root,string FatherName,string NAme);int DeletePeople(Node *root,string FatherName,string Deletepeople);int SetNewName(Node *root,string NAme,string NewName);int FindChild(Node *root,string NAme); void SaveToFile(Nod
21、e *root);void FileToFamilyTree( Node *root) ; ;#endifFamilytree.cpp#include "Familytree.h"int FamilyTree:Numberofpeople=0;int FamilyTree:LifePeopele=0;/生日結(jié)構(gòu)體變量輸入輸出友元重載istream& operator>>(istream &is,BirthDay &b)is>>b.year>>b.month>>b.day;return is;ostrea
22、m& operator<<(ostream &os,const BirthDay &b)os<<b.year<<"-"<<b.month<<"-"<<b.day;return os;FamilyTree:FamilyTree() /構(gòu)造函數(shù),初始化一棵樹(shù),其前序序列由鍵盤(pán)輸入this->root=Creat();FamilyTree:FamilyTree() /析構(gòu)函數(shù),釋放鏈表中各結(jié)點(diǎn)的存儲(chǔ)空間Release(root);Node* FamilyTre
23、e:Getroot() /獲取根結(jié)點(diǎn)return root;Node* FamilyTree:Creat()/構(gòu)造函數(shù)調(diào)用Node *root;string ch;cout<<"請(qǐng)問(wèn)是否創(chuàng)建(是:“y”,否:“#”):"cin>>ch; /輸入名字 if(ch!="y")/異常處理if(ch!="Y")if(ch!="#")int t=1;docout<<"n輸入不明確,請(qǐng)重新輸入!"<<endl;cout<<"請(qǐng)問(wèn)是否創(chuàng)建(
24、是:“y”,否:“#”):"cin>>ch;if(ch="y")|(ch="Y")|(ch="#")t=0;while(t=1);if (ch="#") root = NULL;elseroot=new Node; /申請(qǐng)結(jié)點(diǎn)內(nèi)存空間SetNode(root); /設(shè)置結(jié)點(diǎn)內(nèi)容root->child=Creat( ); /該結(jié)點(diǎn)的孩子root->brother=Creat( ); /該結(jié)點(diǎn)的兄弟return root; /返回結(jié)點(diǎn)void FamilyTree:Release(No
25、de *root) /析構(gòu)函數(shù)調(diào)用if(root!=NULL)Release(root->child); /釋放左孩子Release(root->brother); /釋放右兄弟delete root;void FamilyTree:SetNode(Node *root) /設(shè)置結(jié)點(diǎn)信息Numberofpeople+;cout<<"請(qǐng)輸入家庭成員的基本信息"<<endl;cout<<"姓名:"cin>>root->;cout<<"出生地:"
26、cin>>root->data.birthPlace;cout<<"生日(數(shù)字、年月日以空格或者回車(chē)間隔):"while(1)cin>>root->data.birthDay;if(cin.fail()cout<<"輸入有錯(cuò)!請(qǐng)重新輸入生日(數(shù)字):"<<endl;cin.clear(); /輸入錯(cuò)誤則能重新輸入cin.sync(); /清空流 elsebreak;/isdigit異常處理生日輸入,若參數(shù)c為阿拉伯?dāng)?shù)字09,則返回非0值,否則返回NULL。/*int i;for(i=
27、0;root->data.birthDayi!=0;+i)if(isdigit(root->data.birthDayi)=0)cout<<"n輸入不明確,請(qǐng)重新輸入!"<<endl;break;*/cout<<"性別:"cin>>root->data.sex;cout<<"學(xué)歷:"cin>>root->cation;cout<<"工作:"cin>>root->data.jo
28、b;cout<<"父親:"cin>>root->data.father;cout<<"配偶(有多任配偶則以“,”或者“、”間隔):"<<endl;cin>>root->data.spouse;cout<<"是否健在(y 是,n 否):"cin>>root->data.life;if(toupper(root->data.life)!='Y') /異常處理if(toupper(root->data.life)
29、!='N')int t=1;docout<<"n輸入不明確,請(qǐng)重新輸入!"<<endl;cout<<"是否健在(y 是,n 否):"cin>>root->data.life;if(toupper(root->data.life)='Y')|(toupper(root->data.life)='N')t=0;while(t=1);if(toupper(root->data.life)='Y')LifePeopele+;vo
30、id FamilyTree:PreOrder(Node *root) /前序遞歸遍歷輸出家譜if(root=NULL)return;elsecout<<root-><<'t'PreOrder(root->child);PreOrder(root->brother);void FamilyTree:InOrder(Node *root) /中序遞歸遍歷輸出家譜if(root=NULL) return;elseInOrder(root->child);cout<<root-><
31、;<'t'InOrder(root->brother);void FamilyTree:PostOrder(Node *root) /后序遞歸遍歷輸出家譜if(root=NULL)return;elsePostOrder(root->child);PostOrder(root->brother);cout<<root-><<'t'int FamilyTree:Generation(Node *root) /這個(gè)家族共有幾代人int l; /l左孩子 if(root=NULL) /這個(gè)家族為空
32、,返回0return 0; elsel=Generation(root->child); /左孩子的return l+1;/int numberofpeople=0;int FamilyTree:NumberOfPeople( ) /家族的總?cè)藬?shù)if(root=NULL) /家族人數(shù)為0return 0;/*elseif(root!=NULL)numberofpeople+;NumberOfPeople(root->child);NumberOfPeople(root->brother);return numberofpeople;*/elsereturn Numberofp
33、eople;/int count=0;int FamilyTree:LifeNum( ) /健在人數(shù)if(root=NULL) /-1表示這個(gè)家族不存在return -1; /*elseif(toupper(root->data.life)='Y')count+;LifeNum(root->child);LifeNum(root->brother);return count;*/return LifePeopele;void FamilyTree:PrintMessage(Node *root ) /輸出基本信息if(root=NULL)return ;els
34、ecout<<"姓名:"<<root->;cout<<"tt性別:"<<root->data.sex;cout<<"tt配偶:"<<root->data.spouse<<endl;cout<<"出生地:"<<root->data.birthPlace;cout<<"tt生日:"<<root->data.birthDay
35、;/;<<root->data.birthDay.year<<"-"<<root->data.birthDay.month<<"-"<<root->data.birthDay.day<<endl;cout<<"tt父親:"<<root->data.father<<endl;cout<<"學(xué)歷:"<<root->cation;cout<
36、<"tt工作:"<<root->data.job;cout<<"tt是否健在:"if(toupper(root->data.life)='Y')cout<<"是"<<endl;elsecout<<"否"<<endl; int message=0; /判斷是否查找成功int FamilyTree:Message(Node *root,string Name) /顯示該成員的基本信息if(root=NULL)ret
37、urn message;elseif(root->=Name)message=1;PrintMessage(root );elseMessage(root->child,Name);Message(root->brother,Name);return message;Node* FamilyTree:PreFindFather(Node *root,string FatherName) /給定元素值查找父親結(jié)點(diǎn)指針位置并返回其指針,此方法采用的先序遍歷 if(root=NULL)throw"錯(cuò)誤"Node *p;Node *tree20;
38、int top=0;while(root!=NULL|top!=0)while(root!=NULL)if(root->=FatherName)p=root;top+;treetop=root;root=root->child;if(top!=0)root=treetop->brother;top-;return p;Node* FamilyTree:PreFindBrother(Node *root,string FatherName) /給定元素值查找兄弟結(jié)點(diǎn)指針位置并返回其指針,此方法采用的先序遍歷 if(root=NULL)throw"錯(cuò)誤
39、"Node *p;Node *tree20;int top=0;while(root!=NULL|top!=0)while(root!=NULL)if(root->data.father=FatherName)p=root;top+;treetop=root;root=root->child;if(top!=0)root=treetop->brother;top-;return p;void FamilyTree:AddNewPeople(Node *root,string FatherName,string NAme) /增加新的家族成員if(root=NULL)
40、/如果這個(gè)家族為空,直接把該結(jié)點(diǎn)置為根結(jié)點(diǎn)Creat( ) ;elseNode *p=new Node;p->=NAme;p->child=NULL;p->brother=NULL;Node *Brother=PreFindBrother(root,FatherName); /兄弟結(jié)點(diǎn)if(root->data.father=FatherName) /如果與祖先(根結(jié)點(diǎn))同一個(gè)父親,則置為根結(jié)點(diǎn)的右兄弟Node *q=root;while(q->brother!=NULL) /尋找根結(jié)點(diǎn)的右兄弟結(jié)點(diǎn)為空的結(jié)點(diǎn)q=q->brother;if(
41、q->brother=NULL) q->brother=p;SetNode(p);Node *Father=PreFindFather(root,FatherName); /父親結(jié)點(diǎn)/Node *Brother=PreFindBrother(root,FatherName); /兄弟結(jié)點(diǎn)if(Father->child=NULL) /如果父親結(jié)點(diǎn)的孩子結(jié)點(diǎn)為空Father->child=p;SetNode(p);else /如果父親結(jié)點(diǎn)的孩子結(jié)點(diǎn)不為空if(Brother->brother=NULL) /最后一個(gè)兄弟結(jié)點(diǎn)Brother->brother=p;
42、SetNode(p);int FamilyTree:DeletePeople(Node *root,string FatherName,string Deletepeople) /刪除家族成員int t=0;Numberofpeople-;if(root=NULL)return t;elseif(root->=Deletepeople) /如果要?jiǎng)h除的為祖先,則調(diào)用Release()函數(shù)t=1;root->brother=NULL;root->child=NULL;Release(root);elseNode *Father=PreFindFather(ro
43、ot,FatherName);Node *Brother=PreFindBrother(root,FatherName); /兄弟結(jié)點(diǎn)Node *p;Node *tree20;int top=0;while(root!=NULL|top!=0)while(root!=NULL)if(root->=Deletepeople)p=root;/break;top+;treetop=root;root=root->child;if(top!=0)root=treetop->brother;top-;if(toupper(p->data.life)='Y
44、') /健在人數(shù)減一LifePeopele-;if(Father->child->=p->)/Deletepeople)Father->child=NULL;elseBrother->brother=NULL;/p->brother=NULL;/p->child=NULL;t=1;delete p;return t;int flag=0; /標(biāo)記int FamilyTree:SetNewName(Node *root,string NAme,string NewName) /更改姓名if(root=NULL)
45、return flag;elseif(root->=NAme)flag=1;root->=NewName;elseSetNewName(root->child,NAme,NewName);SetNewName(root->brother,NAme,NewName);return flag;int FamilyTree:FindChild(Node *root,string NAme) /顯示孩子信息int flag=0;if(root=NULL)return flag ;elseif(root->=NAme)i
46、f(root->child=NULL)return flag;elseflag=1;cout<<root->child-><<" "Node *p;Node *tree20;p=root->child;tree0=p;int top=0;while(p->brother!=NULL)p=p->brother;top+;treetop=p;cout<<p-><<" "cout<<"n是否查看孩子的詳細(xì)信息(是:
47、y,否:n):"char ch;cin>>ch;if(toupper(ch)='Y')Node *q=treetop;while(top>-1)PrintMessage(q);cout<<"n-"<<endl;top-;q=treetop;return flag;void FamilyTree:SaveToFile(Node *root) /保存到文件if(root=NULL)cout<<"家譜為空"<<endl;return ;ofstream ofile;co
48、ut << "請(qǐng)輸入要保存文件的路徑:" << endl;char c = cin.get(); /接收回車(chē)char dir40;cin.getline(dir, 40); ofile.open(dir,ios:app); if (_access(dir, 0) = -1) /系統(tǒng)自帶功能判斷路徑是否有效cout << "輸入路徑不存在!" << endl;return;else/d:test.txt"cout << "已經(jīng)保存全部信息。" << end
49、l;ofile << "姓名" << setw(10) << "性別" << setw(10) << "配偶" << setw(10) << "出生地" << setw(10) << "生日" << setw(10) << "學(xué)歷" << setw(7) << "工作" <<setw(7)
50、<< "父親" <<setw(7) << "健在" << endl;Node *tree20;int top=0;while(root!=NULL|top!=0)while(root!=NULL)ofile<<root-><<setw(10) <<root->data.sex<<setw(10) <<root->data.spouse<< setw(10)<<root->data.b
51、irthPlace<<setw(10) <<root->data.birthDay<<setw(10) <<root->cation<<setw(9) <<root->data.job<<setw(9) <<root->data.father<<setw(9) <<root->data.life<<endl;top+;treetop;treetop=root;root=root->child;if(top!=0)
52、root=treetop->brother;top-;ofile.close();void FamilyTree:FileToFamilyTree(Node *root ) /從文件中讀取cout << "請(qǐng)輸入要讀取文件的路徑:" << endl;ifstream ifile;char c = cin.get(); /讀入任意一個(gè)字符,包括回車(chē)符char dir40; /因?yàn)閏in的>>重載會(huì)跳過(guò)空白字符,包括回車(chē)字符,所以無(wú)法使用>>直接讀入回車(chē)符cin.get(),該成員函數(shù)功能為,從cin讀入一個(gè)字符,并返回ci
53、n.getline(dir, 40); / cin.get(),該成員函數(shù)功能為,從cin讀入一個(gè)字符,并返回ifile.open(dir); /if (_access(dir, 0) = -1)cout << "輸入路徑不存在!" << endl;return;string ch;getline(ifile, ch);cout << ch << endl;Node *tree20;int i=0;while (!ifile.eof() /eof文件末尾/姓名 性別 配偶 出生地 生日 學(xué)歷 工作 父親 健在ifile>
54、>root->>>root->data.sex>>root->data.spouse>>root->data.birthPlace>>root->data.birthDay>>root->cation>>root->data.job>>root->data.father>>root->data.life;treei=root;i+;i-;for(int j=0;j<i;j+)cout<<treej-><<" "<<treej->data.sex<<" "<<treej->data.spouse<<" "<<treej->data.birthPlace<<" "<<treej->data.birthDay<<" "<<treej->cati
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 幼兒教育學(xué) 幼兒教育概述課件
- 打造幼教服務(wù)產(chǎn)業(yè)鏈園區(qū)生態(tài)圈
- 2024-2025學(xué)年下學(xué)期高二生物人教版期末必刷??碱}之生態(tài)系統(tǒng)的物質(zhì)循環(huán)
- 部編版二年級(jí)下冊(cè)第七單元《大象的耳朵》教案
- 8 4 拋物線(xiàn)-2026版53高考數(shù)學(xué)總復(fù)習(xí)A版精煉
- 2025屆河北省唐山市高三二模語(yǔ)文試題(解析版)
- 2024-2025學(xué)年四川省雅安市高三第一次診斷性考試語(yǔ)文試題(解析版)
- 2024-2025學(xué)年山東省威海市文登區(qū)高三第一次模擬語(yǔ)文試題(解析版)
- it項(xiàng)目應(yīng)急預(yù)案
- 信訪(fǎng)問(wèn)題回復(fù)函
- 道路保潔臺(tái)賬管理制度
- 全國(guó)衛(wèi)生健康系統(tǒng)職業(yè)技能競(jìng)賽(預(yù)防接種項(xiàng)目)備考試題庫(kù)-上(單選題部分)
- 模切安全生產(chǎn)培訓(xùn)
- 2025-2030中國(guó)互聯(lián)網(wǎng)行業(yè)市場(chǎng)前景趨勢(shì)及競(jìng)爭(zhēng)格局與投資研究報(bào)告
- 扶貧資產(chǎn)入股協(xié)議書(shū)
- 安寧療護(hù)之疼痛管理
- DBJ51T-041-2015-四川省-建筑節(jié)能門(mén)窗應(yīng)用技術(shù)規(guī)程
- 中國(guó)中鐵股份有限公司內(nèi)部控制運(yùn)行管理辦法試行
- 酒后違紀(jì)違法警示教育
- 四川省 2025屆高考?xì)v史全真模擬試題(含解析)
- 華一光谷2024-2025學(xué)年度9月七年級(jí)英語(yǔ)試題(含答案)
評(píng)論
0/150
提交評(píng)論