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 &
>>灞曞紑鍏ㄦ枃<<