Chciałem sobie zrobić coś a'la drzewo genealogiczne na klasach. Mam problem z dwiema rzeczami.
1. W jaki sposób mam napisać kod żeby można było bez końca wpisywać członków rodziny? W odcinkach Pana Mirosława tworzyliśmy określoną liczbę obiektów. Jak w takim razie napisać kod dla liczby nieokreślonej?
2. W jaki sposób zastosować sortowanie gdy nie używam tablic?
Dla rozjaśnienia sprawy wrzucę swój kod
//
// main.cpp
// Family Tree Creator
//
//
#include <iostream>
class Person{
std::string firstName, lastName;
int birthDay, birthMonth, birthYear;
int deathDay, deathMonth, deathYear;
public:
void enterPerson(){
std::cout << "Enter first name of person: ";
std::cin >> firstName;
std::cout << "Enter last name of person: ";
std::cin >> lastName;
std::cout << "Enter day, month and year of birth (separated by a space): ";
std::cin >> birthDay >> birthMonth >> birthYear;
std::cout << "Enter day, month and year of death (separated by a space): ";
std::cin >> deathDay >> deathMonth >> deathYear;
}
void showPerson(){
std::cout << "Person first and last name: ";
std::cout << firstName << " " << lastName << std::endl;
std::cout << "Birth: " << birthDay << "." << birthMonth << "." << birthYear << std::endl;
std::cout << "Death: " << deathDay << "." << deathMonth << "." << deathYear << std::endl;
}
void sort(){
}
};
int main() {
Person p1;
p1.enterPerson();
p1.showPerson();
return 0;
}