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

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.³öÉúµØµã