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
57 changes: 54 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <random>

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<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.

Reserve the vector capacity with people.reserve(num_people) before the loop to avoid repeated reallocations.

Copilot uses AI. Check for mistakes.
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> num_dist(3, 10);
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.

[nitpick] Extract the magic numbers 3 and 10 into named constants to clarify their purpose and improve readability.

Suggested change
std::uniform_int_distribution<> num_dist(3, 10);
std::uniform_int_distribution<> num_dist(MIN_PEOPLE, MAX_PEOPLE);

Copilot uses AI. Check for mistakes.
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)) {
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.

Add a default case or an assertion inside the switch to handle unexpected values and make the intent explicit.

Copilot uses AI. Check for mistakes.
case 0: people.push_back(std::make_unique<Moe>()); break;
case 1: people.push_back(std::make_unique<Larry>()); break;
case 2: people.push_back(std::make_unique<Curley>()); break;
case 3: people.push_back(std::make_unique<Shemp>()); break;
}
}
for (const auto& person : people) {
std::cout << "Hello, " << person->getFirstName() << "!" << std::endl;
}
return 0;
}
}

void print_hello_world() {
std::cout << "Hello, World!" << std::endl;
}