Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update profile.cpp
  • Loading branch information
GSMgeeth authored May 16, 2022
commit 23c6cd0e6fdadc95264c25bbac38f4da99832be5
29 changes: 7 additions & 22 deletions 7-classes-and-objects/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,21 @@

#include "profile.hpp"

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;
}

Profile::Profile(const std::string new_name, const int new_age, const std::string new_city, const std::string new_country, const std::string new_pronouns) : name(new_name), age(new_age), city(new_city), country(new_country), pronouns(new_pronouns) {
}

std::string Profile::view_profile() {
std::string hobbies_str = "";

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";

for (const std::string &hobby : hobbies) {
hobbies_str += hobby + ", ";
}

return bio + "\n" + hobby_string;
hobbies_str = hobbies_str.substr(0, hobbies_str.length() - 2);

return name + " is " + std::to_string(age) + " years old and " + pronouns.substr(0, pronouns.find("/")) + " lives in " + city + " city, " + country + ".\n" + "Hobbies : " + hobbies_str + "\n";
}

void Profile::add_hobby(std::string new_hobby) {

void Profile::add_hobby(const std::string &new_hobby) {
hobbies.push_back(new_hobby);

}