From 7807b772673b21d7af65a14c91d0dca4d8f35594 Mon Sep 17 00:00:00 2001 From: Jason Stratton Date: Wed, 25 Jun 2025 12:49:54 -0400 Subject: [PATCH] Implement Person interface and concrete classes, random greeting logic, and refactor getName to getFirstName --- main.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index f4fcae6..8d593d4 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,57 @@ #include +#include +#include +#include +#include -int main() { - std::cout << "Hello, World!" << std::endl; +class Person { +public: + virtual std::string getFirstName() const = 0; + virtual ~Person() = default; +}; + +class Moe : public Person { +public: + std::string getFirstName() const override { return "Moe"; } +}; + +class Larry : public Person { +public: + std::string getFirstName() const override { return "Larry"; } +}; + +class Curley : public Person { +public: + std::string getFirstName() const override { return "Curley"; } +}; + +class Shemp : public Person { +public: + std::string getFirstName() const override { return "Shemp"; } +}; + +int main(int argc, char* argv[]) { + (void)argc; (void)argv; + std::vector> people; + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> num_dist(3, 10); + std::uniform_int_distribution<> type_dist(0, 3); + int num_people = num_dist(gen); + for (int i = 0; i < num_people; ++i) { + switch (type_dist(gen)) { + case 0: people.push_back(std::make_unique()); break; + case 1: people.push_back(std::make_unique()); break; + case 2: people.push_back(std::make_unique()); break; + case 3: people.push_back(std::make_unique()); break; + } + } + for (const auto& person : people) { + std::cout << "Hello, " << person->getFirstName() << "!" << std::endl; + } return 0; -} \ No newline at end of file +} + +void print_hello_world() { + std::cout << "Hello, World!" << std::endl; +} \ No newline at end of file