From 3ab82366877abf2371b41e0f6949a522839440f7 Mon Sep 17 00:00:00 2001 From: Borys Date: Mon, 9 Mar 2026 13:01:20 +0100 Subject: [PATCH 1/3] Replace add_hobby with new_hobby method Also added using namespace std for better readability. --- 7-classes-and-objects/app.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/7-classes-and-objects/app.cpp b/7-classes-and-objects/app.cpp index 229170e..4fcddfc 100644 --- a/7-classes-and-objects/app.cpp +++ b/7-classes-and-objects/app.cpp @@ -1,13 +1,14 @@ #include #include "profile.hpp" -int main() { +using namespace std; - Profile sam("Sam Drakkila", 30, "New York", "USA", "he/him"); - sam.add_hobby("listening to audiobooks and podcasts"); - sam.add_hobby("playing rec sports like bowling and kickball"); - sam.add_hobby("writing a speculative fiction novel"); - sam.add_hobby("reading advice columns"); - std::cout << sam.view_profile(); +int main() { -} \ No newline at end of file + Profile sam("Sam Drakkila", 30, "New York", "USA", "he/him"); + sam.new_hobby("listening to audiobooks and podcasts"); + sam.new_hobby("playing rec sports like bowling and kickball"); + sam.new_hobby("writing a speculative fiction novel"); + sam.new_hobby("reading advice columns"); + cout << sam.view_profile(); +} From 29c33877bc67aaff3f30e22ecf0bd3f9500e768f Mon Sep 17 00:00:00 2001 From: Borys Date: Mon, 9 Mar 2026 13:02:56 +0100 Subject: [PATCH 2/3] Refactor Profile class constructor and methods Added using namespace std for better readability. Changed how hobbies are separated and how they end. --- 7-classes-and-objects/profile.cpp | 56 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/7-classes-and-objects/profile.cpp b/7-classes-and-objects/profile.cpp index 4f40619..e055d9a 100644 --- a/7-classes-and-objects/profile.cpp +++ b/7-classes-and-objects/profile.cpp @@ -1,37 +1,37 @@ -#include - #include "profile.hpp" +#include +#include +#include -Profile::Profile(std::string new_name, int new_age, std::string new_city, std::string new_country, std::string new_pronouns) - : name(new_name), age(new_age), city(new_city), country(new_country), pronouns(new_pronouns) { +using namespace std; - if (new_age >= 18) { +Profile::Profile(string new_name, int new_age, string new_city, string new_country, string new_pronouns) { + name = new_name; age = new_age; - } else { - age = 0; - } - + city = new_city; + country = new_country; + pronouns = new_pronouns; } -std::string Profile::view_profile() { - - std::string bio = "Name: " + name; - bio += "\nAge: " + std::to_string(age); - bio += "\nPronouns: " + pronouns; - std::string hobby_string = "Hobbies:\n"; - - for (std::string hobby : hobbies) { - - hobby_string += " - " + hobby + "\n"; - - } - - return bio + "\n" + hobby_string; - +string Profile::view_profile() { + string profile_details = "Name: " + name; + profile_details += "\nAge: " + to_string(age); + profile_details += "\nCity: " + city; + profile_details += "\nCountry: " + country; + profile_details += "\nPronouns: " + pronouns; + profile_details += "\nHobbies: "; + for (int i = 0; i < hobbies.size(); i++) { + profile_details += hobbies[i]; + if (i < hobbies.size() - 1) { + profile_details += ", "; + } else { + profile_details += ".\n"; + } + } + + return profile_details; } -void Profile::add_hobby(std::string new_hobby) { - - hobbies.push_back(new_hobby); - +void Profile::new_hobby(string new_hobby) { + hobbies.push_back(new_hobby); } From 6a4b2b7b04be16853bb336375d687e8fe781fa14 Mon Sep 17 00:00:00 2001 From: Borys Date: Mon, 9 Mar 2026 13:03:56 +0100 Subject: [PATCH 3/3] Refactor Profile class with default constructor values Updated Profile class to include default values for constructor parameters and changed add_hobby method to new_hobby. Also added using namespace std for better readability. --- 7-classes-and-objects/profile.hpp | 38 +++++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/7-classes-and-objects/profile.hpp b/7-classes-and-objects/profile.hpp index 9a04429..0430441 100644 --- a/7-classes-and-objects/profile.hpp +++ b/7-classes-and-objects/profile.hpp @@ -1,17 +1,25 @@ #include +#include -class Profile { -private: - std::string name; - int age; - std::string city; - std::string country; - std::string pronouns; - std::vector hobbies; - -public: - Profile(std::string new_name, int new_age, std::string new_city, std::string new_country, std::string new_pronouns = "they/them"); - std::string view_profile(); - void add_hobby(std::string new_hobby); - -}; \ No newline at end of file +using namespace std; + +class Profile { + + private: + + string name; + int age; + string city; + string country; + string pronouns; + vector hobbies; + + public: + + Profile(string new_name = "John/Jane Doe", int new_age = 0, string new_city = "Sin City", string new_country = "Unknown", string new_pronouns = "they/them"); + + string view_profile(); + + void new_hobby(string new_hobby); + +};