/*---------------------------------------------- * File name: arygnrc.cpp * Author: Xiannong Meng * Date: April 3, 1997 * Assignment: Classroom demonstration * Problem statement: This is the 'implementation' of the * class templates Array. *---------------------------------------------- */ #include #include "arygnrc.tem" // 'header' file of class templates // Constructor, sets up the low bound and upper bound // and initialize the array elements to be 'zero' template Array::Array(IndexType lo, IndexType hi) { lowBound = lo; hiBound = hi; for (IndexType i = lo; i <= hi; i = IndexType((int)i + 1)) array[i] = DataType(0); } // Constructor, sets up the low bound and upper bound // to be 0 and 9 and initialize the array elements to be 'zero' template Array::Array() { lowBound = 0; hiBound = DIM-1; for (IndexType i = lowBound; i <= hiBound; i = IndexType((int)i + 1)) array[i] = DataType(0); } // Read array elements from keyboard template void Array::ReadAry() { for (IndexType i = lowBound; i <= hiBound; i = IndexType((int)i + 1)) { cout << " type in " << i << "th value : "; cin >> array[i]; } } // Print array elements to screen template void Array::PrintAry() { for (IndexType i = lowBound; i <= hiBound; i = IndexType((int)i + 1)) { cout << " print " << i << "th value : " << array[i]; } cout << endl; }