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

#ifndef _GROUP_OF_DATA #define _GROUP_OF_DATA #include <iostream> #include <fstr

ID: 668151 • Letter: #

Question

#ifndef _GROUP_OF_DATA

#define _GROUP_OF_DATA

#include <iostream>

#include <fstream>

using namespace::std;

const int MEMBERS_IN_GROUP = 10;

// ASSUME THERE ALWAYS 10 MEMBERS OF THE GROUP

template<class ItemType>

class DataGroup

{

private:

   ItemType data[MEMBERS_IN_GROUP]; // memory for data allocated at compile time

   // User decides on additional instance fields

int last;

int lastAmount;

public:

   DataGroup();

   DataGroup(const ItemType *);

   ~DataGroup();

   void rotateRight(); // 1 cell

   void rotateLeft(); // 1 cell

   void rotateRight(int amount); // amount 1 <= amount < MEMBERS_IN_GROUP

   void rotateLeft(int amount); // amount 1 <= amount < MEMBERS_IN_GROUP

   void unDue(); // can only undue the last method called , cannot have multiple unDue method calls in a row

   void display(ostream &) const;

}; // end DataGroup

#include "DataGroup.cpp"

#endif

//DataGroup.cpp

#include "DataGroup.h"

template<class ItemType>

DataGroup<ItemType>::DataGroup()

{

} // end default constructor

template<class ItemType>

DataGroup<ItemType>::DataGroup(const ItemType * mofo)

{

for (int i = 0; i < MEMBERS_IN_GROUP; i++)

   {

       data[i] = mofo[i];

   }

} // end constructor

template<class ItemType>

DataGroup<ItemType>::~DataGroup()

{

} // end default constructor

template<class ItemType>

void DataGroup<ItemType>::rotateRight()

{

last =1;

ItemType temp = data[MEMBERS_IN_GROUP-1];

for(int i = MEMBERS_IN_GROUP-1; i >=0; i--)

{

data[i] = data[i-1];

}

data[0] = temp;

}

template<class ItemType>

void DataGroup<ItemType>::rotateLeft()

{

last =2;

   ItemType temp = data[0];

for (int i = 1; i < MEMBERS_IN_GROUP; i++)

   {

       data[i - 1] = data[i];

   }

   data[MEMBERS_IN_GROUP - 1] = temp;

}

template<class ItemType>

void DataGroup<ItemType>::rotateRight(int amount)

{

last =3;

lastAmount = amount;

ItemType * temp = new ItemType[amount];

for(int i = MEMBERS_IN_GROUP-1; i < MEMBERS_IN_GROUP-amount; i--)

{

*(temp+i) = data[i];

}

for(int i =amount; i <=0; i--)

{

data[i] = *(temp+i);

}

  

}

template<class ItemType>

void DataGroup<ItemType>::rotateLeft(int amount)

{

last = 4;

lastAmount = amount;

int * temp = new int[amount];

for (int i = 0; i < amount; i++) //save

   {

       temp[i] = data[i];

   }

for (int i = 0; i < MEMBERS_IN_GROUP - amount; i++) //shift

   {

       data[i] = data[i + amount];

   }

int j = MEMBERS_IN_GROUP - amount;

for (int i = 0; i < amount; i++, j++)//retrieve

   {

       data[j] = temp[i];

   }

delete[]temp;

}

template<class ItemType>

void DataGroup<ItemType>::unDue()

{

  

if (last == 1 )

{

   rotateLeft();

   }

else if(last == 2){

   rotateRight();}

else if( last ==3){

   rotateLeft(lastAmount);}

else if(last == 4){

   rotateRight(lastAmount);}

}

template<class ItemType>

void DataGroup<ItemType>::display(ostream & outMofo) const

{

for (int i = 0; i < MEMBERS_IN_GROUP; i++)

   {

       outMofo << data[i] << " ";

   }

   outMofo << endl;

}

//DataGroupOfPointers.h

#ifndef _GROUP_OF_POINTERS_TO_DATA

#define _GROUP_OF_POINTERS_TO_DATA

#include <iostream>

#include <fstream>

using namespace::std;

const int MEMBERS_IN_GROUP_POINTERS = 10;

// ASSUME THERE ARE EXACTLY 10 MEMBERS IN THE GROUP

template<class ItemType>

class DataGroupOfPointers

{

private:

   ItemType * data[MEMBERS_IN_GROUP_POINTERS]; // memory for 10 pointers allocated at compile time

// need to allocate dynamic memory for 10 data ites

// at run time

   // User decides on additional instance fields

public:

   DataGroupOfPointers();

   DataGroupOfPointers(const ItemType *);

   ~DataGroupOfPointers();

   void rotateRight(); // 1 cell

   void rotateLeft(); // 1 cell

   void rotateRight(int amount); // amount 1 <= amount < MEMBERS_IN_GROUP_POINTERS

   void rotateLeft(int amount); // amount 1 <= amount < MEMBERS_IN_GROUP_POINTERS

