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

need help with rotateRight function!!! #include \"DataGroup.h\" template<class I

ID: 667559 • Letter: N

Question

need help with rotateRight function!!!

#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()

{

}

template<class ItemType>

void DataGroup<ItemType>::rotateLeft()

{

   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)

{

}

template<class ItemType>

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

{

int * temp = new int[amount];

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

   {

       temp[i] = data[i];

   }

#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

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

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()

{

}

template<class ItemType>

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

{

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

   {

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

   }

   outMofo << endl;

}

#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

Explanation / Answer

//DataGroup.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);

               a.rotateLeft();

    a.display(cout);

    a.rotateRight();

    a.display(cout);

//cout<<" Rotating by amount";

//          a.rotateLeft(2);

   // a.display(cout);

// a.rotateRight(2);

   // a.display(cout);

   return 0;

} // end main

//DataGroup.h

#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

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

#endif

//DataGroupPointers.h

#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 destructor

template<class ItemType>

void DataGroup<ItemType>::rotateRight()

{

                   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>::rotateRight(int amount)

{

ItemType * temp = new ItemType[amount];

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

    {

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

    }

   

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

    {

        data[i] = data[i-amount];

    }

   

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

    {

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

    }  

}

template<class ItemType>

void DataGroup<ItemType>::rotateLeft()

{

    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>::rotateLeft(int amount)

{

ItemType * temp = new ItemType[amount];

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

    {

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

    }

   

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

    {

        data[i - amount] = data[i];

    }

    int c=0;

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

    {

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

         c++;

    }  

   

}

template<class ItemType>

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

{

               out<<" Data Elements are:";

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

    {

    out<<data[i]<<" ";

}

}