Skip to content
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

Update profile.cpp #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
45 changes: 23 additions & 22 deletions 7-classes-and-objects/profile.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
#include <iostream>

#include <vector>
#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<std::string> 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);

}