Question: Convert this header file to use templates. // FILE: set.h // CLASS PROVIDED: set (part of the namespace main_savitch_5) // // TYPEDEFS for the set

Convert this header file to use templates.

// FILE: set.h // CLASS PROVIDED: set (part of the namespace main_savitch_5) // // TYPEDEFS for the set class: // set::value_type // is the data type of the items in the set. It may be any // of the C++ built-in types (int, char, etc.), or a class with a default // constructor, a copy constructor, an assignment // operator, and a test for equality (x == y). // // set::size_type // is the data type of any variable that keeps track of how many items are // in a set // // CONSTRUCTOR for the set class: // set( ) // Postcondition: The set is empty. // // MODIFICATION MEMBER FUNCTIONS for the set class: // // bool erase(const value_type& target) // Postcondition: If target was in the set, then one copy of target has // been removed from the set; otherwise the set is unchanged. A true // return value indicates that one copy was removed; false indicates that // nothing was removed. // // bool insert(const value_type& entry) // Postcondition: The entry is inserted if not already present in the set. // A true is return if insertion successful otherwise false. // // void operator +=(const set& addend) // Postcondition: Each item in addend , if not already present has been added to this set. // // CONSTANT MEMBER FUNCTIONS for the set class: // size_type size( ) const // Postcondition: Return value is the total number of items in the set. // // size_type count(const value_type& target) const // Postcondition: Return value is number of times target is in the set. // // // value_type grab( ) const // Precondition: size( ) > 0. // Postcondition: The return value is a randomly selected item from the set. // // NONMEMBER FUNCTIONS for the set class: // set operator +(const set& b1, const set& b2) // Postcondition: The set returned is the union of b1 and b2. // // set operator -(const set& b1, const set& b2) // Postcondition: The set returned is the complement i.e. b1- b2 (all elements in b1 that are not in b2) // VALUE SEMANTICS for the set class: // Assignments and the copy constructor may be used with set objects. // // DYNAMIC MEMORY USAGE by the set: // If there is insufficient dynamic memory, then the following functions throw // bad_alloc: The constructors, insert, operator +=, operator +, and the // assignment operator.

#ifndef MAIN_SAVITCH_set_H #define MAIN_SAVITCH_set_H #include // Provides size_t and NULL #include "node1.h" // Provides node class namespace main_savitch_5 { class set { public: // TYPEDEFS typedef std::size_t size_type; typedef node::value_type value_type; // CONSTRUCTORS and DESTRUCTOR set( ); set(const set& source); ~set( ); // MODIFICATION MEMBER FUNCTIONS bool erase(const value_type& target); bool insert(const value_type& entry); set intersect(const set& set2); void operator +=(const set& addend); void operator -=(const set& set2); void operator =(const set& source); // CONSTANT MEMBER FUNCTIONS size_type size( ) const { return many_nodes; } bool isPresent(const value_type& target) const;

value_type grab( ) const; void display() ; private: node *head_ptr; // List head pointer size_type many_nodes; // Number of nodes on the list };

// NONMEMBER FUNCTIONS for the set class: set operator +(const set& b1, const set& b2); set operator -(const set& b1, const set& b2); } #endif

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!