Êý¾Ý½á¹¹´ó×÷ÒµÖ®¼ÒÆ×¹ÜÀíϵͳ ÏÂÔØ±¾ÎÄ

C++ʵÏÖµÄÊý¾Ý½á¹¹´ó×÷ÒµÖ®¼ÒÆ×¹ÜÀíϵͳ »¶Ó­½çÃæ£º

Ö÷²Ëµ¥:

ÆäËûһЩÔËÐнá¹û²»ÔÚÒ»Ò»Áо٣¬Ò»ÃæÆª·ù¹ý³¤¡£

Õâ¸ö¼ÒÆ×¹ÜÀíϵͳ£¬Ö§³Ö¼üÅ̲Ù×÷£¬ËùÓеIJÙ×÷¶¼¿ÉÒÔÓüüÅÌÍê³É£¬ÈçÑ¡Ôñ¹¦ÄÜ¡¢Í˳öµÈ¡£´úÂëµÄʵÏÖʹÓõÄÊÇc++11±ê×¼£¬Óë¾É±ê×¼»òÓв»Í¬¡£

ÀàµÄÍ·Îļþ£º

#include #include using std::string; using std::ostream; using std::istream; struct BirthDay{ //ÉúÈսṹ±äÁ¿ int year=0; int month=0; int day=0; }; class Member{ friend class FamilySystem; friend ostream &operator<<(ostream &out, const Member &m);//Êä³ö³ÉÔ±ÐÅÏ¢µ½¿ØÖÆÌ¨ friend istream &operator>>(istream &in, Member &m);//´ÓÎļþÖжÁÈë³ÉÔ±ÐÅÏ¢ public: Member()=default;//ʹÓÃĬÈϺϳɹ¹Ô캯Êý void setE();//ͨ¹ý¿ØÖÆÌ¨ÊäÈë¸ø³ÉÔ±¸³Öµ ~Member() = default;//ʹÓÃĬÈϺϳÉÎö¹¹º¯Êý Member* pson=nullptr;//Ö¸Ïò¶ù×ÓµÄÖ¸Õë Member* pbro = nullptr;//Ö¸ÏòÐֵܵÄÖ¸Õë private: //³ÉÔ±µÄ¸÷ÖÖÊý¾Ý string name=\δ֪\; string birthPlace = \δ֪\; BirthDay birthDay; string sex = \δ֪\; float height=0; int age=0; string education = \δ֪\; string job = \δ֪\; string father = \δ֪\; }; class FamilySystem{ public: FamilySystem() = default;//ʹÓÃĬÈϺϳɹ¹Ô캯Êý ~FamilySystem(){ delete root; } bool fileInit();//´ÓÎļþÖжÁÈ¡Êý¾Ý int menu();//ÏÔʾ²Ëµ¥£¨¹¦ÄÜ£© bool addMem();//Ôö¼Ó³ÉÔ± bool deleteMem();//ɾ³ý³ÉÔ± bool demandMem();//²éѯ bool demandAve();//²éѯ¼ÒÍ¥ÕûÌåÇé¿ö bool modifyMem();//Ð޸ijÉÔ± bool showFamily();//չʾÕû¸ö¼ÒÆ× bool saveFile();//±£´æÐÅÏ¢µ½ÎļþÖУ¬½«Ê¹ÓÃÁ½¸öÎļþ£¬Ò»¸ö±£´æ³ÉÔ±ÐÅÏ¢£¬Ò»¸ö±£´æ¼ÒÆ×ÕûÌåÐÅÏ¢ Member* root = nullptr;//¼ÒÆ×Êý½á¹¹µÄ¸ù½ÚµãÖ¸Õë? private: int total = 0;//×ÜÈËÊý float aveAge=0;//ƽ¾ùÄêÁä float aveHeight=0;//ƽ¾ùÉí¸ß float aveMember=0;//¼Òͥƽ¾ùÈËÊý float ratio=0;//ÄÐÅ®±ÈÀý void calculate();//¼ÆËãÆ½¾ùÖµµÈ Member *seek(string);//²éÕÒÊÇ·ñ´æÔÚ³ÉÔ± void display(Member*, int);//ÏÈÐò±éÀúÊ÷£¬ÓÃÓÚÏÔʾËùÓгÉÔ± }; extern string gets();//ÓÃÓÚ½ÓÊÕ¼üÅ̵ÄÊäÈë

