Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <random>

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
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract the 1 and 10 bounds into named constants (e.g. kMinPersons, kMaxPersons) for clarity and easier updates.

Suggested change
std::uniform_int_distribution<> dist(1, 10); // random number of persons
std::uniform_int_distribution<> dist(kMinPersons, kMaxPersons); // random number of persons

Copilot uses AI. Check for mistakes.
int numPersons = dist(gen);

std::vector<std::unique_ptr<Person>> people;
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider calling people.reserve(numPersons); after creating the vector to avoid repeated reallocations when pushing back numPersons elements.

Suggested change
std::vector<std::unique_ptr<Person>> people;
std::vector<std::unique_ptr<Person>> people;
people.reserve(numPersons); // Preallocate memory for numPersons elements

Copilot uses AI. Check for mistakes.
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<Moe>());
else if (type == 1) people.push_back(std::make_unique<Larry>());
else people.push_back(std::make_unique<Curley>());
}

for (const auto& person : people) {
printHello(person->getName());
}
return 0;
}
}