-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Copy pathUser.cpp
38 lines (32 loc) · 1.31 KB
/
User.cpp
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>
#include <iomanip>
User::User(std::string userId, std::string name, std::string email)
: userId(userId), name(name), email(email), active(true) {}
std::string User::getUserId() const { return userId; }
std::string User::getName() const { return name; }
std::string User::getEmail() const { return email; }
bool User::isActive() const { return active; }
double User::getBalanceWith(const std::string& userId) const {
auto it = balances.find(userId);
return it != balances.end() ? it->second : 0.0;
}
const std::map<std::string, double>& User::getBalances() const { return balances; }
void User::updateBalance(const std::string& userId, double amount) {
balances[userId] += amount;
}
void User::setActive(bool status) {
active = status;
}
void User::displayInfo() const {
std::cout << "User: " << name << " (ID: " << userId << ")" << std::endl;
std::cout << "Email: " << email << std::endl;
std::cout << "Status: " << (active ? "Active" : "Inactive") << std::endl;
}
void User::displayBalances() const {
std::cout << "\nBalances for " << name << ":" << std::endl;
for (const auto& balance : balances) {
std::cout << "With " << balance.first << ": $"
<< std::fixed << std::setprecision(2) << balance.second << std::endl;
}
}