ÀàµÄº¯Êý¼°Ïà¹Ø²Ù×÷º¯ÊýµÄʵÏÖ

#include #include #include #include #include #include\ using std::cin; using std::cout; using std::endl; using std::setw; using std::vector; using std::ios; using std::ifstream; using std::ofstream; using std::istringstream; string gets(){//´Ó¿ØÖÆÌ¨»ñÈ¡×Ö·ûµÈÐÅÏ¢ string s; while (int n = _getch()){ if (n == 27){ throw 27; break; } else if (n == 13){ cout << endl; break; } else if (n == 8){ s.pop_back(); cout << \; } else{ cout << char(n); s.push_back(char(n)); } } return s; } //ÓëBirthDayÏà¹ØµÄº¯Êý istream &operator>>(istream &in, BirthDay &b){//´ÓÎļþÖжÁÈ¡ÉúÈÕµÄÐÅÏ¢ in >> b.year >> b.month >> b.day; return in; } ostream &operator<<(ostream &out, BirthDay &b){ out << b.year << \ << b.month << \ << b.day; return out; } //ÓëMemberÏà¹ØµÄº¯Êý void Member::setE(){ try{ istringstream sin; cout << setw(20) << \ÇëÊäÈë³ÉÔ±ÐÅÏ¢£º\\n\ << endl << setw(20) << \ÐÕÃû£º\; sin.str(gets()); sin >> name; cout << endl << setw(20) << \³öÉúµØ£º\;

sin.str(gets()); sin.clear(); sin >> birthPlace; cout << endl << setw(20) << \ÉúÈÕ£º\; sin.str(gets()); while (true){ sin.clear(); sin >> birthDay.year >> birthDay.month >> birthDay.day; if ( !sin||birthDay.year > 2014 || birthDay.month > 12 || birthDay.day > 31){ cout << \ÊäÈë´íÎó£¬ÇëÖØÐÂÊäÈë:\; sin.str(gets()); } else break; } cout << endl << setw(20) << \ÐÔ±ð:\; sin.str(gets()); sin.clear(); while (sin >> sex){ if (sex == \ || sex == \ || sex == \ÄÐ\ || sex == \Å®\) break; else{ cout << \ÐÔ±ð±ØÐëÊÇmale¡¢female¡¢ÄлòÕßÅ®£¬ÇëÖØÐÂÊäÈë:\; sin.str(gets()); sin.clear(); } } cout << endl << setw(20) << \Éí¸ß(ÀåÃ×):\; sin.str(gets()); sin.clear(); while (!(sin >> height)){ cout << \ÊäÈë´íÎó£¬ÇëÖØÐÂÊäÈë:\; sin.str(gets()); sin.clear(); } cout << endl << setw(20) << \ÄêÁä:\; sin.str(gets()); sin.clear(); while (!(sin >> age) || age > 300){ cout << \ÊäÈë´íÎó£¬ÇëÖØÐÂÊäÈë:\ << endl; sin.str(gets()); sin.clear(); } cout << endl << setw(20) << \ѧÀú:\;

