Question: Task 1 (7 points): Your task is to implement a Bag data structure in C++. Your Bag data structure must store and retrieve numbers of
Task 1 (7 points): Your task is to implement a Bag data structure in C++. Your Bag data structure must store and retrieve numbers of type int. It must have a capacity of 1000 integers. ONLY NON-NEGATIVE values are allowed to be added to the bag. (If someone tries to add a negative number, just ignore it.) Your Bag must implement the following public member functions, in addition to a constructor, if you need one: public: //adds the element j to the Bag. Returns true if //successfully added, false if the Bag was full. bool add (int j); // returns true if j is contained in the Bag, false otherwise bool contains( int j; // removes one instance of j from the Bag. Returns true // if an element is removed, false if the element was not // contained in the Bag bool remove (int j); / returns the number of elements stored in the Bag int getsize ): returns true if there are no elements in the Bag bool isEmpty 1/
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
