I've been spending all night BUILDING various shit.
I'll post it here and would really enjoy some GUIDANCE (not a solution per se) but if that is unavailable then I will just post it for reference I guess :/
Code
#include <iostream>
#include <ctype.h>
#include <string>
using namespace std;
const string EMPTY = "EMPTY";
class person
{
string name;
string birthdate;
char marital;
person *spouse;
person *kids;
person *sibling;
string deathdate;
public:
person (); //HOW MANY OF THESE DO WE REALLY NEED?
void set_name (string input)
{
name = input;
};
void set_birthdate (string input)
{
birthdate = input;
};
void set_marital (char input)
{
marital = input;
};
void set_spouse()
{
spouse = new(person);
};
void set_spouse_name(string input)
{
spouse->name = input;
};
void set_kids()
{
kids = new(person);
};
void set_kids_name(string input)
{
kids->name = input;
};
void set_sibling()
{
sibling = new(person);
};
void set_sibling_name(string input)
{
sibling->name = input;
};
void access_kids(person *&head)
{
head = head->kids;
};
void access_spouse(person *&head)
{
head = head->spouse;
};
void access_sibling(person *&head)
{
head = head->sibling;
};
friend void head_return(person *&head, person *target);
void print_all();
bool search(string input, person *head); //DEFUNCT ATM. TRY TO FIX LATER? (POSSIBLY RETURN VALUE?)
friend void input_handler(string input, person *head); //STILL IN PROGRESS!! ARE WE DOING IT RIGHT??
friend void add_kids(person *&head, string input); //DOES THIS WORK THE RIGHT WAY?? TEST!!
};
person::person()
{
name = EMPTY;
birthdate = EMPTY;
marital = 'x';
spouse = NULL;
kids = NULL;
sibling = NULL;
deathdate = EMPTY;
}
void head_return(person *&head, person *target)
{
head = target;
}
void person::print_all() //THIS IS A FUNCTION FOR TESTING PURPOSES ONLY!!
{
cout << name << endl;
cout << birthdate << endl;
cout << marital<< endl;
if (spouse != NULL)
{
cout << spouse->name << endl;
cout << spouse->birthday << endl;
}
if (kids != NULL)
{
cout << kids->name << endl;
cout << kids->birthday << endl;
}
void add_kids(person *&head, string input)
{
if (head == NULL)
{
head = new(person);
head->name = input;
return;
}
head->access_sibling();
add_kids(head, input);
}
bool person::search(string input, person *head) //SEG FAULTS!! FIX??
{
if (head == NULL)
return false;
if (head->name == input)
{
head->print_all();
return true;
}
if (search(input, spouse))
return true;
else if (search (input, kids))
return true;
else if (search (input, sibling))
return true;
else return false;
}
void input_handler(string input, person *&head)
{
person *root = head;
string temp;
int pos;
while (!input.empty())
{
pos = input.find_first_of(' '); //DONT FORGET THE SPECIAL CASES (X AND QUIT)
temp = input.substr(0, pos-1); //IS THIS THE RIGHT WAY TO ALLOCATE??
if (head->name == EMPTY)
head->name = temp;
else if (head->birthday = EMPTY)
head->birthday = temp;
else if (head->marital == 'x')
head->marital = temp;
else if (head->marital == 'S')
{
if (isalpha(temp[0]))
{
head->access_kids();
add_kids(head, temp);
head_return(head, root);
}
else head->deathday = temp; //IS THIS CORRECT?
if (temp.length() > 1)
{
if (isalpha(temp[0])
{
if (head->name == EMPTY)
head->name = temp;
Don't mind the awkward comments and various gaps of missing code...like I said I haven't made terribly much progress, if ANY at all.