diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/cpp/my_nfts/person.cc | |
add: graphs et rushs
Diffstat (limited to 'graphs/cpp/my_nfts/person.cc')
| -rw-r--r-- | graphs/cpp/my_nfts/person.cc | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/graphs/cpp/my_nfts/person.cc b/graphs/cpp/my_nfts/person.cc new file mode 100644 index 0000000..cf4b291 --- /dev/null +++ b/graphs/cpp/my_nfts/person.cc @@ -0,0 +1,61 @@ +#include "person.hh" + +#include <algorithm> +Person::Person(const std::string& name, uint money) + : name_{ name } + , money_{ money } +{} +std::vector<std::string> Person::enumerate_nfts() const +{ + std::vector<std::string> res; + for (auto nft = nfts_.begin(); nft != nfts_.end(); nft++) + { + res.push_back(**nft); + } + return res; +} +void Person::add_nft(NFT nft) +{ + nfts_.push_back(std::move(nft)); +} +NFT Person::remove_nft(const std::string& name) +{ + auto pos = std::find_if(nfts_.begin(), nfts_.end(), + [&](NFT const& nft) { return *nft == name; }); + if (pos == nfts_.end()) + return create_empty_nft(); + nfts_.erase(pos); + return create_nft(name); +} +void Person::add_money(uint money) +{ + money_ += money; +} +bool Person::remove_money(uint money) +{ + if (money > money_) + return false; + money_ -= money; + return true; +} +uint Person::get_money() const +{ + return money_; +} +const std::string& Person::get_name() const +{ + return name_; +} +std::ostream& operator<<(std::ostream& os, const Person& p) +{ + os << "Name: " << p.get_name() << "\nMoney: " << p.get_money() << "\nNFTs:"; + if (const std::vector<std::string> nfts = p.enumerate_nfts(); !nfts.empty()) + { + for (size_t i = 0; i < nfts.size(); ++i) + { + os << " " << nfts.at(i); + } + } + os << "\n"; + return os; +} |
