#include <iostream>
#include <unordered_map>
#include <string>
class User {
public:
User(const std::string& name) : name(name), balance(0.0) {}
void deposit(double amount) {
if (amount > 0) {
balance += amount;
std::cout << amount << " deposited. New balance: " << balance << std::endl;
} else {
std::cout << "Invalid deposit amount!" << std::endl;
}
}
void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
std::cout << amount << " withdrawn. New balance: " << balance << std::endl;
} else {
std::cout << "Invalid withdrawal amount or insufficient funds!" << std::endl;
}
}
double getBalance() const {
return balance;
}
private:
std::string name;
double balance;
};
class CryptocurrencySystem {
public:
void addUser(const std::string& name) {
if (users.find(name) == users.end()) {
users[name] = User(name);
std::cout << "User " << name << " added." << std::endl;
} else {
std::cout << "User already exists!" << std::endl;
}
}
void deposit(const std::string& name, double amount) {
if (users.find(name) != users.end()) {
users[name].deposit(amount);
} else {
std::cout << "User not found!" << std::endl;
}
}
void withdraw(const std::string& name, double amount) {
if (users.find(name) != users.end()) {
users[name].withdraw(amount);
} else {
std::cout << "User not found!" << std::endl;
}
}
void checkBalance(const std::string& name) const {
if (users.find(name) != users.end()) {
std::cout << "Balance for " << name << ": " << users.at(name).getBalance() << std::endl;
} else {
std::cout << "User not found!" << std::endl;
}
}
private:
std::unordered_map<std::string, User> users;
};
int main() {
CryptocurrencySystem system;
// Adding users
system.addUser("Alice");
system.addUser("Bob");
// Performing transactions
system.deposit("Alice", 100.0);
system.deposit("Bob", 50.0);
system.withdraw("Alice", 30.0);
system.withdraw("Bob", 10.0);
// Checking balances
system.checkBalance("Alice");
system.checkBalance("Bob");
return 0;
}