// File: tdtest2.cpp // // This file checks that // the TwoDimArray class works. // // The [][] operator should do range checking. // #include // Compile using twodim.h or twodim2.h // The second implementation has range checking for columns // while using the [] operator. #include "twodim.h" // #include "twodim2.h" using namespace std ; int main() { unsigned int N = 7 ; TwoDimArray A(N,N) ; // Initialize A with mod 7 times table for (unsigned int i = 0 ; i < N ; i++) { for (unsigned int j = 0 ; j < N ; j++) { A.at(i,j) = (i*j) % N ; } } cout << "\n\nMod " << N << " Multiplication Table:\n\n" ; A.Print() ; N = 9 ; TwoDimArray B(N,N) ; // Initialize B with mod 9 times table for (unsigned int i = 0 ; i < N ; i++) { for (unsigned int j = 0 ; j < N ; j++) { B[i][j] = (i*j) % N ; } } cout << "\n\nMod " << N << " Multiplication Table:\n\n" ; B.Print() ; cout << "Kaboom!\n\n" ; cout << "B[1][17] assigned...\n" ; B[1][17] = 91 ; // Actually worse if this doesn't seg fault cout << "B[1][17000] assigned...\n" ; B[1][17000] = 91 ; // Actually worse if this doesn't seg fault cout << "B[1][17000000] assigned...\n" ; B[1][17000000] = 91 ; // Actually worse if this doesn't seg fault cout << "End of test: " << B[1][17000] << endl ; }