-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||||||
| std::random_device rd; | ||||||
| std::mt19937 gen(rd()); | ||||||
| std::uniform_int_distribution<> num_dist(3, 10); | ||||||
|
||||||
| std::uniform_int_distribution<> num_dist(3, 10); | |
| std::uniform_int_distribution<> num_dist(MIN_PEOPLE, MAX_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.
Add a default case or an assertion inside the switch to handle unexpected values and make the intent explicit.
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.