sin.str(gets()); sin.clear(); sin >> education; cout << endl << setw(20) << \¹¤×÷:\; sin.str(gets()); sin.clear(); sin >> job; cout << endl << setw(20) << \¸¸Ç×:\; sin.str(gets()); sin.clear(); sin >> father; } catch (int ex){ throw ex; } return; } ostream &operator<<(ostream &out, const Member

&m){ out << endl << setw(25) << \¸Ã³ÉÔ±ÐÅÏ¢ÈçÏÂ:\ << endl <>(istream &in, Member &m){ in >> m.name >> m.birthPlace >> m.birthDay >> m.sex >> m.height >> m.age >> m.education >> m.job >> m.father; return in; } //FamilySystemµÄ³ÉÔ±º¯Êý int FamilySystem::menu(){ cout << \; cout << \---------------------------\\n\; cout << \|\\n\; cout << \ϵͳ²Ëµ¥ |\\n\; cout << \|\\n\; cout << \²éѯ³ÉÔ± |\\n\; cout << \|\\n\; cout << \²éѯ¼ÒÍ¥ÕûÌåÇé¿ö |\\n\; cout << \|\\n\; cout << \Ìí¼Ó³ÉÔ± |\\n\; cout << \|\\n\; cout << \ɾ³ý

³ÉÔ± |\\n\; cout << \|\\n\; cout << \Ð޸ijÉÔ±ÐÅÏ¢ |\\n\; cout << \|\\n\; cout << \ÏÔʾÕû¸ö¼ÒÆ× |\\n\; cout << \|\\n\; cout << \°´ESCÍ˳öϵͳ |\\n\; cout << \|\\n\; cout << \---------------------------\\n\; cout << \; int n = 0; while (1){ n = _getch(); if (n == 27) break; if (n >= 49 &&n<=54) break; cout << \Çë°´ÏÂ1¡¢2¡¢3¡¢4¡¢5¡¢6Ñ¡Ôñ»ò°´ESC¼üÍ˳ö!\ << endl; } return n; } bool FamilySystem::fileInit(){ ifstream infile; //´ò¿ª´æ´¢³ÉÔ±ÐÅÏ¢µÄÎļþ£¬¶ÁÈë³ÉÔ±ÐÅÏ¢ infile.open(\, ios::in | ios::_Nocreate); if (!infile){ return false; } vector genely;//±£´æÕâÒ»´ú³ÉÔ±µÄÖ¸Õë vector next;//±£´æÏÂÒ»´ú³ÉÔ±µÄÖ¸Õë Member *temp = new Member;//ÁÙʱ±£´æÊäÈëµÄ³ÉÔ±ÐÅÏ¢ root = temp;//µÚÒ»¸ö¸³¸øroot genely.push_back(root); next.push_back(root); while (infile >> *temp){ //½«³ÉÔ±·ÅÈë¼Ò×åÊ÷ÖÐ,³ÉÔ±µÄ¸¸Ç×±ØÐëÊÇÕâÒ»´úµÄ³ÉÔ± for (auto i = genely.begin(); i != genely.end(); ++i){ if ((*i)->name == temp->father){ if ((*i)->pson==nullptr) (*i)->pson = temp; else{ Member *p = (*i)->pson; while (p->pbro!=nullptr) p = p->pbro; p->pbro = temp; } next.push_back(temp); temp = nullptr; break; } } //Èô³ÉÔ±µÄ¸¸Çײ»ÊÇÕâÒ»´úµÄ³ÉÔ±£¬Ôò½«next¸³Óègenely,µü½øÏÂÒ»´ú if (temp != nullptr){ genely = next;//µü½øÏÂÒ»´ú next.clear();//Çå¿Õnext for (auto i : genely){//½«³ÉÔ±·ÅÈë¼Ò×åÊ÷ÖÐ if (i->name == temp->father){ i->pson = temp; next.push_back(temp); temp = nullptr; break; } } } //¶¯Ì¬´´½¨ÁÙʱ³ÉÔ±±äÁ¿,ÓÃÓÚ´æ´¢ÊäÈëµÄÏÂÒ»¸ö³ÉÔ±µÄÐÅÏ¢

temp = new Member; } infile.close();//¹Ø±Õ´æ´¢³ÉÔ±ÐÅÏ¢µÄÎļþ //ÈôÎļþÖÐûÓгÉÔ±ÐÅÏ¢£¬½«rootÖÃΪ¿Õ if (root->name == \δ֪\) root = nullptr; //´ò¿ª´æ´¢¼ÒÍ¥×ÜÌåÐÅÏ¢µÄÎļþ£¬¶ÁÈëÐÅÏ¢ infile.open(\, ios::in | ios::_Nocreate); if (!infile){ return false; } infile >> total >> aveAge >> aveHeight >> aveMember >> ratio; infile.close();//¹Ø±ÕÎļþ return true; } Member *FamilySystem::seek(string nam){ //Èô¼ÒÆ×Ê÷Ϊ¿Õ£¬·µ»Ø¿ÕÖ¸Õë if (root == nullptr) return nullptr; //Èôroot²»Îª¿Õ£¬¼ÌÐø²éÕÒ Member *store = nullptr;//´æ´¢·µ»ØµÄÖ¸Õë vector genely;//´æ´¢ÕâÒ»´úµÄÖ¸Õë genely.push_back(root); vector next;//´æ´¢ÏÂÒ»´úµÄÖ¸Õë for (;;){//Ñ­»·²éÕÒ //ÔÚÕâÒ»´úÖвéÕÒ£¬ÈôÕÒµ½£¬Ìøµ½×îºó for (auto p : genely){ if (p->name == nam){ store = p; goto End; } } //ÅжÏÏÂÒ»´úÊÇ·ñΪ¿Õ£¬ÈôΪ¿Õ£¬Ìøµ½×îºó int jubge = 0; for (auto p : genely){ if (p->pson != nullptr) ++jubge; } if (jubge == 0) goto End; //ÕÒµ½ÏÂÒ»´ú for (auto p : genely){ Member *temp = p->pson; if (temp==nullptr) continue; else{ next.push_back(temp); while (temp->pbro != nullptr){ next.push_back(temp->pbro); temp = temp->pbro; } } } genely = next; next.clear(); } End:return store; } bool FamilySystem::addMem(){ cout << \Ìí¼Ó³ÉÔ±.\\n\; Member *temp=new Member; try{ temp->setE();//ÊäÈë³ÉÔ±ÐÅÏ¢ } catch (int){ return false; } //¼ì²éÆä¸¸Ç×ÊÇ·ñ´æÔÚ Member *jubge = seek(temp->father); if (root == nullptr) root = temp; else if (jubge == nullptr){ cout << \¼ÒÆ×ÖÐûÓдËÈ˸¸Ç×µÄÐÅÏ¢£¡ÎÞ·¨²åÈ룡\; cout << \ÇëÈ·ÈÏ´ËÈËÊÇ·ñ´Ë¼Ò×åÖеÄÈË£¡\; } else { if (seek(temp->name) != nullptr){ cout << \´ËÈËÒÑ´æÔÚÓÚ¼ÒÆ×ÖУ¡\ << endl; } else{ cout << \°´ENTERÈ·¶¨Ìí¼Ó²¢·µ»Ø²Ëµ¥\\n °´ESCÈ¡ÏûÌí¼Ó²¢·µ»Ø²Ëµ¥\; for (;;){ int j = _getch(); if (j == 27){ delete temp; break; } if (j == 13){ if (jubge->pson == nullptr) jubge->pson = temp; else{ Member *p = jubge->pson; while (p->pbro != nullptr) p = p->pbro; p->pbro = temp; } cout << \±£´æ³É¹¦!\\n\; break; } } } } cout << \°´ESC¼ü·µ»Ø²Ëµ¥\; for (;;){ if (_getch() == 27) break; } return true; } bool FamilySystem::deleteMem(){ cout << \ɾ³ý³ÉÔ±.\\n\\n\; cout << \ÇëÊäÈëÐÕÃû:\; string na; try{ istringstream sin(gets()); sin >> na; } catch (int){ goto end; } Member *temp = seek(na); if (temp == nullptr) cout << \¼ÒÆ×ÖÐûÓдËÈË£¡\\n\\n\; else{ if (temp->pson != nullptr){ cout << \´ËÈËÓкó´ú£¡Èôɾ³ý´ËÈËÆäºó´ú½«Í¬Ê±±»É¾£¡\; cout << \°´ENTER¼ÌÐø\\n °´ESCÍ˳ö\; for (;;){ int j = _getch(); if ( j== 27) return false; if (j == 13) break; } } Member *p = seek(temp->father); if (p == nullptr) root = nullptr; else if (temp == p->pson) p->pson = nullptr; else{ while (p->pbro!=temp){ p = p->pbro; } p->pbro = nullptr; } cout << \ɾ³ý³É¹¦£¡\\n\\n\; } cout<<\°´ESC¼ü·µ»Ø²Ëµ¥\; for (;;){ if (_getch() == 27) break; } end:return true; } bool FamilySystem::demandMem(){ cout << \²éѯ³ÉÔ±.\\n\\n\; cout << \ÇëÊäÈëÐÕÃû:\; string na; try{ istringstream sin(gets()); sin >> na; } catch (int){ goto end; } Member *m=seek(na); if(m!=nullptr) cout << *m; else cout << \¶Ô²»Æð£¬¼ÒÆ×ÖÐûÓдËÈ˵ÄÐÅÏ¢£¡\\n\\n\; cout << \°´ESC¼ü·µ»Ø²Ëµ¥\; for (;;){ if (_getch() == 27) break; } end:return true; } void FamilySystem::calculate(){ //Èô¼ÒÆ×Ê÷Ϊ¿Õ£¬½«¸÷×ÜÌåÖµÖÃÁã if (root == nullptr){ total = 0; aveAge = 0; aveHeight = 0; aveMember = 0; ratio = 0; return; } //Èôroot²»Îª¿Õ£¬¼ÌÐø vector genely;//´æ´¢ÕâÒ»´úµÄÖ¸Õë genely.push_back(root); vector next;//´æ´¢ÏÂÒ»´úµÄÖ¸Õë int girl = 0;//Å®ÐÔÊý int family = 0;//¼ÒÍ¥Êý total = 0; aveAge = 0; aveHeight = 0;//initialize for (;;){//Ñ­»·µþ¼Ó¸÷ËùÐè×ÜÌåÊý¾Ý //ÔÚÕâÒ»´úÖÐ for (auto p : genely){ ++total; aveAge += p->age; aveHeight += p->height; if (p->sex == \ || p->sex == \Å®\) ++girl; } //ÅжÏÏÂÒ»´úÊÇ·ñΪ¿Õ£¬ÈôΪ¿Õ£¬Ìøµ½×îºó int jubge = 0; for (auto p : genely){ if (p->pson != nullptr){ ++jubge; ++family; } } if (jubge == 0) goto cal; //ÕÒµ½ÏÂÒ»´ú for (auto p : genely){ Member *temp = p->pson; if (temp == nullptr) continue; else{ next.push_back(temp); while (temp->pbro != nullptr){ next.push_back(temp->pbro); temp = temp->pbro; } } } genely = next;//µü½øÏÂÒ»´ú next.clear();//Çå¿Õnext } //¼ÆËã×îºó½á¹û cal:total = total; aveAge /= total; aveHeight /= total; if (family == 0) family = 1; aveMember = static_cast(total) / static_cast(family); if (girl!=0) ratio = static_cast(total - girl) / static_cast(girl); else ratio = 0; //Í˳ö return; } bool FamilySystem::demandAve(){ calculate(); cout << \²éѯ¼ÒÍ¥ÕûÌåÇé¿ö.\\n\; cout << endl << endl; cout << setw(30) << \¼ÒÍ¥µÄÕûÌåÇé¿öÈçÏ£º\\t\ << endl << endl << endl; cout << setw(30) << \×ÜÈËÊý:\\t\ << total << endl << endl << endl; cout << setw(30) << \ƽ¾ùÄêÁä:\\t\ << aveAge << endl << endl << endl; cout << setw(30) << \ƽ¾ùÉí¸ß:\\t\ << aveHeight << endl << endl << endl; cout << setw(30) << \¼Òͥƽ¾ùÈËÊý:\\t\ << aveMember << endl << endl << endl; cout << setw(30) << \ÄÐÅ®±ÈÀý:\\t\ << ratio; if( ratio!=0 ) cout << \ << endl; else cout << endl; cout << \°´ESC¼ü·µ»Ø²Ëµ¥\; for (;;){ if (_getch() == 27) break; } return true; } bool FamilySystem::modifyMem(){ cout << \Ð޸ijÉÔ±ÐÅÏ¢.\\n\\n\; cout << \ÇëÊäÈëÐÕÃû:\; string na; try{ istringstream sin(gets()); sin >> na; } catch (int){ goto rend; } Member *temp = seek(na); if (temp == nullptr){ cout << \¼ÒÆ×ÖÐûÓдËÈ˵ÄÐÅÏ¢£¡\\n\; goto end; } cout << \Ñ¡ÔñÐÞ¸ÄÏ\\n\\n\; cout << \ÐÕÃû 2.³öÉúµØµã

