From 19b0d3be79221e509205481480b3ca77542e5db5 Mon Sep 17 00:00:00 2001 From: Jason Stratton Date: Wed, 25 Jun 2025 04:03:48 -0400 Subject: [PATCH] Implement Person interface, Moe/Larry/Curley classes, and random greetings --- main.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index f4fcae6..9cc6449 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,54 @@ #include +#include +#include +#include +#include -int main() { - std::cout << "Hello, World!" << std::endl; +// Person interface +class Person { +public: + virtual std::string getName() const = 0; + virtual ~Person() = default; +}; + +class Moe : public Person { +public: + std::string getName() const override { return "Moe"; } +}; + +class Larry : public Person { +public: + std::string getName() const override { return "Larry"; } +}; + +class Curley : public Person { +public: + std::string getName() const override { return "Curley"; } +}; + +// Function to print the hello message +void printHello(const std::string& name) { + std::cout << "Hello, " << name << "!" << std::endl; +} + +int main(int /*argc*/, char* /*argv*/[]) { + // Seed random number generator + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dist(1, 10); // random number of persons + int numPersons = dist(gen); + + std::vector> people; + std::uniform_int_distribution<> typeDist(0, 2); + for (int i = 0; i < numPersons; ++i) { + int type = typeDist(gen); + if (type == 0) people.push_back(std::make_unique()); + else if (type == 1) people.push_back(std::make_unique()); + else people.push_back(std::make_unique()); + } + + for (const auto& person : people) { + printHello(person->getName()); + } return 0; -} \ No newline at end of file +}