// File: p3main4.cpp // // Tests ZoomTable functionality. // Used for grading. // #include #include #include "ZoomTable.h" using namespace std ; // Global two dimensional array. // We're using a global variable here because it is statically allocated // and hopefully immune to pointer problems in the student's code. int ANS[10][7] ; int errors = 0 ; ZoomTable foo(ZoomTable Z) { Node *ptr ; ZoomTable A(5,5) ; A = Z ; // should be able to munge Z without changing A ptr = Z.FirstInRow(1) ; if (ptr != NULL) Z.remove(ptr) ; ptr = Z.FirstInRow(2) ; if (ptr != NULL) Z.remove(ptr) ; ptr = Z.FirstInRow(3) ; if (ptr != NULL) Z.remove(ptr) ; return A ; } int main() { ZoomTable Z(10,7) ; Node *ptr ; int i, j ; // Clear ANS array // for (i = 0 ; i < 10 ; i++) { for (j = 0 ; j < 7 ; j++) { ANS[i][j] = 0 ; } } // Insert some stuff Z.insert(0, 2, 1002) ; Z.insert(8, 6, 1015) ; Z.insert(1, 0, 1004) ; Z.insert(1, 1, 1005) ; Z.insert(5, 4, 1011) ; Z.insert(5, 2, 1010) ; Z.insert(9, 2, 1016) ; Z.insert(1, 5, 1006) ; Z.insert(8, 1, 1013) ; Z.insert(8, 4, 1014) ; Z.insert(1, 6, 1007) ; Z.insert(5, 6, 1012) ; Z.insert(3, 1, 1009) ; Z.insert(0, 0, 1001) ; Z.insert(0, 4, 1003) ; Z.insert(2, 3, 1008) ; // Print ANS array // /* for (i = 0 ; i < 10 ; i++) { for (j = 0 ; j < 7 ; j++) { cout << setw(7) << ANS[i][j] << " " ; } cout << "\n" ; } */ // Store Z in 2-D Global Array // for (i = 0 ; i < 10 ; i++) { for (j = 0 ; j < 7 ; j++) { ANS[i][j] = Z.at(i,j) ; } } ZoomTable B = foo(Z) ; // should be able to munge Z without changing B ptr = Z.FirstInCol(3) ; if (ptr != NULL) Z.remove(ptr) ; ptr = Z.FirstInCol(4) ; if (ptr != NULL) Z.remove(ptr) ; ptr = Z.FirstInCol(6) ; if (ptr != NULL) Z.remove(ptr) ; Z.remove(5,4) ; // Check B against 2-D Global Array // for (i = 0 ; i < 10 ; i++) { for (j = 0 ; j < 7 ; j++) { if (ANS[i][j] != B.at(i,j)) { cerr << "Value not preserved at (" << i << "," << j << ")\n" ; errors++ ; } } } cerr << "Total Copy/Assignment errors = " << errors << "\n" ; }