3.ÉúÈÕ\\n\\n\; cout << \ÐÔ±ð 5.Éí¸ß 6.ÄêÁä\\n\\n\; cout << \ѧÀú 8.¹¤×÷ \\n\\n\; cout << \°´ESC¼üÍ˳öÐÞ¸Ä\\n\\n\; for (;;){ int get = _getch(); if (get == 27) break; switch (get){ case 49: cout << \ÐÕÃûԭΪ£º\ << temp->name; cout << \ÇëÊäÈë¸ü¸Ä£º\; cin >> temp->name; if (temp->pson == nullptr) break; else{ string na = temp->name; temp=temp->pson; temp->father = na; while (temp->pbro != nullptr){ temp = temp->pbro; temp->father = na; } break; } case 50: cout << \³öÉúµØµãԭΪ£º\ <<

temp->birthPlace; cout << \ÇëÊäÈë¸ü¸Ä£º\; cin >> temp->birthDay; break; case 51: cout << \ÉúÈÕԭΪ£º\ << temp->birthDay; cout << \ÇëÊäÈë¸ü¸Ä£º\; cin >> temp->birthDay; break; case 52: cout << \ÐÔ±ðԭΪ£º\ << temp->sex; cout << \ÇëÊäÈë¸ü¸Ä£º\; cin >> temp->sex; while (temp->sex != \&&temp->sex != \&& temp->sex != \ÄÐ\&&temp->sex != \Å®\){ cout << \ÊäÈë´íÎó£¬ÐÔ±ð±ØÐëΪmale¡¢female¡¢ÄлòÅ®£¡\\nÇëÖØÐÂÊäÈ룺\; cin >> temp->sex; } break; case 53: cout << \Éí¸ßԭΪ£º\ << temp->height; cout << \ÇëÊäÈë¸ü¸Ä£º\; cin >> temp->height; break; case 54: cout << \ÄêÁäԭΪ£º\ << temp->age; cout << \ÇëÊäÈë¸ü¸Ä£º\; cin >> temp->age; break; case 55: cout << \ѧÀúԭΪ£º\ << temp->education; cout << \ÇëÊäÈë¸ü¸Ä£º\; cin >> temp->education; break; case 56: cout << \¹¤×÷ԭΪ£º\ << temp->job; cout << \ÇëÊäÈë¸ü¸Ä£º\; cin >> temp->job; break; default:; } cout << \Ð޸ijɹ¦£¡\; } end:cout<<\°´ESC¼ü·µ»Ø²Ëµ¥\; for (;;){ if (_getch() == 27) break; } rend:return true; } void FamilySystem::display(Member *r, int n){ string blank=\; for (int i = 0; i != n; ++i) blank += \; cout << blank<name<pson!=nullptr) display(r->pson, n + 6); if (r->pbro != nullptr) display(r->pbro, n); return; } bool FamilySystem::showFamily(){ cout << \ÏÔʾÕû¸ö¼ÒÆ×.\\n\\n\; if (root == nullptr) cout << \¼ÒÆ×Ϊ¿Õ£¡\\n\\n\; else display(root, 0); //escape cout << \°´ESC¼ü·µ»Ø²Ëµ¥\; for (;;){ if (_getch() == 27) break; } return true; } bool FamilySystem::saveFile(){ ofstream outfile; //´ò¿ª±£´æ¼ÒÍ¥ÐÅÏ¢µÄÎļþ£¬²¢Ð´ÈëÐÅÏ¢ outfile.open(\, ios::out); if (!outfile){ return false; } calculate(); outfile << total << \ << aveAge << \ << aveHeight << \ << aveMember << \ << ratio; outfile.close(); //´ò¿ª±£´æ¼ÒÍ¥³ÉÔ±ÐÅÏ¢µÄÎļþ²¢Ð´ÈëÐÅÏ¢ outfile.open(\, ios::out); if (!outfile){ return false; } vector genely;//±£´æÒ»´ú³ÉÔ±µÄÖ¸Õë genely.push_back(root); while (1){ //Êä³öÕâÒ»´ú³ÉÔ±µÄÐÅÏ¢ for (auto p : genely){ if (p != nullptr){ outfile << p->name << \\ << p->birthPlace << \ \

<< p->birthDay << \ << p->sex << \ << p->height << \ << p->age << \ << p->job << \ << p->education << \ << p->father << endl; } } //¼ÆËãÕâÒ»´ú³ÉÔ±µÄ¶ùÅ®µÄÈËÊý //ÈôÕâÒ»´ú¶¼Ã»ÓжùÅ®£¬ÔòÍ˳ö int jubge = 0; for (auto p : genely){ if (p != nullptr){ if (p->pson != nullptr) ++jubge; } } if (jubge == 0) break; //ÕÒµ½ÏÂÒ»´úµÄ³ÉÔ±£¬¼´ÕâÒ»´úµÄ¶ùÅ® vector next; for (auto p : genely){ Member *temp=p->pson; if (temp!= nullptr){ next.push_back(temp); while (temp->pbro != nullptr){ next.push_back(temp->pbro); temp = temp->pbro; } } } genely = next;//µü½øÏÂÒ»´ú next.clear(); } return true; }

