HELP!!! Search function

(person.h)
#include <iostream>
#include <string>

using namespace std;

class Person
{

private:
string name;
string birth;
string death;
string marstat;
Person *next;
Person *spouse;
Person *child;

public:
void addName(string);
void addBirth(string);
void addDeath(string);
void addMarstat(string);
void addSpouse (person*);
void addChild (person*);

};

void searchPerson();
void printFamily();



#endif



(header.h)
#include <iostream>
#include "Person.h"

using namespace std;


void addName(string in);
{
name = in;
}
void addBirth(string in);
{
birth = in;
}
void addDeath(string in);
{
death = in;
}
void addMarstat(string in);
{
Marstat=in;
}
void addSpouse (Person* relations);
{
spouse = relations;
}
void addChild (person* spawn);
{
spawn -> next=child;
child = spawn;

}
void searchPerson(string in[], int &size)
{


char searchname;

cout << "Please enter the name to seach for " << endl;
cin >> searchname;

for(int y = 0; y < size; y++)
{
for(int x = 0; x < size - y; x++)
{
int result = strcmp(temp[x].name, searchname);

if (result = 0)
{
cout << setiosflags(ios_base::left) << setw(20) << temp[x].name << setw(15) << temp[x].number
<< resetiosflags(ios_base::left) << setw(10) << setprecision(2) << setiosflags(ios_base::fixed) << temp[x].salary << endl;
}
else
{
cout << "Sorry, no student exists with such name" << endl;

}
}
}
}

void printFamily();


#endif





#include <iostream>
#include "Header.h"
#include <string>


using namespace std;

int main ()
string tempname;
string tempbirth;
string tempmarstat;
string thexfactorX;
string tempsN;
string tempsB;


Person *pPer = NULL;

while (cin >>tempname, tempname != "QUIT")
{

cin>> tempbirth;
cin>> tempmarstat;

Person *mainp = new Person;
if (pPer == NULL)
{

pPer = mainp;

}
mainp -> addName(tempname);
mainp-> addBirth(tempbirth);
mainp -> addMarstat (tempMarstat);

if (tempMarstat == "M")
{
cin >> tempsN;
cin>> tempsB;

Person *other = new Person;
other -> addName(tempsN);
other-> addBirth(tempsB);
mainp-> addSpouse(other);
other-> addSpouse(mainp);


}

while (cin >>tempname, tempname != "X" && !isdigit(tempname[0])){

Person *kid = new Person;
kid -> addName(tempname);
mainp-> addChild(kid);

}

if (tempname != "x")
{
mainp-> addDeath (tempname);
cin >> thexfactorX;
}

}




I need help with creating a search function that will search for the head name then display the name (birthdate-deathdate) spouse (their birthdate) [if M]
followed on the next line and tabbed the children's name if any present.
thanks in advance for any help!!!!!
Firstly, you either need to make all the data members in class Person public or write functions to return their values (eg string person::getName () {return name;}) - as they are private members, you currently have no way of legally accessing them.

Secondly, how are you storing this data (eg in an stl container)? The way you store it alters how you can search for the person.

Thirdly, I'd suggest that your person class actually held pointers to all of its children - not just one of them with indirect connections to all the others.
Topic archived. No new replies allowed.