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 #include using namespace:

ID: 669733 • Letter: #

Question

#ifndef _GROUP_OF_DATA
#define _GROUP_OF_DATA
#include
#include
using namespace::std;

const int MEMBERS_IN_GROUP = 10;
// ASSUME THERE ALWAYS 10 MEMBERS OF THE GROUP
template
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;
   int Undue = 0;

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

#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;
   if (amount <= 0 || amount >= size) return;
lastAmount = amount;
ItemType * temp = new ItemType[amount];
for(int i = 0 i < amount ; i++)
{
       temp[i] = data[MEMBERS_IN_GROUP - amount-1];
}
for(int i =MEMBERS_IN_GROUP-1; i >= amount; i--)
{
data[i] = data[i-amount];
}
for (int i = 0; i < amount; i++){
   data[i] = temp[i];
   delete[] temp;
}

}

template<class ItemType>
void DataGroup<ItemType>::rotateLeft(int amount)
{
last = 4;
   if (amount <= 0 || amount >= MEMBERS_IN_GROUP) return;
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];
   }
   for (int i = 0; i < amount; i++)//retrieve
   {
       data[i + MEMBERS_IN_GROUP- amount] = temp[i];
   }
   delete [] temp;
}


template<class ItemType>
void DataGroup<ItemType>::unDue()
{
   if (Undue == 1){
       if (last == 1)
       {
           rotateLeft();
       }
       else if (last == 2){
           rotateRight();
       }
       else if (last == 3){
           rotateLeft(lastAmount);
       }
       else if (last == 4){
           rotateRight(lastAmount);
       }
   }
   Undue = 0;
}

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
#include
#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 a(scores);
   //DataGroupOfPointers aPtr(scores);

   string names[10] = { "Anna", "Bill", "Cathy", "David", "Ethel", "Frank", "Georgia", "Henry", "Irene", "Jeff" };
   //DataGroup b(names);
   //DataGroupOfPointers bPtr(names);

   // test all of your member functions below

   a.display(cout);
   //a.rotateLeft();
   //a.display(cout);
   cout << "rotated right" << endl;  
   a.rotateRight(2);
   a.display(cout);
   cout << "undue " << endl;
   a.unDue();
   a.display(cout);
   //a.rotateLeft(2);


return 0;
} // end main

NEED HELP on rotate methods & calling functions on main

and check if it runs the others

Explanation / Answer

Note:

    The given code in the question without changing variables and methods is modified as required to run the program.

Program:


//DataGroup.h
#ifndef _GROUP_OF_DATA
#define _GROUP_OF_DATA
#include <iostream>
#include <fstream>
using namespace::std;
const int MEMBERS_IN_GROUP = 10;
template<class ItemType> class DataGroup
{
   // Variable declaretion
   private:
       ItemType data[MEMBERS_IN_GROUP];
       int last;
       int lastAmount;
       int Undue;
   // Method definition
   public:
       DataGroup();
       DataGroup(const ItemType *);
       ~DataGroup();
       void rotateRight();           
       void rotateLeft();            
       void rotateRight(int amount);
       void rotateLeft(int amount);  
       void unDue();      
       void display(ostream &) const;
}; // end DataGroup
#endif

#include "DataGroup.h"
//Constructor
template<class ItemType> DataGroup<ItemType>::DataGroup()
{ }

// Constructor with arguments
template<class ItemType> DataGroup<ItemType>::DataGroup(const ItemType * mofo)
{
    for (int i = 0; i < MEMBERS_IN_GROUP; i++)
    {
        data[i] = mofo[i];
    }
} // end constructor

// Destructor
template<class ItemType> DataGroup<ItemType>::~DataGroup()
{} // end default destructor

// Method to rotate right
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;
}

// Method to rotate right with arguments
template<class ItemType> void DataGroup<ItemType>::rotateRight(int amount)
{
   last = 3;
   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 = MEMBERS_IN_GROUP-amount; i>=0 ; i--)
    {
        data[i] = data[i-amount];
    }
   for (int i =amount ; i <=0; i--)
    {
        data[i]=*(temp+i) ;
    }
}

// Method to rotate left
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;
}

// Method to rotate left with arguments
template<class ItemType> void DataGroup<ItemType>::rotateLeft(int amount)
{
   last = 4;
   ItemType * temp = new ItemType[amount];
   for (int i = 0; i < amount; i++)
    {
       *(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++)
    {
        data[i]=*(temp+c) ;
        c++;
    }
}

// Method for undue
template<class ItemType> void DataGroup<ItemType>::unDue()
{
    if (Undue == 1){
        if (last == 1)
        {
            rotateLeft();
        }
        else if (last == 2){
            rotateRight();
        }
        else if (last == 3){
            rotateLeft(lastAmount);
        }
        else if (last == 4){
            rotateRight(lastAmount);
        }
    }
    Undue = 0;
}

// Method to display the values
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]<<" ";
   }
}


//DataGroup.cpp
#include <iostream>
#include <fstream>
#include "DataGroup.h"
#include "DataGroupOfPointers.h"
using namespace std;
// Main method
int main()
{
   // Declare the required variables and initialize the values
   int scores[10] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
   DataGroup<int> a(scores);
   string names[10] = { "Anna", "Bill", "Cathy", "David", "Ethel", "Frank", "Georgia", "Henry", "Irene", "Jeff" };

   // Call method to perform the operation
   a.display(cout);
   a.rotateLeft();
   a.display(cout);
   cout << "rotated right" << endl;
   a.rotateRight(2);
   a.display(cout);

   a.display(cout);
   a.rotateLeft(2);
   system("pause");
   return 0;
}

Result:


Data Elements are:10 20 30 40 50 60 70 80 90 100
Data Elements are:20 30 40 50 60 70 80 90 100 10

rotated right

Data Elements are:-858993460 -858993460 20 30 40 50 60 70 80 10
Data Elements are:-858993460 -858993460 20 30 40 50 60 70 80 10
Press any key tocontinue . . .