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
38 lines (33 loc) · 1.04 KB
/
profile.cpp
File metadata and controls
38 lines (33 loc) · 1.04 KB
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
38
#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;
}
std::string Profile::view_profile()
{
std::string profileInfo = "Name: " + name + "\n";
profileInfo += "age: " + std::to_string(age);
profileInfo += "\ncity: " + city;
profileInfo += "\ncountry: " + country;
profileInfo += "\npronouns: " + pronouns;
profileInfo += "\nhobbies: ";
// Loop through users's hobbies included in their profile
for (int hobbyIndex = 0; hobbyIndex < hobbies.size(); hobbyIndex++)
{
// Deals with edge case of the last item
if ((hobbyIndex + 1) < hobbies.size())
profileInfo += hobbies[hobbyIndex] + ", ";
else
profileInfo += hobbies[hobbyIndex];
}
return profileInfo;
}
void Profile::add_hobby(std::string new_hobby)
{
hobbies.push_back(new_hobby);
}