forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.cpp
More file actions
38 lines (31 loc) · 1.22 KB
/
User.cpp
File metadata and controls
38 lines (31 loc) · 1.22 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 "User.hpp"
#include <iostream>
User::User(std::string userId, std::string username, std::string email)
: userId(userId), username(username), email(email), reputation(1), active(true) {}
std::string User::getUserId() const { return userId; }
std::string User::getUsername() const { return username; }
std::string User::getEmail() const { return email; }
int User::getReputation() const { return reputation; }
const std::vector<std::string>& User::getBadges() const { return badges; }
bool User::isActive() const { return active; }
void User::updateReputation(int points) {
reputation += points;
}
void User::addBadge(const std::string& badge) {
badges.push_back(badge);
}
void User::setActive(bool status) {
active = status;
}
void User::displayInfo() const {
std::cout << "User: " << username << " (ID: " << userId << ")" << std::endl;
std::cout << "Email: " << email << std::endl;
std::cout << "Reputation: " << reputation << std::endl;
std::cout << "Status: " << (active ? "Active" : "Inactive") << std::endl;
if (!badges.empty()) {
std::cout << "Badges:" << std::endl;
for (const auto& badge : badges) {
std::cout << "- " << badge << std::endl;
}
}
}