/* outofrange.cpp demonstrates aberrant behavior 
 * resulting from out-of-range errors.
 ***********************************************/

#include <iostream>            // cout, <<

const int CAPACITY = 4;
typedef int IntArray[CAPACITY];

void PrintArray(char name, IntArray x, int numElements);


int main()
{

   IntArray a = {0, 1, 2, 3},
            b = {4, 5, 6, 7},
            c = {8, 9, 10, 11};
   int below = -3,
       above = 6;

   PrintArray('a', a, 4);
   PrintArray('b', b, 4);
   PrintArray('c', c, 4);

   b[below] = -999;
   b[above] = 999;

   cout << endl;
   PrintArray('a', a, 4);
   PrintArray('b', b, 4);
   PrintArray('c', c, 4);

   return 0;
}

#include <iomanip>             // setw()

/* PrintArray() displays an int array.
 *
 * Receives:  name, a character, and x. an int array
 * Output:    name of array, and 4 values stored in it
 ******************************************************/

void PrintArray(char name, IntArray x, int numElements)
{
   cout << name << " = ";
   for (int i = 0; i < numElements; i++)
      cout << setw(5) << x[i];
   cout << endl;
}