Ö÷º¯Êý¼°»¶Ó­½çÃæµÄʵÏÖ #include #include\ using std::cout; using std::endl; using std::flush; int main(){ //ÏÔʾϵͳ»¶Ó­½çÃæ void welcome(); system(\);//½«ÏµÍ³±³¾°ÑÕÉ«ÖÃΪºÚÉ«£¬Ç°¾°°µÂÌÉ« welcome(); //»­ÃæÍ£Áô3Ãë const time_t start = time(0); while (1){ time_t current = time(0); if (current - start == 3) break; } FamilySystem genealogy;//³ÌÐòΨһµÄÒ»¸ö¼ÒÆ×¶ÔÏó //´ÓÎļþÖжÁÈ¡³ö¼ÒÍ¥³ÉÔ±µÄÐÅÏ¢£¬Èô¶ÁÈ¡²»³É¹¦£¬ÔòÇ¿ÖÆÍ˳ö³ÌÐò if (!genealogy.fileInit()){ system(\); //Êä³ö´íÎóÐÅÏ¢ for (int i = 0; i != 10; ++i) cout << \; string str = \; cout <

genealogy.showFamily(); break;//Ñ¡Ôñ²Ëµ¥Ïî6 default: ; } } //±£´æÐÅÏ¢µ½ÎļþÖУ¬Èô·¢Éú´íÎó£¬Ôòµ±Ç°Ëù×öÐ޸IJ»±£´æ²¢Ç¿ÖÆÍ˳ö³ÌÐò if (!genealogy.saveFile()){ system(\); //Êä³ö´íÎóÐÅÏ¢ for (int i = 0; i != 12; ++i) cout << \; cout << \±£´æÎļþʱ·¢Éú´íÎó£¬ËùÓй¤×÷½«¶ªÊ§£¡\\n¼´½«Ç¿ÖÆÍ˳ö¡¤¡¤¡¤\<

\***************************\\n\, \*\\n\, \*\\n\, \*\\n\, \*** * ** ** *\\n\, \* * * * *\\n\, \* * * * *\\n\, \* * * *\\n\, \* * * *\\n\, \* * * * *\\n\, \* *** ****** *** *\\n\, \*\\n\, \******* * * *\\n\, \* * * * * *\\n\, \* * * * * *\\n\, \******* * * * *\\n\, \* * * * *\\n\, \* * * *\\n\, \******* * * *\\n\, \*\\n\, \*\\n\, \*\\n\,

\***************************\\n\ }; cout << endl; for (const auto &i:wel) cout << \<