/*********************************************************************
example 4 - safearray.h
    combining put() and get() with access() using return by reference
*********************************************************************/
#include <iostream>
using namespace std;
#include <process.h> //for the exit() function

const int maxsize = 100;
//class definition
class safearray {
    private:
        int array[maxsize];
    public:
        int& access(const int& pos) {
            if ((pos < 0) || (pos >= maxsize)) {
                cerr << endl << "Index out of bounds" << endl;
                exit(1);
            }
            return array[pos];
        }

        const int& access(const int& pos) const {
            if ((pos < 0) || (pos >= maxsize)) {
                cerr << endl << "Index out of bounds" << endl;
                exit(1);
            }
            return array[pos];
        }

};