   void unDue(); // can only undue the last method called , cannot have multiple unDue method calls in a row

   void display(ostream &) const;

}; // end DataGroupOfPointers

#include "DataGroupOfPointers.cpp"

#endif

#include "DataGroupOfPointers.h"

template<class ItemType>

DataGroupOfPointers<ItemType>::DataGroupOfPointers()

{

} // end default constructor

template<class ItemType>

DataGroupOfPointers<ItemType>::DataGroupOfPointers(const ItemType *)

{

} // end constructor

template<class ItemType>

DataGroupOfPointers<ItemType>::~DataGroupOfPointers()

{

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::rotateRight()

{

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::rotateLeft()

{

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::rotateRight(int amount)

{

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::rotateLeft(int amount)

{

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::unDue()

{

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::display(ostream & out) const

{

}

//main.cpp

#include <iostream>

#include <string>

#include "DataGroup.h"

#include "DataGroupOfPointers.h"

using namespace std;

int main()

{

int scores[10] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };

   DataGroup<int> a(scores);

//DataGroupOfPointers<int> aPtr(scores);

   string names[10] = { "Anna", "Bill", "Cathy", "David", "Ethel", "Frank", "Georgia", "Henry", "Irene", "Jeff" };

//DataGroup<string> b(names);

//DataGroupOfPointers<string> bPtr(names);

// test all of your member functions below

   a.rotateLeft();

   a.display(cout);

   a.rotateRight();

   a.display(cout);

   return 0;

} // end main

NEED HELP WITH TEMPLATE DataGroup.cpp and DataGroupOfPointers.cpp

Explanation / Answer

Answer:

Note:Asked to fill methods

Modified Code:

#ifndef _GROUP_OF_DATA

#define _GROUP_OF_DATA

#include <iostream>

#include <fstream>

using namespace::std;

const int MEMBERS_IN_GROUP = 10;

// ASSUME THERE ALWAYS 10 MEMBERS OF THE GROUP

template<class ItemType>

class DataGroup

{

private:

   ItemType data[MEMBERS_IN_GROUP];    // memory for data allocated at compile time

   // User decides on additional instance fields

    int last;

    int lastAmount;

public:

   DataGroup();

   DataGroup(const ItemType *);

   ~DataGroup();

   void rotateRight();             // 1 cell

   void rotateLeft();              // 1 cell

   void rotateRight(int amount);   // amount   1 <= amount < MEMBERS_IN_GROUP

   void rotateLeft(int amount);    // amount   1 <= amount < MEMBERS_IN_GROUP

   void unDue();        // can only undue the last method called , cannot have multiple unDue method calls in a row

   void display(ostream &) const;

  

}; // end DataGroup

#include "DataGroup.cpp"

#endif

//DataGroup.cpp

#include "DataGroup.h"

template<class ItemType>

DataGroup<ItemType>::DataGroup()

{

for (int i = 0; i < MEMBERS_IN_GROUP; i++)

    {

        data[i] = 0;

    }

} // end default constructor

template<class ItemType>

DataGroup<ItemType>::DataGroup(const ItemType * mofo)

{

for (int i = 0; i < MEMBERS_IN_GROUP; i++)

    {

        data[i] = mofo[i];

    }

} // end constructor

template<class ItemType>

DataGroup<ItemType>::~DataGroup()

{

       delete[] data ;

} // end default constructor

template<class ItemType>

void DataGroup<ItemType>::rotateRight()

{

    last =1;

ItemType temp = data[MEMBERS_IN_GROUP-1];

for(int i = MEMBERS_IN_GROUP-1; i >=0; i--)

    {

      data[i] = data[i-1];

    }

data[0] = temp;

}

template<class ItemType>

void DataGroup<ItemType>::rotateLeft()

{

     last =2;

    ItemType temp = data[0];

     for (int i = 1; i < MEMBERS_IN_GROUP; i++)

    {

        data[i - 1] = data[i];

    }

    data[MEMBERS_IN_GROUP - 1] = temp;

}

template<class ItemType>

void DataGroup<ItemType>::rotateRight(int amount)

{

    last =3;

    lastAmount = amount;

     ItemType * temp = new ItemType[amount];

     for(int i = MEMBERS_IN_GROUP-1; i < MEMBERS_IN_GROUP-amount; i--)

    {

      *(temp+i) = data[i];

    }

     for(int i =amount; i <=0; i--)

    {

      data[i] = *(temp+i);

    }

}

template<class ItemType>

void DataGroup<ItemType>::rotateLeft(int amount)

{

    last = 4;

    lastAmount = amount;

int * temp = new int[amount];

for (int i = 0; i < amount; i++) //save

    {

        temp[i] = data[i];

    }

for (int i = 0; i < MEMBERS_IN_GROUP - amount; i++) //shift

    {

        data[i] = data[i + amount];

    }

int j = MEMBERS_IN_GROUP - amount;

for (int i = 0; i < amount; i++, j++)//retrieve

    {

        data[j] = temp[i];

    }

delete[]temp;

}

template<class ItemType>

void DataGroup<ItemType>::unDue()

{

   

if (last == 1 )

{

     rotateLeft();

     }

else if(last == 2){

     rotateRight();}

else if( last ==3){

     rotateLeft(lastAmount);}

else if(last == 4){

     rotateRight(lastAmount);}

}

template<class ItemType>

void DataGroup<ItemType>::display(ostream & outMofo) const

{

for (int i = 0; i < MEMBERS_IN_GROUP; i++)

    {

        outMofo << data[i] << " ";

    }

    outMofo << endl;

}

//DataGroupOfPointers.h

#ifndef _GROUP_OF_POINTERS_TO_DATA

#define _GROUP_OF_POINTERS_TO_DATA

#include <iostream>

#include <fstream>

using namespace::std;

const int MEMBERS_IN_GROUP_POINTERS = 10;

// ASSUME THERE ARE EXACTLY 10 MEMBERS IN THE GROUP

template<class ItemType>

class DataGroupOfPointers

{

private:

   ItemType * data[MEMBERS_IN_GROUP_POINTERS]; // memory for 10 pointers allocated at compile time

                                                //   need to allocate dynamic memory for 10 data ites

                                                //   at run time

   // User decides on additional instance fields

public:

   DataGroupOfPointers();

   DataGroupOfPointers(const ItemType *);

   ~DataGroupOfPointers();

   void rotateRight();               // 1 cell

   void rotateLeft();                // 1 cell

   void rotateRight(int amount);     // amount 1 <= amount < MEMBERS_IN_GROUP_POINTERS

   void rotateLeft(int amount);      // amount 1 <= amount < MEMBERS_IN_GROUP_POINTERS

   void unDue();         // can only undue the last method called , cannot have multiple unDue method calls in a row

   void display(ostream &) const;

}; // end DataGroupOfPointers

#include "DataGroupOfPointers.cpp"

#endif

#include "DataGroupOfPointers.h"

template<class ItemType>

DataGroupOfPointers<ItemType>::DataGroupOfPointers()

{

     for (int i = 0; i < MEMBERS_IN_GROUP; i++)

    {

        data[i] = new ItemType[MEMBERS_IN_GROUP];

    }

} // end default constructor

template<class ItemType>

DataGroupOfPointers<ItemType>::DataGroupOfPointers(const ItemType *input1)

{

     for (int i = 0; i < MEMBERS_IN_GROUP; i++)

    {

        *(data+i) = *(input1+i);

    }

} // end constructor

template<class ItemType>

DataGroupOfPointers<ItemType>::~DataGroupOfPointers()

{

     for (int i = 0; i < MEMBERS_IN_GROUP; i++)

    {

       delete[] data[i] ;

    }

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::rotateRight()

{

last=1;

ItemType *temp=data[MEMBERS_IN_GROUP-1];

for(int i = MEMBERS_IN_GROUP-1; i >=0; i--)

{

    (data+i) = (data+(i-1));

}

data[0] = temp;

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::rotateLeft()

{

     last =2;

    ItemType *temp = (data+0);

     for (int i = 1; i < MEMBERS_IN_GROUP; i++)

    {

        (data+(i-1)) = (data+i);

    }

    (data+(MEMBERS_IN_GROUP - 1)) = temp;

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::rotateRight(int amount)

{

     last =3;

    lastAmount = amount;

     ItemType * temp[amount];

     for(int i=0;i<amount;i++)

          temp[i] = new ItemType[amount];

     for(int i = MEMBERS_IN_GROUP-1; i < MEMBERS_IN_GROUP-amount; i--)

    {

      (temp+i) = (data+i);

    }

     for(int i =amount; i <=0; i--)

    {

      (data+i) = (temp+i);

    }

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::rotateLeft(int amount)

{

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::unDue()

{

     if (last == 1 )

     {

          rotateLeft();

    }

     else if(last == 2)

     {

          rotateRight();

     }

     else if( last ==3)

     {

          rotateLeft(lastAmount);

     }

     else if(last == 4)

     {

          rotateRight(lastAmount);

     }

}

template<class ItemType>

void DataGroupOfPointers<ItemType>::display(ostream & out) const

{

     for (int i = 0; i < MEMBERS_IN_GROUP; i++)

    {

        out << *(data+i) << " ";

    }

    out << endl;

}

//main.cpp

#include <iostream>

#include <string>

#include "DataGroup.h"

#include "DataGroupOfPointers.h"

using namespace std;

int main()

{

int scores[10] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };

    DataGroup<int> a(scores);

//DataGroupOfPointers<int> aPtr(scores);

    string names[10] = { "Anna", "Bill", "Cathy", "David", "Ethel", "Frank", "Georgia", "Henry", "Irene", "Jeff" };

//DataGroup<string> b(names);

//DataGroupOfPointers<string> bPtr(names);

// test all of your member functions below

    a.rotateLeft();

    a.display(cout);

    a.rotateRight();

    a.display(cout);

  

  

   return 0;

} // end main