/* This program demonstrates aberrant behavior resulting from
   range errors.

   Output: arrays A, B, and C
------------------------------------------------------------------*/

#include <iostream.h>
#include <iomanip.h>

void PrintArray(const char[], const int[], int);

int main(void)
{
   const int
      ArrayLimit = 4;
   int
      A[ArrayLimit] = {0, 1, 2, 3},
      B[ArrayLimit] = {4, 5, 6, 7},
      C[ArrayLimit] = {8, 9, 10, 11},
      below = -3,
      above = 6;

   PrintArray("A", A, ArrayLimit);
   PrintArray("B", B, ArrayLimit);
   PrintArray("C", C, ArrayLimit);

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

   cout << endl;
   PrintArray("A", A, ArrayLimit);
   PrintArray("B", B, ArrayLimit);
   PrintArray("C", C, ArrayLimit);

   return 0;
}

/*---------------------------------------------------------------*/
void PrintArray(const char Name[], const int L[], int N)
{
  cout << Name << " = ";
  for (int i = 0; i < N; i++)
    cout << setw(5) << L[i];
  cout << endl;
}

