s. Suppose you are implementing a customer around an STL list 10 a) ( 10 pts) Co
ID: 3706964 • Letter: S
Question
s. Suppose you are implementing a customer around an STL list 10 a) ( 10 pts) Complete the following class declaration (Write only the prototypes and the private data field; definitions will follew the class declaration) template designed coetainer called Dec as a wrapper class Dec public: // hasDuplicate function that returns true if the private data member has an item that appears twice or more in the iist. // eraseA1l function to remove all items which are equal to the item specified in the function parameter // isGreaterThan function to determine if the Dec object itself is greater than another Dec object. Assuming a Dec object is always arranged in ascending order. If the Dec object itself has more or equal items as the other Dec object, as as each item in the Dec object itself is greater than the corresponding item in the other Dec object, return true otherwise, return false. wel1 // insert_before_third function to insert an item before the third item if there are more than two items private: // list to hold the elements of the decExplanation / Answer
Usually we create wrapper to work on cross platform or cross language and to extend the functionality of existing class. and we use template to generalize the behaviour accross the various object which can function similarly.
however you want to extend the functionality of list with give member function the prototype of your wrapper class would be looks like below.
template<typename ElementType>
class Dec
{
public:
// you first define iterator
typedef typename std::list<ElementType>::iterator iterator;
iterator begin(){ return m_elementTypeList.begin(); };
iterator end(){ return m_elementTypeList.end(); };
// has duplicate function that returns true if the private
//data member has an item that appears twice or more in the list.
bool hasDuplicate()
{
//implementation code
return true;
}
//eraseAll function to remove all item which are equal to the
// item specified in the function parameter.
void eraseAll(ElementType list_to_remove)
{
//implementation code
}
//isGreaterThen function to determine if the Dec object itself
//is greater than another Dec objct. Assuming a Dec objct is always
//arranged in ascending order. if the Dec objctitself has more or equal item as the
//other Dec objct, as well as each item in the Dec object itself is greater than the
//corresponding item in the other Dec objct, return true; otherwise, return false.
bool isGreaterThen(Dec otherObject)
{
//implementation code
}
//inser_befor_third function to insert an item before the third item if
// there are more than two item.
bool inser_befor_third(ElementType item)
{
}
private:
//List to hold the elements of dec
std::list<ElementType> m_elementTypeList;
};
//your main will looks like below to use the wrapper list Dec
int main()
{
Wrapper<ElementType> wrapper;
for (Wrapper::iterator it = wrapper.begin(); it != wrapper.end(); ++it)
std::cout<<"Hi"<<std::endl;
}
Personaly i will prefer to use private inheritance instead of having private member variavble of list<ElementType> because in later case you have to implement all the members function of list to wrap arround the list functionality.
like below
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.