Question: Can you please correct my code? Main.cc -------------------------- #include #include #include product.h int main() { std::shared_ptr avocado = std::make_shared (avocado, 0.68, nullptr, nullptr); std::shared_ptr apple
Can you please correct my code?
Main.cc
--------------------------
#include
#include "product.h"
int main() { std::shared_ptr
std::shared_ptr
std::cout << "Price of a pineapple: "; std::cout << root->FindPrice("pineapple") << " "; }
--------------------------
product.h
-----------------------
#include
class Product { public: Product(std::string &name, double price, std::shared_ptr
// Implement a recursive `FindPrice` member function that accepts the name of a `Product` and returns its price. If the product name does not match the product or any of its linked products, return -1.0.
double FindPrice(std::string &name) { if (name_ == name) { return price_; } else if (name_ != name && right_ != nullptr && left_ != nullptr) { return -1; } else if (name > name_ && right_ != nullptr) { return right_->FindPrice(name); } else { return left_->FindPrice(name); } }
private: std::string name_; double price_; std::shared_ptr
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
