Question: Please write this program according to the prompt below and using the code provided. Thank you Bag1.cpp Bag1.h The goal of assignment 3 is to

Please write this program according to the prompt below and using the code provided. Thank you  Please write this program according to the prompt below and using
the code provided. Thank you Bag1.cpp Bag1.h The goal of assignment 3
Bag1.cpp
is to reinforce implementation ofcontainer class concepts in C++. Specifically, the assignment
is to do problem 3.5 on page 149 of the text. You
need to implement the set operations union, intersection, and relative complement. Your
Bag1.h
code must implement the style guidelines of the author (preconditions, postconditions, a
unit test style - test each implemented fnction and clearly label your
output. class invariant, and function efficiencies). Your test program should us You

The goal of assignment 3 is to reinforce implementation ofcontainer class concepts in C++. Specifically, the assignment is to do problem 3.5 on page 149 of the text. You need to implement the set operations union, intersection, and relative complement. Your code must implement the style guidelines of the author (preconditions, postconditions, a unit test style - test each implemented fnction and clearly label your output. class invariant, and function efficiencies). Your test program should us You will be provided with bag I.h and bagl.cpp files as reference. You will need to adapt this class to implement a set Here are some typical features of a set: 1. A set can have unique elements only -no duplicates allowed 2. dmion of sets s1 U 2-a new set wilh fl nd s2 withou ny duplicates If sl 1,2,33, s213,4,5) then slus2= {1,2,3,4,5} 3. Intersection of 2 sets sins2 a new set with elements common to both sl and s2 4. Relative complement of sl to s2 a new set with all elements from sl that are not present in s21.2) Here are the changes you should ideally be making to the h and implementation files: 2. You will need to add new functions Union, Intersection and Relative complement, these will need to be non- member friend functions. 3. You should also add a function called contains that checks to see if an entry is already present in the set. It should return a boolean value. This function should be a private function that can be called anytime, you need to insert an entry into a set (to make sure you don't add duplicate entries). 4. You do not need the following functions from the bag class: a. Erase b. Count c. +overloaded function d. overloaded function 5. Do not add any more functions besides the ones listed under 2. &3. 6. Test the 3 set operations and clearly label your imput and outputs. FILE: bagl.cx:x / CLASS IMPLEMENTED: bag (see bag1.h for documentation) / INVARIANT for the bag class: 1. The number of items in the bag is in the member variable used / 2. For an empty bag, we do not care what is stored in any of data: for a non-empty bag the items in the bag are stored in data [0] through data used-1], and we don't care what 's in the rest of data. #include // Provides copy function #include cassert> // Provides assert function include "bagl.h" using namespace std: namespace main savitch 3 const bag: :size type bag: : CAPACITY: bag: :size_ type bag: :erase (const value type& target) size type index -0 size_type. many_removed 0 while (index // Provides size t - - namespace main savitch 3 class bag public: TYPEDEFS and MEMBER CONSTANTS typedef int value type: typedef std::size t size typei static const size type CAPACITY 30: ICONSTRUCTOR bag used 0 ) // MODIFICATION MEMBER FUNCTIONS size type erase (const value type& target) : bool erase_ one (const value type& target); void insert (const value type& entry) void operator +-(const bag& addend) // CONSTANT MEMBER FUNCTIONS size type size() const t return used: size type count (const value type& target) const private: value_type data [CAPACITY] / The array to store items size type used: // How much of array is used // NONMEMBER FUNCTIONS for the bag class bag operator +(const bag& bl, const bag& b2): tendif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!