Do the following pic SolutionHere is the solution for the fi

Do the following pic:

Solution

Here is the solution for the first 2 problems in the pic:

#include <vector>
using namespace std;
template <typename ElementType>
class Dec
{
public:
   //hasDuplicate function that returns true if the private data member has an item that appears twice or more in the list.
   bool hasDuplicate();
   //eraseAll function to remove all items which are equal to the item specified in the function parameter.
   void eraseAll(ElementType element);
   //isLessThan function to determine if another Dec object is greater than the Dec object itself.
   //If the summation of all items from the Dec object itself is less than the summation of all
   //items from another Dec object, return true, otherwise, return false.
   bool isLessThan(Dec other);
   //push_second function to add an item after the first item if there are more than one items.
   void push_second(ElementType element);
private:
vector<ElementType> dec;
};
template <typename ElementType>
bool Dec<ElementType>::hasDuplicate()
{
for(vector<int>::iterator ot = dec.begin(); ot != dec.end(); ot++)
for(vector<int>::iterator it = dec.begin() + ot + 1; it != dec.end(); it++)
if(*it == *ot)
return true;
return false;   
}
template<typename ElementType>
bool Dec<ElementType>::isLessThan(Dec other)
{
int sum1 = 0, sum2 = 0;
for(vector<int>::iterator it = dec.begin(); it != dec.end(); it++)
sum1 += *it;
for(vector<int>::iterator it = other.dec.begin(); it != other.dec.end(); it++)
sum2 += *it;
return sum1 < sum2;
}

Do the following pic: SolutionHere is the solution for the first 2 problems in the pic: #include <vector> using namespace std; template <typename Eleme

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site