-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Person interface and concrete classes, random greeting logi… #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…c, and refactor getName to getFirstName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces the simple “Hello, World!” with a dynamic greeting system by defining a Person interface and multiple implementations, then randomly instantiating and greeting them. Key changes include:
- Introduce an abstract
Personinterface and concrete classes (Moe,Larry,Curley,Shemp). - Implement random generation of 3–10
Personobjects and print personalized greetings. - Refactor
getNametogetFirstNameand keep a legacyprint_hello_worldhelper.
Comments suppressed due to low confidence (1)
main.cpp:55
- The function
print_hello_worldis defined but never used; consider removing it or documenting its intended usage.
void print_hello_world() {
| 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)) { |
Copilot
AI
Jun 25, 2025
There was a problem hiding this comment.
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.
|
|
||
| int main(int argc, char* argv[]) { | ||
| (void)argc; (void)argv; | ||
| std::vector<std::unique_ptr<Person>> people; |
Copilot
AI
Jun 25, 2025
There was a problem hiding this comment.
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.
| std::vector<std::unique_ptr<Person>> people; | ||
| std::random_device rd; | ||
| std::mt19937 gen(rd()); | ||
| std::uniform_int_distribution<> num_dist(3, 10); |
Copilot
AI
Jun 25, 2025
There was a problem hiding this comment.
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.
| std::uniform_int_distribution<> num_dist(3, 10); | |
| std::uniform_int_distribution<> num_dist(MIN_PEOPLE, MAX_PEOPLE); |
…c, and refactor getName to getFirstName