summaryrefslogtreecommitdiff
path: root/src/Test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Test.cc')
-rw-r--r--src/Test.cc348
1 files changed, 348 insertions, 0 deletions
diff --git a/src/Test.cc b/src/Test.cc
new file mode 100644
index 0000000..9fa1e9d
--- /dev/null
+++ b/src/Test.cc
@@ -0,0 +1,348 @@
+#include <iostream>
+#include <variant>
+#include <vector>
+
+#include "Cage.hh"
+#include "Mammal.hh"
+#include "Zoo.hh"
+
+namespace zoo {
+template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
+template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
+} // namespace zoo
+
+int main() {
+ zoo::Zoo zoo;
+ std::vector<zoo::Cage> cages;
+ std::vector<std::variant<zoo::ZooAnimal, zoo::Mammal>> zooAnimals;
+
+ // Prompt the user to enter up to ten exhibits at the Zoo
+ std::cout << "enter up to ten exhibit names (negative number to finish):"
+ << std::endl;
+
+ for (int i = 0; i < 10; ++i) {
+ std::string exhibit;
+
+ std::cout << "exhibit name #" << i + 1 << ": ";
+
+ std::getline(std::cin, exhibit);
+
+ if (exhibit.starts_with('-')) {
+ break;
+ }
+
+ zoo.setExhibit(exhibit);
+ }
+
+ // Prompt the user to enter up to ten cages at the zoo
+ std::cout << "\nenter up to ten cage numbers (negative number to finish):"
+ << std::endl;
+
+ for (int i = 0; i < 10; ++i) {
+ int cageNumber;
+ zoo::Cage cage(0, 0, "", &zoo);
+
+ std::cout << "cage number #" << i + 1 << ": ";
+ std::cin >> cageNumber;
+
+ if (cageNumber < 0) {
+ break;
+ }
+
+ zoo.setCage(cageNumber);
+ cage.setCageNumber(cageNumber);
+ cages.emplace_back(cage);
+ }
+
+ // Prompt the user to add information to each of the cages
+ if (zoo.getNumCages() > 0) {
+ std::cout << "\nadd information to each of the cages:" << std::endl;
+
+ for (;;) {
+ int cageNumber;
+ std::string cageLocation;
+ int cageSquareFootage;
+
+ std::cout << "available cages numbers: ";
+
+ for (std::size_t i = 0; i < static_cast<std::size_t>(zoo.getNumCages());
+ ++i) {
+ std::cout << *zoo.getCage(i) << " ";
+ }
+
+ // Various mechanisms have been put in place to ensure that the user's
+ // choice of cage to edit is a valid cage number which exists in the zoo
+ // before it can be added as a cage.
+ std::cout
+ << "\ncage number to edit (negative number to finish, -1 to go one "
+ "by one): ";
+ std::cin >> cageNumber;
+
+ if (cageNumber == -1) {
+ for (std::size_t i = 0; i < static_cast<std::size_t>(zoo.getNumCages());
+ ++i) {
+ std::cout << "cage #" << *zoo.getCage(i) << "'s location: ";
+
+ std::cin.ignore();
+ std::getline(std::cin, cageLocation);
+
+ std::cout << "cage #" << *zoo.getCage(i) << "'s square footage: ";
+ std::cin >> cageSquareFootage;
+
+ // Make sure the square footage of the cage is within the 2 to 100000
+ // range
+ if (cageSquareFootage < 2 || cageSquareFootage > 100000) {
+ std::cout << "invalid cage squared footage: must be in range of "
+ "2-100000, try again."
+ << std::endl;
+
+ i -= 1;
+
+ continue;
+ }
+
+ cages.at(i).setCageLocation(cageLocation);
+ cages.at(i).setCageSqFt(cageSquareFootage);
+ }
+
+ break;
+ }
+
+ for (std::size_t i = 0; i < static_cast<std::size_t>(zoo.getNumCages());
+ ++i) {
+ if (*zoo.getCage(i) == cageNumber) {
+ std::cout << "cage #" << *zoo.getCage(i) << "'s location: ";
+
+ std::cin.ignore();
+ std::getline(std::cin, cageLocation);
+
+ std::cout << "cage #" << *zoo.getCage(i) << "'s square footage: ";
+ std::cin >> cageSquareFootage;
+
+ cages.at(i).setCageLocation(cageLocation);
+ cages.at(i).setCageSqFt(cageSquareFootage);
+ }
+ }
+
+ if (cageNumber < 0) {
+ break;
+ }
+ }
+ }
+
+ // Prompt the user to add up to twenty animals to the zoo
+ std::cout << "\nadd up to twenty animals and/ or mammals to the zoo "
+ "(negative number to finish):"
+ << std::endl;
+
+ for (int i = 0; i < 20; ++i) {
+ int idNumber;
+ int cageNumber;
+ int dateAcquired;
+ std::string species;
+ bool isMammal;
+ std::string exhibit;
+ std::string name;
+ int cageSizeMin;
+
+ std::cout << "animal/ mammal #" << i + 1 << " id number: ";
+ std::cin >> idNumber;
+
+ if (idNumber < 0) {
+ break;
+ }
+
+ std::cout << "animal/ mammal #" << i + 1 << " cage number: ";
+ std::cin >> cageNumber;
+ std::cout << "animal/ mammal #" << i + 1 << " date acquired: ";
+ std::cin >> dateAcquired;
+ std::cout << "animal/ mammal #" << i + 1 << " species: ";
+
+ std::cin.ignore();
+ std::getline(std::cin, species);
+
+ std::cout << "is this animal a mammal? (0 = no, 1 = yes): ";
+ std::cin >> isMammal;
+
+ if (isMammal) {
+ zoo::Mammal mammal = zoo::Mammal("", "", 0, idNumber, cageNumber,
+ dateAcquired, species, &zoo);
+
+ std::cout << "mammal #" << i + 1 << " exhibit: ";
+
+ std::cin.ignore();
+ std::getline(std::cin, exhibit);
+
+ std::cout << "mammal #" << i + 1 << " name: ";
+
+ std::getline(std::cin, name);
+
+ std::cout << "mammal #" << i + 1 << " minimum cage size: ";
+ std::cin >> cageSizeMin;
+
+ mammal.setExhibit(exhibit);
+ mammal.setName(name);
+ mammal.setCageSizeMin(cageSizeMin);
+ zooAnimals.emplace_back(mammal);
+ } else {
+ zoo::ZooAnimal zooAnimal =
+ zoo::ZooAnimal(idNumber, cageNumber, dateAcquired, species, &zoo);
+
+ zooAnimal.setIDNum(idNumber);
+ zooAnimal.setCageNum(cageNumber);
+ zooAnimal.setDateAcq(dateAcquired);
+ zooAnimal.setSpecies(species);
+ zooAnimals.emplace_back(zooAnimal);
+ }
+ }
+
+ // Display all the information about the zoo, cage, zoo animals, and mammals
+ // owned by the zoo
+ std::cout << "\nzoo:" << std::endl;
+
+ if (zoo.getNumExhibits() > 0) {
+ std::cout << " exhibits:" << std::endl;
+
+ for (std::size_t i = 0; i < static_cast<std::size_t>(zoo.getNumExhibits());
+ ++i) {
+ std::cout << " exhibit #" << i + 1 << " name: " << *zoo.getExhibit(i)
+ << std::endl;
+ }
+
+ std::cout << std::endl;
+ } else {
+ std::cout << " there were no exhibits at the zoo\n" << std::endl;
+ }
+
+ if (zoo.getNumCages() > 0) {
+ std::cout << " cages:" << std::endl;
+
+ for (std::size_t i = 0; i < static_cast<std::size_t>(zoo.getNumCages());
+ ++i) {
+ std::cout << " cage #" << i + 1
+ << ":\n number: " << cages.at(i).getCageNumber()
+ << "\n square footage: " << cages.at(i).getCageSqFt()
+ << "\n location: " << cages.at(i).getCageLocation()
+ << std::endl;
+ }
+
+ std::cout << std::endl;
+ } else {
+ std::cout << " there were no cages at the zoo\n" << std::endl;
+ }
+
+ if (!zooAnimals.empty()) {
+ std::cout << " animals and/ or mammals:" << std::endl;
+
+ for (std::size_t i = 0; i < zooAnimals.size(); ++i) {
+ std::visit(zoo::overloaded{
+ [&](zoo::Mammal &animal) {
+ std::cout
+ << " mammal #" << i + 1
+ << ":\n id number: " << animal.getIDNum()
+ << "\n cage number: " << animal.getCageNum()
+ << "\n date acquired: " << animal.getDateAcq()
+ << "\n species: " << animal.getSpecies()
+ << "\n exhibit: " << animal.getExhibit()
+ << "\n name: " << animal.getName()
+ << "\n minimum cage size: "
+ << animal.getCageSizeMin();
+ },
+ [&](zoo::ZooAnimal &animal) {
+ std::cout
+ << " animal #" << i + 1
+ << ":\n id number: " << animal.getIDNum()
+ << "\n cage number: " << animal.getCageNum()
+ << "\n date acquired: " << animal.getDateAcq()
+ << "\n species: " << animal.getSpecies();
+ }},
+ zooAnimals.at(i));
+
+ std::cout << std::endl;
+ }
+ }
+
+ if (!zooAnimals.empty()) {
+ // Let the user choose to see all information about a specific animal, by
+ // identification number
+ std::cout << "\nanimal ids:";
+
+ for (auto &zooAnimal : zooAnimals) {
+ std::visit(
+ [](auto &&animal) { std::cout << "\n " << animal.getIDNum(); },
+ zooAnimal);
+ }
+
+ std::cout << std::endl;
+
+ for (;;) {
+ int idNumber;
+
+ std::cout << "id number to view (negative number to finish): ";
+ std::cin >> idNumber;
+
+ if (idNumber < 0) {
+ break;
+ }
+
+ for (auto &zooAnimal : zooAnimals) {
+ std::visit(zoo::overloaded{
+ [&](zoo::Mammal &animal) {
+ if (animal.getIDNum() == idNumber) {
+ std::cout
+ << "mammal #" << idNumber
+ << ":\n id number: " << animal.getIDNum()
+ << "\n cage number: " << animal.getCageNum()
+ << "\n date acquired: " << animal.getDateAcq()
+ << "\n species: " << animal.getSpecies()
+ << "\n exhibit: " << animal.getExhibit()
+ << "\n name: " << animal.getName()
+ << "\n minimum cage size: "
+ << animal.getCageSizeMin() << std::endl;
+ }
+ },
+ [&](zoo::ZooAnimal &animal) {
+ if (animal.getIDNum() == idNumber) {
+ std::cout
+ << "animal #" << idNumber
+ << ":\n id number: " << animal.getIDNum()
+ << "\n cage number: " << animal.getCageNum()
+ << "\n date acquired: " << animal.getDateAcq()
+ << "\n species: " << animal.getSpecies()
+ << std::endl;
+ }
+ }},
+ zooAnimal);
+ }
+ }
+ } else {
+ std::cout << "there were no animals at the zoo" << std::endl;
+ }
+
+ if (!zooAnimals.empty()) {
+ std::size_t mammalCount = 0;
+
+ std::cout << "\nmammals names:";
+
+ for (auto &zooAnimal : zooAnimals) {
+ std::visit(
+ [&mammalCount](auto &&animal) {
+ if constexpr (std::is_same_v<std::decay_t<decltype(animal)>,
+ zoo::Mammal>) {
+ std::cout << "\n " << animal.getName();
+
+ mammalCount += 1;
+ }
+ },
+ zooAnimal);
+ }
+
+ if (mammalCount == 0) {
+ std::cout << " there were no mammals at the zoo";
+ }
+
+ std::cout << std::endl;
+ }
+
+ return 0;
+}