第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/6/1 9:46:04 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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.出生地点

搜索更多关于: 数据结构大作业之家谱管理系统 的文档
数据结构大作业之家谱管理系统.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c2tkvx2c7s51jxut0i32m_6.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top