Question: c++ I have the following program from the the image below. #include #include #include #include using namespace std; class Person { string name; list children;

c++
I have the following program from the the image below.
 c++ I have the following program from the the image below.
#include #include #include #include using namespace std; class Person { string name;
#include
#include
#include
#include
using namespace std;
class Person
{
string name;
list children;
public:
Person()
{
name = "";
}
Person(string name) // constructor to create a person with name
{
name = name;
}
string get_name()
{
return name;
}
void setChild(Person* child)
{
children.push_back(child);
}
void displayChildren()
{
cout
for(list ::iterator it = children.begin();
it != children.end(); ++it)
cout get_name()
cout
}
~Person()
{
children.clear();
}
};
list persons;
void displayChildren(string name)
{
for(list ::iterator it = persons.begin() ; it != persons.end(); ++it)
{
if(!name.compare((*it).get_name()))
(*it).displayChildren();
}
}
int main()
{
ifstream in("noah_family.txt");
string father_name, child_name;
in >> father_name >> child_name;
int i = 0;
if(!in)
cout
while(!in.eof())
{
Person child(child_name);
Person* c = new Person;
c = &child;
bool exist = false;
i++;
for(list ::iterator it = persons.begin() ; it != persons.end(); ++it,i++)
{
cout get_name();
if(!father_name.compare((*it).get_name()))
{
(*it).setChild(c);
exist = true;
}
}
if(!exist)
{
Person father(father_name);
father.setChild(c);
persons.push_back(father);
for(list ::iterator it = persons.begin() ; it != persons.end(); ++it,i++)
cout get_name();
}
persons.push_back(child);
in >> father_name >> child_name;
}
in.close();
displayChildren("Noah");
return 0;
}
It is correct besides not displaying any output and that the data is supposed to be loaded in the constructor of the class, I was unsure how to fix these two problems. The goal of this problem is to build on the previous one.
The description for the problem is as follows:
Goal:
Learn how to use recursive functions.
Requirement:
Add displayDescendants() as a public function to the Person class and call it from main() to display all descendants of Noah. (So in main() we no longer call displayChildren().)
/// What your main() should look like.
int main()
{
Person Noah("Noah");
Noah.displayDescendants();
return 0;
}
Output:
The output should be similar to the following display.
Father: Noah
Children: Shem, Japheth, Ham
Father: Shem
Children: Arphaxad
Father: Arphaxad
Children: Shalah
Father: Japheth
Children: Gomer, Magog, Madai, Tubal, Meshech, Tiras
Father: Ham
Children: Cush, Nimrod, Phut, Canaan
The input file Noah_family-1.txt contains the following:
Noah Shem
Noah Japheth
Noah Ham
Shem Arphaxad
Japheth Gomer
Japheth Magog
Japheth Madai
Japheth Tubal
Japheth Meshech
Japheth Tiras
Ham Cush
Ham Nimrod
Ham Phut
Ham Canaan
Arphaxad Shalah
Thank you for your help.
Goal: 1. Learn how to use constructor to load data for the private data members, such as array or vector, of the class. These data are loaded into the objects by using "new" operators and the objects are linked by the array (or vector) pointers. 2. Learn how to use destructor to release dynamically allocated memorY Use class, struct and vector to implement a family tree which is top part of the one below The Genealogy of Noah came to rest on Mt Arrarat (in hem Japheth Ham Europe Fohi or Yao (Noah) Arphaxad Tiras Cush Phut Shalaha Gemer Magog Eber Peleg Reu as Serug Nahor u Terah s Meshech Assyrin llisterical Source Biblieal Records Non-Kiblical Sources Shin-Nong Nahor Abramis Whang-Ti This simplified version of family tree only takes spear side into account. In this HW, there will be only four persons: Noah and his three sons. Input file, named noah_family.txt, has two columns: (1) Haran (Abraham) Lot 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!