N rotations of an array, either left or right, and then printing the result Disclaimer, I'm new to OOP, but have experience in haskell and javascript. 

Essentially, the challenge was to create a program which would shift an array a given amount of times to the left and then print the result. 

I've tried to make this more extendable by allowing the option to shift to the right.

My code is

#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

vector&lt;int&gt; rotate(vector&lt;int&gt; myVector, int direction, int count);
vector&lt;int&gt; rotate(vector&lt;int&gt; myVector, int direction);
void print(vector&lt;int&gt; rotatedVector);



void print(vector&lt;int&gt; rotatedVector){
    for(int i = 0; i &lt; rotatedVector.size(); i++){
        cout &lt;&lt; rotatedVector[i] &lt;&lt; endl;
    }
}

vector&lt;int&gt; rotate(vector&lt;int&gt; myVector, int direction, int count){

    while(count &gt; 0){
        myVector = rotate( myVector,  direction); // should I create a new variable, or just overwrite myVector each time?
        --count;
    }

    return myVector;
}

vector&lt;int&gt; rotate(vector&lt;int&gt; myVector, int direction){

    const int length = myVector.size();

    vector&lt;int&gt; rotatedVector(length);

    for(int i = 0; i &lt; myVector.size(); i++){
        rotatedVector.at(i) = myVector.at((length+i-direction)%length);
    }

    return rotatedVector;
}


int main(){

    // Array to rotate
    int arr[5] = {1,2,3,4,5};

    // Times to rotate
    const int count = 2;


    // Creating a vector object out of array
    // Should I have worked with the array given? 
    int n = sizeof(arr) / sizeof(arr[0]); 
    vector&lt;int&gt; myVector(arr, arr + n); 

    enum direction  {left = -1, right = 1}; // should this be global? 

    myVector = rotate(myVector, left, count);

    print(myVector);

    // Could potentially turn vector back into array? 

    return 0 ;
}


My design questions are...


Is this extendable enough, how could it be made more so?  
Should the enums be made global?  
Should I have used multiple
functions instead of using enums to make the rotation functions
generic? (e.g a right rotation function, and a left one)
Should I have kept with the array, instead of creating a vector from it?
Was overloading the function necessary? 


The most important thing I would like to clarify from this review, is the concept of "state" in these types of programming puzzles (done in C++/OOP) 

The line which overwrites the vector is...

myVector = rotate( myVector,  direction);


Is it better form to perhaps implement something like...

myVector.rotate(direction);


and thus action on the same object each time? (and if so why) 

When would I use one over the other? 

In my head, I feel as though it would be best to make the vector immutable and keep creating a new one each time, but am unsure and slightly confused about which one to use.
There are two basic ways to solve this type of problem.  One is having to do the rotation in place, where you can't allocate additional storage for a copy of the array.  This uses less memory but takes longer, since the rotations have to go by small increments (usually 1, since that is easiest to implement).  The other way is to do the rotation into a copy.  This has the advantage of being faster but can take additional memory.  Your implementation is a hybrid of both.

Don't write using namespace std;.

You're passing all your vectors by value, which will result in copies being made.  Since you're making a new vector to store the rotated vector in, you can pass them by const &amp;.  For example,

std::vector&lt;int&gt; rotate(const std::vector&lt;int&gt; &amp;myVector, int direction);


print can take advantage of range based for loops:

void print(const vector&lt;int&gt; &amp;rotatedVector) {
    for (int v: rotatedVector){
        std::cout &lt;&lt; v &lt;&lt; '\n';
    }
}


This also avoids using endl, since that will do a flush which can greatly slow the rate output is displayed.

Your two parameter rotate function can rotate by more than one element at a time.  You can combine the two rotate functions into one, with an offset of -direction * count instead of -direction.  (With appropriate code to precalculate that value and a check so that the result is not larger than -length to avoid having a negative number on the left of %.)