Question: Problem: A) Fix any errors to get the following program to run in your environment. B) The header file seems well documented, but add any
Problem: A) Fix any errors to get the following program to run in your environment. B) The header file seems well documented, but add any comments that you think may help new C++ programmers. C) Document the class implementation file to explain the algorithms used in each function to achieve the intended postcondition. D) Document the test program. 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?
// FILE: bag1.h // CLASS PROVIDED: bag (part of the namespace main_savitch_3) // // TYPEDEF and MEMBER CONSTANTS for the bag class: // typedef ____ value_type // bag::value_type is the data type of the items in the bag. It may be any of // the C++ built-in types (int, char, etc.), or a class with a default // constructor, an assignment operator, and operators to // test for equality (x == y) and non-equality (x != y). // // typedef ____ size_type // bag::size_type is the data type of any variable that keeps track of how many items // are in a bag. // // static const size_type CAPACITY = _____ // bag::CAPACITY is the maximum number of items that a bag can hold. // // CONSTRUCTOR for the bag class: // bag( ) // Postcondition: The bag has been initialized as an empty bag. // // MODIFICATION MEMBER FUNCTIONS for the bag class: // size_type erase(const value_type& target); // Postcondition: All copies of target have been removed from the bag. // The return value is the number of copies removed (which could be zero). // // void erase_one(const value_type& target) // Postcondition: If target was in the bag, then one copy has been removed; // otherwise the bag is unchanged. A true return value indicates that one // copy was removed; false indicates that nothing was removed. // // void insert(const value_type& entry) // Precondition: size( ) < CAPACITY. // Postcondition: A new copy of entry has been added to the bag. // // void operator +=(const bag& addend) // Precondition: size( ) + addend.size( ) <= CAPACITY. // Postcondition: Each item in addend has been added to this bag. // // CONSTANT MEMBER FUNCTIONS for the bag class: // size_type size( ) const // Postcondition: The return value is the total number of items in the bag. // // size_type count(const value_type& target) const // Postcondition: The return value is number of times target is in the bag. // // NONMEMBER FUNCTIONS for the bag class: // bag operator +(const bag& b1, const bag& b2) // Precondition: b1.size( ) + b2.size( ) <= bag::CAPACITY. // Postcondition: The bag returned is the union of b1 and b2. // // VALUE SEMANTICS for the bag class: // Assignments and the copy constructor may be used with bag objects. #ifndef MAIN_SAVITCH_BAG1_H #define MAIN_SAVITCH_BAG1_H #include
// FILE: bag1.cpp // 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
// FILE: bag_demo.cpp // This is a small demonstration program showing how the bag class is used. #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
