#include #include #include "Amoeba.h" using namespace std; Amoeba::Amoeba() : name_("anonymous"), generation_(1) { cout << "New anonymous Amoeba" << endl; } Amoeba::Amoeba(const char *name): name_(name), generation_(1) { cout << "New Amoeba: " << FullName() << endl; } Amoeba::~Amoeba() { cout << "Amoeba passed away (RIP): " << FullName() << endl; } Amoeba::Amoeba(const Amoeba &parent) { name_ = parent.name_; generation_ = parent.generation_+1; cout << "Amoeba " << parent.FullName() << " gave birth to "; cout << FullName() << endl; } Amoeba &Amoeba::operator=(const Amoeba &other) { cout << "Amoeba " << FullName() << " adopted by " << other.FullName() << endl; formerly_ = FullName(); name_ = other.name_; generation_ = other.generation_+1; return *this; } bool Amoeba::operator<(const Amoeba &other) const { cout << "Amoeba " << FullName() << " compared to " << other.FullName() << endl; return name_ < other.name_; } std::string Amoeba::FullName(void) const { stringstream ss; ss << name_; if (generation_ == 1) { } else if (generation_ == 2) { ss << " the second"; } else if (generation_ == 3) { ss << " the third"; } else if (generation_ == 4) { ss << " the fourth"; } else if (generation_ == 5) { ss << " the fifth"; } else if (generation_ == 6) { ss << " the sixth"; } else if (generation_ == 7) { ss << " the seventh"; } else if (generation_ == 8) { ss << " the eigth"; } else if (generation_ == 8) { ss << " the ninth"; } else { ss << " gen. " << generation_; } if (!formerly_.empty()) { ss << " (formerly " << formerly_ << ")"; } return ss.str(); } std::ostream &operator<<(std::ostream &out, const Amoeba &critter) { out << critter.FullName(); return out; }