Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Multi part question regarding the bag class. Based on the screenshots: E) Write

ID: 3742441 • Letter: M

Question

Multi part question regarding the bag class. Based on the screenshots:

E) Write your own test program to display the results of the implemented functions. Be sure to document your test program.

F) Write a summary of what your test program fully tests the bag class. Include a copy of the output after your summary.

G) Answer the following questions about the original code:

1) Are all member functions defined in the implementation file? If not, explain why the code still works.

2) Are all member and non-member functions tested by the original test program? If not, list those that were not tested.

3) Why do you think the “namespace main_savitch” code was used? Can the code be made to work without this code?

bag.h

bag.cpp

testbag.cpp

E#ifndef MAIN. SAVITCH. BAGI. H 60 61 62 #define MAIN SAVITCH BAGI H #includecstdlíb> // Provides sizet - 64 65 namespace main savitch3 :class bag 67 68 69 70 71 72 73 : public: :I/ TYPEDEFS and MEMBER CONSTANTS typedef int value_type; typedef std::size_t size_type; static const size_type CAPACITY = 30; : // CONSTRUCTOR bag) used - 0; :// MODIFICATION MEMBER FUNCTIONS 75 76 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); 79 80 /1 CONSTANT MEMBER FUNCTIONS :size_type size() const return used; y size_type count (const value_type& target) const; 83 84 85 86 87 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& b1, const bag& b2); 89 90 #endif

Explanation / Answer

summary of what your test program fully tests the bag class

bag class define in namespace main_savitch_3

namespace is similar to package in java. It is collection of different classes.

in above example we define class bag under namespace main_savitch_3.

in class bag
publically define variable of interge type value_type
we can inherit the size_t size_type variable using inheritance operator.
and constant variable capacity which value set to 30.

then we can define bag constuctor in which we initialised to 0 all variables which act as modification member function.

after that we define erase thype function in which we define constant type pointer target.
after that define erace_one function same variable is define.
then define insert function in varible entry is provide by using entry variable.
operator function is used to provide operation.
all are constant function.
size_type size() which is used to return size.
count() is used to count the variable.

then
we define private variable of array data in which array size specify by variable CAPACITY, Which is used to store items.
then to find how much array used we use used variable of type size_type.

then class defination is closed by closing curly bracket.
out of class defination we define non member function as name operator +() in which pass bag class object b1 and b2 as parameter list.
it is parametarised function in which two parameter are provided.
then end namespace defination by closing curly bracket.