From f525a0036135d18018db427de444b0f721180a9b Mon Sep 17 00:00:00 2001 From: TomCode <87766694+TomDevX@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:29:54 +0700 Subject: [PATCH] Update profile.cpp Added profile header and custom length for its divider --- 7-classes-and-objects/profile.cpp | 45 ++++++++++++++++--------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/7-classes-and-objects/profile.cpp b/7-classes-and-objects/profile.cpp index 4f40619..723a5f3 100644 --- a/7-classes-and-objects/profile.cpp +++ b/7-classes-and-objects/profile.cpp @@ -1,37 +1,38 @@ #include - +#include #include "profile.hpp" -Profile::Profile(std::string new_name, int new_age, std::string new_city, std::string new_country, std::string new_pronouns) +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) { - if (new_age >= 18) { - age = new_age; - } else { - age = 0; - } - } -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"; +std::string Profile::view_profile(){ + std::vector divide = {"========"}; + for (int i = 0; i < name.size(); i++){ + divide.push_back("="); + } + for(std::string s : divide){ + std::cout << s; + } + std::cout << "\n" << name << " profile\n"; + for(std::string s2 : divide){ + std::cout << s2; } + std::cout << "\n"; + + std::string bio = "Name: " + name + "\nAge: " + std::to_string(age) + "\nPronouns: " + pronouns + "\n"; - return bio + "\n" + hobby_string; + std::string hobby_string = "Hobbies: \n"; + for (std::string hobby : hobbies){ + hobby_string += "- " + hobby + "\n"; + } + return bio + hobby_string; } -void Profile::add_hobby(std::string new_hobby) { - +void Profile::add_hobby(std::string new_hobby){ hobbies.push_back(new_hobby); - } +