数据结构大作业之家谱管理系统

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 << \修改成员信息.\\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.出生地点

联系客服:779662525#qq.com(#替换为@)