C++
Define the following operator overloads in ShoppingCart.hpp and implement them accordingly in ShoppingCart.cpp.
/** Implements Greater Than Comparison A ShoppingCart is greater than another ShoppingCart if the total cost of its items is greater. @param a_cart to be compared with this (the calling) cart @return true if the total cost of this (the calling) cart is greater than the total cost of items in a_cart. **/ bool operator>(ShoppingCart a_cart); /** Implements Less Than Comparison A ShoppingCart is less than another ShoppingCart if the total cost of its items is less. @param a_cart to be compared with this (the calling) cart @return true if the total cost of this (the calling) cart is less than the total cost of items in a_cart. **/ bool operator<(ShoppingCart a_cart);
Below are the simple implementation of the two operator overloaded functions. I am assuming there is a member variable by the name total_cost that store the total cost of the shopping cart object.
Let me know for any changes or query.
==================================================================
bool ShoppingCart::operator>(ShoppingCart a_cart){
return this->total_cost>a_cart.total_cost;
}
==================================================================
bool ShoppingCart::operator<(ShoppingCart a_cart){
return
this->total_cost<a_cart.total_cost;
}
==================================================================
Get Answers For Free
Most questions answered within 1 hours.