Question

C++ Define the following operator overloads in ShoppingCart.hpp and implement them accordingly in ShoppingCart.cpp. /** Implements...

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);

Homework Answers

Answer #1

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;
}

==================================================================

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Given the following specifications for an array-based unsorted list, implement all of the functions (declared below)...
Given the following specifications for an array-based unsorted list, implement all of the functions (declared below) and a write a driver code to test all of your implementations. // Define a structure to use as the list item struct ListItem { int key; int Data; }; #define MAX_SIZE 50 // Define maximum length of the list class UnsortedArray { private: int head; // Index to head of the list ListItem theList[MAX_SIZE]; // The list public: UnsortedArray(); // Class constructor ~...
Data Structures using C++ Consider the classes QueueADT and ArrayQueueType: QueueADT: #ifndef QUEUEADT_H #define QUEUEADT_H template...
Data Structures using C++ Consider the classes QueueADT and ArrayQueueType: QueueADT: #ifndef QUEUEADT_H #define QUEUEADT_H template <class ItemType> class QueueADT { public:        // Action responsibilities        virtual void resetQueue() = 0;           // Reset the queue to an empty queue.           // Post: Queue is empty.        virtual void add(const ItemType& newItem) = 0;           // Function to add newItem to the queue.           // Pre: The queue exists and is not full.          ...
Data Structures using C++ Consider the following class #ifndef LINKEDQUEUETYPE_H #define LINKEDQUEUETYPE_H #include <iostream> #include <new>...
Data Structures using C++ Consider the following class #ifndef LINKEDQUEUETYPE_H #define LINKEDQUEUETYPE_H #include <iostream> #include <new>    #include <cstdlib> #include "QueueADT.h" using namespace std; // Definition of the node template <class ItemType> struct NodeType {        ItemType info;        NodeType<ItemType> *next; }; template <class ItemType> class LinkedQueueType: public QueueADT<ItemType> { public:        // Constructor        LinkedQueueType();           // Default constructor.           // Post: An empty queue has been created. queueFront = NULL;           //       queueBack = NULL;...
2. Define a relation R on pairs of real numbers as follows: (a, b)R(c, d) iff...
2. Define a relation R on pairs of real numbers as follows: (a, b)R(c, d) iff either a < c or both a = c and b ≤ d. Is R a partial order? Why or why not? If R is a partial order, draw a diagram of some of its elements. 3. Define a relation R on integers as follows: mRn iff m + n is even. Is R a partial order? Why or why not? If R is...
iven your computation and conclusions, which of the following statements is true? A) When the coupon...
iven your computation and conclusions, which of the following statements is true? A) When the coupon rate is greater than Noah’s required return, the bond should trade at a premium. B) When the coupon rate is greater than Noah’s required return, the bond’s intrinsic value will be less than its par value. C) When the coupon rate is greater than Noah’s required return, the bond should trade at a discount. D) A bond should trade at a par when the...
Under which of the following scenarios will increasing the payout ratio for a firm increase its...
Under which of the following scenarios will increasing the payout ratio for a firm increase its equity value? •A) Never •B) Always •C) When the return on equity is equal to its cost of equity •D) When the return on equity is less than the cost of equity •E) When the return on equity is greater than the cost of equity WHY? Could I please have the explanation. Thank you
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The triplet ADT has the following functions:  default constructor  explicit constructor: initialize the data member using parameters  three accessors (three get functions) which will return the value of each individual element of the array data member  one mutator (set function) which will assign values to the data member...
1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and...
1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called...
CAPM, PORTFOLIO RISK, AND RETURN Consider the following information for stocks A, B, and C. The...
CAPM, PORTFOLIO RISK, AND RETURN Consider the following information for stocks A, B, and C. The returns on the three stocks are positively correlated, but they are not perfectly correlated. (That is, each of the correlation coefficients is between 0 and 1.) Stock Expected Return Standard Deviation Beta A 10.10% 16% 0.9 B 11.01    16    1.1 C 13.28    16    1.6 Fund P has one-third of its funds invested in each of the three stocks. The risk-free rate is 6%, and...