diff --git a/src/enumerations.cc b/src/enumerations.cc new file mode 100644 index 0000000..1f56ce4 --- /dev/null +++ b/src/enumerations.cc @@ -0,0 +1,55 @@ +#include + +std::string generate_crewmate_string(std::string type); + +enum class CrewmateType { + Sus, + NotSus, + Imposter +}; + +class Crewmate { +public: + Crewmate(CrewmateType type) + { + this->type = type; + } + + CrewmateType type; + + // check if the type variable equals any of the values in the CrewmateType enumerator. + void print_type() + { + switch (this->type) { + case CrewmateType::Sus: + std::cout << generate_crewmate_string("Sus") << std::endl; + break; + case CrewmateType::NotSus: + std::cout << generate_crewmate_string("NotSus") << std::endl; + break; + case CrewmateType::Imposter: + std::cout << generate_crewmate_string("Imposter") << std::endl; + break; + } + } +}; + +std::string generate_crewmate_string(std::string type) +{ + return "Your crewmate type is " + type; +} + +int main() +{ + Crewmate sussy = Crewmate(CrewmateType::Sus); + Crewmate notSussy = Crewmate(CrewmateType::NotSus); + Crewmate imposter = Crewmate(CrewmateType::Imposter); + + // create an array of crewmate pointers. + Crewmate* crewmates[3] = { &sussy, ¬Sussy, &imposter }; + + // loop through each of them to print their type. + for (Crewmate* crewmate : crewmates) { + crewmate->print_type(); + } +} diff --git a/src/hello.cc b/src/hello.cc index 43dc5fe..579859a 100644 --- a/src/hello.cc +++ b/src/hello.cc @@ -1,5 +1,6 @@ #include -int main() { +int main() +{ std::cout << "hello" << std::endl; } diff --git a/src/math.cc b/src/math.cc index 180d0e3..df0d870 100644 --- a/src/math.cc +++ b/src/math.cc @@ -1,4 +1,5 @@ #include "math.hh" -double Math::sqrt(double x) { - return x*x; +double Math::square(double x) +{ + return x * x; } diff --git a/src/math.hh b/src/math.hh index 337b738..799321a 100644 --- a/src/math.hh +++ b/src/math.hh @@ -1,4 +1,4 @@ class Math { - public: - double static sqrt(double x); +public: + double static square(double x); }; diff --git a/src/meson.build b/src/meson.build index fd2b1a9..473b72f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,3 +1,4 @@ executable('hello', 'hello.cc') executable('sqrt', ['math.cc', 'sqrt.cc']) executable('inheritance', 'inheritance.cc') +executable('enumerations', 'enumerations.cc') diff --git a/src/sqrt.cc b/src/sqrt.cc index 959fc42..1a5f411 100644 --- a/src/sqrt.cc +++ b/src/sqrt.cc @@ -1,15 +1,15 @@ -#include #include "math.hh" +#include -double sqrt(double x); -void print_sqrt(double x); +void print_squared(double x); -int main() { - print_sqrt(21.420); - print_sqrt(420); +int main() +{ + print_squared(21.420); + print_squared(420); } -void print_sqrt(double x) { - std::cout << "the square root of " << x << " is " << Math::sqrt(x) << std::endl; +void print_squared(double x) +{ + std::cout << "the squared of " << x << " is " << Math::square(x) << std::endl; } -