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
34 lines (27 loc) · 854 Bytes
/
profile.cpp
File metadata and controls
34 lines (27 loc) · 854 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
#include "profile.hpp"
#include <iostream>
#include <string>
Profile::Profile (std::string name, unsigned int age, std::string city, std::string pronouns)
: name(name), age(age), city(city), pronouns(pronouns) {}
void Profile::add_hobbies(std::initializer_list<std::string> new_hobbies)
{
hobbies.insert(hobbies.end(), new_hobbies.begin(), new_hobbies.end());
}
std::string Profile::view_profile()
{
std::string age_string = std::to_string(age);
std::string profile_info = "Name: " + Profile::name + "\n" + "Age: " + age_string + "\n" + "City: " + Profile::city + "\n" + "Pronouns: " + Profile::pronouns + "\n" + "Hobbies:";
int size = hobbies.size();
for (std::string i: hobbies)
{
if (i != hobbies[0])
{
profile_info += ", " + i;
}
else
{
profile_info += " " + i;
}
}
return profile_info;
}