数据结构大作业之家谱管理系统 下载本文

内容发布更新时间 : 2024/5/11 2:33:16星期一 下面是文章的全部内容请认真阅读。

} 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 <