forked from Codecademy/learn-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.cpp
More file actions
37 lines (23 loc) · 752 Bytes
/
profile.cpp
File metadata and controls
37 lines (23 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#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;
}
}
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;
}
void Profile::add_hobby(std::string new_hobby) {
hobbies.push_back(new_hobby);
}