From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/cpp/my_nfts/auction.cc | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 graphs/cpp/my_nfts/auction.cc (limited to 'graphs/cpp/my_nfts/auction.cc') diff --git a/graphs/cpp/my_nfts/auction.cc b/graphs/cpp/my_nfts/auction.cc new file mode 100644 index 0000000..534c61d --- /dev/null +++ b/graphs/cpp/my_nfts/auction.cc @@ -0,0 +1,45 @@ +#include "auction.hh" + +#include +Auction::Auction(Person& organizer, NFT nft, uint initial_bid) + : organizer_{ organizer } + , nft_{ std::move(nft) } + , highest_bidder_{ nullptr } + , highest_bid_{ initial_bid } +{ + if (!nft_ || nft_->empty()) + throw std::invalid_argument{ "Invalid nft!" }; +} +Auction::~Auction() +{ + if (highest_bidder_ == nullptr) + organizer_.add_nft(std::move(nft_)); + else + { + highest_bidder_->add_nft(std::move(nft_)); + organizer_.add_money(highest_bid_); + } +} +bool Auction::bid(Person& person, uint money) +{ + if (money > highest_bid_) + { + if (highest_bidder_ == nullptr) + highest_bidder_ = &person; + else + highest_bidder_->add_money(highest_bid_); + highest_bid_ = money; + highest_bidder_ = &person; + highest_bidder_->remove_money(money); + return true; + } + return false; +} +const std::string& Auction::get_nft_name() const +{ + return *nft_; +} +uint Auction::get_highest_bid() const +{ + return highest_bid_; +} \ No newline at end of file -- cgit v1.2.3