|
//file : p010.cpp //author: AOU //date : 07/15/2004 /* Project #7 07/15/2004 bool isEqualTo(const CArray &a2) const; bool operator ==(const CArray &a2) const; bool operator !=(const CArray &a2) const; Project #6 07/14/2004 friend bool isEqualTo(const CArray &a1, const CArray &a2); CArray(const CArray &second); and identify contstant functions Project #5 07/13/2004 void shuffle(void); friend void shuffle(CArray &a1); Project #4 07/12/2004 bool has(int x); bool hasDistinctValues(void); */ #include <iostream.h> #include <stdlib.h> #include <time.h> const int ARRAY_SIZE = 10; const int MIN_VALUE = 0; const int MAX_VALUE = 6; const int TEST_COUNT = 5; void testAll(void); void test_populate(void); void test_sortBubble(void); void test_isSorted(void); void test_constructor_n(void); void test_constructor_r(void); void test_constructor_s(void); void test_constructor_d(void); void test_has(void); void test_hasDistinctValues(void); void test_shuffle(void); void test_shuffle_friend(void); void test_isEqualTo_friend(void); void test_constructor_copy(void); void test_isEqualTo_member(void); void test_isEqualTo_operator(void); void test_isNotEqualTo_operator(void); class CArray { private: int a[ARRAY_SIZE]; int n; public: CArray(void); void populate(void); void display(void) const; void sortBubble(void); bool isSorted(void) const; void display(int m) const; CArray(int n); CArray(char ch); bool has(int x) const; // myArray.has(x) bool hasDistinctValues(void) const; void shuffle(void); friend void shuffle(CArray &a1); friend bool isEqualTo(const CArray &a1, const CArray &a2); CArray(const CArray &second); bool isEqualTo(const CArray &a2) const; bool operator ==(const CArray &a2) const; bool operator !=(const CArray &a2) const; }; void main(void) { //test_populate(); //test_sortBubble(); //test_isSorted(); //test_constructor_n(); //test_constructor_r(); //test_constructor_s(); //test_constructor_d(); //test_has(); //test_hasDistinctValues(); //test_shuffle(); //test_shuffle_friend(); //test_isEqualTo_friend(); //test_constructor_copy(); //test_isEqualTo_member(); //test_isEqualTo_operator(); //test_isNotEqualTo_operator(); testAll(); } ///////////////////////////////////////////////// ///////////////////////////////////////////////// void testAll(void) { test_populate(); test_sortBubble(); test_isSorted(); test_constructor_n(); test_constructor_r(); test_constructor_s(); test_constructor_d(); test_has(); test_hasDistinctValues(); test_shuffle(); test_shuffle_friend(); test_isEqualTo_friend(); test_constructor_copy(); test_isEqualTo_member(); test_isEqualTo_operator(); test_isNotEqualTo_operator(); } ///////////////////////////////////////////////// // bool CArray::operator !=(const CArray &a2) const ///////////////////////////////////////////////// bool CArray::operator !=(const CArray &a2) const { return !(*this == a2); //return !(::isEqualTo(*this, a2)); //return !(this->isEqualTo(a2)); /* if (*this == a2) return false; else return true; */ /* if (this->n != a2.n) return true; for (int i=0; i<=this->n-1; i++) if (this->a[i] != a2.a[i]) return true; return false; */ } ///////////////////////////////////////////////// // test_isNotEqualTo_operator ///////////////////////////////////////////////// void test_isNotEqualTo_operator(void) { cout << "++++++++++++++++++++++++++\n"; cout << "test_isNotEqualTo_operator\n"; cout << "++++++++++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('r'), a2('r'); cout << "a1="; a1.display(); cout << "a2="; a2.display(); if (a1 != a2) cout << "a1 is NOT equal to a2\n"; else cout << "a1 is equal to a2\n"; if (a1 != a1) cout << "a1 is NOT equal to a1\n"; else cout << "a1 is equal to a1\n"; a1 = a2; //??? assigning a2 to a1 cout << "After a1 = a2;\n"; cout << "a1="; a1.display(); cout << "a2="; a2.display(); if (a1 != a2) cout << "a1 is NOT equal to a2\n"; else cout << "a1 is equal to a2\n"; cout << "----------------\n"; } } ///////////////////////////////////////////////// // bool CArray::operator ==(const CArray &a2) const ///////////////////////////////////////////////// bool CArray::operator ==(const CArray &a2) const { if (this->n != a2.n) return false; for (int i=0; i<=this->n-1; i++) if (this->a[i] != a2.a[i]) return false; return true; } ///////////////////////////////////////////////// // test_isEqualTo_operator ///////////////////////////////////////////////// void test_isEqualTo_operator(void) { cout << "+++++++++++++++++++++++\n"; cout << "test_isEqualTo_operator\n"; cout << "+++++++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('r'), a2('r'); cout << "a1="; a1.display(); cout << "a2="; a2.display(); if (a1 == a2) //if (a1.operator ==(a2)) cout << "a1 is equal to a2\n"; else cout << "a1 is NOT equal to a2\n"; if (a1 == a1) cout << "a1 is equal to a1\n"; else cout << "a1 is NOT equal to a1\n"; a1 = a2; //??? assigning a2 to a1 cout << "After a1 = a2;\n"; cout << "a1="; a1.display(); cout << "a2="; a2.display(); if (a1 == a2) cout << "a1 is equal to a2\n"; else cout << "a1 is NOT equal to a2\n"; cout << "----------------\n"; } } ///////////////////////////////////////////////// // bool CArray::isEqualTo(const CArray &a2) const ///////////////////////////////////////////////// bool CArray::isEqualTo(const CArray &a2) const { if (this->n != a2.n) return false; for (int i=0; i<=this->n-1; i++) if (this->a[i] != a2.a[i]) return false; return true; } ///////////////////////////////////////////////// // test_isEqualTo_member ///////////////////////////////////////////////// void test_isEqualTo_member(void) { cout << "+++++++++++++++++++++\n"; cout << "test_isEqualTo_member\n"; cout << "+++++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('r'), a2('r'); cout << "a1="; a1.display(); cout << "a2="; a2.display(); if (a1.isEqualTo(a2)) cout << "a1 is equal to a2\n"; else cout << "a1 is NOT equal to a2\n"; if (a1.isEqualTo(a1)) cout << "a1 is equal to a1\n"; else cout << "a1 is NOT equal to a1\n"; a1 = a2; //??? assigning a2 to a1 cout << "After a1 = a2;\n"; cout << "a1="; a1.display(); cout << "a2="; a2.display(); if (a1.isEqualTo(a2)) cout << "a1 is equal to a2\n"; else cout << "a1 is NOT equal to a2\n"; cout << "----------------\n"; } } ///////////////////////////////////////////////// // CArray::CArray(const CArray &second) ///////////////////////////////////////////////// CArray::CArray(const CArray &second) { cout << "Copy constructor CArray(CArray &second) was called\n"; this->n = second.n; for (int i=0; i<=second.n-1; i++) this->a[i] = second.a[i]; } ///////////////////////////////////////////////// // test_constructor_copy ///////////////////////////////////////////////// void test_constructor_copy(void) { cout << "+++++++++++++++++++++\n"; cout << "test_constructor_copy\n"; cout << "+++++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('r'); cout << "a1="; a1.display(); CArray a2(a1); cout << "a2="; a2.display(); cout << "a1="; a1.display(); cout << "----------------\n"; } } ///////////////////////////////////////////////// // bool isEqualTo(const CArray &a1, const CArray &a2) ///////////////////////////////////////////////// bool isEqualTo(const CArray &a1, const CArray &a2) { //a1.n =a2.n = 0; protected by const gun if (a1.n != a2.n) return false; for (int i=0; i<=a1.n-1; i++) if (a1.a[i] != a2.a[i]) return false; return true; } ///////////////////////////////////////////////// // test_isEqualTo_friend ///////////////////////////////////////////////// void test_isEqualTo_friend(void) { cout << "+++++++++++++++++++++\n"; cout << "test_isEqualTo_friend\n"; cout << "+++++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('r'), a2('r'); cout << "a1="; a1.display(); cout << "a2="; a2.display(); if (isEqualTo(a1, a2)) cout << "a1 is equal to a2\n"; else cout << "a1 is NOT equal to a2\n"; if (isEqualTo(a1, a1)) cout << "a1 is equal to a1\n"; else cout << "a1 is NOT equal to a1\n"; a1 = a2; //??? assigning a2 to a1 cout << "After a1 = a2;\n"; cout << "a1="; a1.display(); cout << "a2="; a2.display(); if (isEqualTo(a1, a2)) cout << "a1 is equal to a2\n"; else cout << "a1 is NOT equal to a2\n"; cout << "----------------\n"; } } ///////////////////////////////////////////////// // void shuffle(CArray &a1) ///////////////////////////////////////////////// void shuffle(CArray &a1) { for (int i=1; i<=a1.n*a1.n*a1.n; i++) { int k47 = rand()%a1.n; int temp = a1.a[0]; a1.a[0] = a1.a[k47]; a1.a[k47] = temp; } } ///////////////////////////////////////////////// // void test_shuffle_friend(void) ///////////////////////////////////////////////// void test_shuffle_friend(void) { cout << "+++++++++++++++++++\n"; cout << "test_shuffle_friend\n"; cout << "+++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('s'); a1.display(); shuffle(a1); cout << "After shuffle\n"; a1.display(); cout << "----------------\n"; } } ///////////////////////////////////////////////// // void CArray::shuffle(void) ///////////////////////////////////////////////// /* do the following n*n times swap a random value with the first value */ void CArray::shuffle(void) { for (int i=1; i<=n*n*n; i++) { int k47 = rand()%n; int temp = a[0]; a[0] = a[k47]; a[k47] = temp; } } ///////////////////////////////////////////////// // void test_shuffle(void) ///////////////////////////////////////////////// void test_shuffle(void) { cout << "++++++++++++\n"; cout << "test_shuffle\n"; cout << "++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('s'); a1.display(); a1.shuffle(); cout << "After shuffle\n"; a1.display(); cout << "----------------\n"; } } ///////////////////////////////////////////////// // bool CArray::hasDistinctValues(void) const ///////////////////////////////////////////////// bool CArray::hasDistinctValues(void) const { if (n<2) return true; int left, right; for (left = 0; left<=n-2; left++) for (right=left+1; right<=n-1; right++) if(a[left] == a[right]) return false; return true; } ///////////////////////////////////////////////// // void test_hasDistinctValues(void) ///////////////////////////////////////////////// void test_hasDistinctValues(void) { cout << "++++++++++++++++++++++\n"; cout << "test_hasDistinctValues\n"; cout << "++++++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('r'); a1.display(); if (a1.hasDistinctValues()) cout << "list has distinct values\n"; else cout << "list does NOT have distinct values\n"; CArray a2('d'); a2.display(); if (a2.hasDistinctValues()) cout << "list has distinct values\n"; else cout << "list does NOT have distinct values\n"; cout << "----------------\n"; } } ///////////////////////////////////////////////// // bool CArray::has(int x) const ///////////////////////////////////////////////// bool CArray::has(int x) const // myArray.has(x) // possibilities // n=0 and n>0 // n=0 =>false // n>0 =>false or true /* Algorithm: if n is 0 then return false else if x matches with any element in a[] return true else return false */ { if (0==n) return false; else { for (int j=0; j<=n-1; j++) if (x==a[j]) return true; return false; } } ///////////////////////////////////////////////// // void test_has(void) ///////////////////////////////////////////////// void test_has(void) { cout << "++++++++\n"; cout << "test_has\n"; cout << "++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('r'); a1.display(); int x = MIN_VALUE + rand()%(MAX_VALUE-MIN_VALUE+1); cout << "Searching for " << x << endl; if (a1.has(x)) cout << x << " is in the list\n"; else cout << x << " is in NOT the list\n"; cout << "----------------\n"; } } ///////////////////////////////////////////////// // CArray::CArray(void) ///////////////////////////////////////////////// CArray::CArray(void) { cout << "Constructor CArray(void) was called\n"; n = 0; for (int i=0; i<ARRAY_SIZE; i++) a[i] = 0; } ///////////////////////////////////////////////// // void CArray::display(void) const ///////////////////////////////////////////////// void CArray::display(void) const { cout << "a[" << n << "] = "; for (int i=0; i<=n-1; i++) cout << a[i] << ' '; cout << endl; } ///////////////////////////////////////////////// // void CArray::populate(void) ///////////////////////////////////////////////// void CArray::populate(void) { n = rand()%(ARRAY_SIZE+1); for (int i=0; i<=n-1; i++) a[i] = MIN_VALUE + rand()%(MAX_VALUE-MIN_VALUE+1); } ///////////////////////////////////////////////// // void CArray::sortBubble(void) ///////////////////////////////////////////////// void CArray::sortBubble(void) { int swapCount; do { swapCount = 0; for (int i=0; i<=n-2; i++) { if (a[i] > a[i+1]) { int temp = a[i]; a[i]=a[i+1]; a[i+1] = temp; swapCount++; } } } while (swapCount>0); } ///////////////////////////////////////////////// // bool CArray::isSorted(void) const ///////////////////////////////////////////////// bool CArray::isSorted(void) const { for (int i=0; i<=n-2; i++) if (a[i] > a[i+1]) return false; return true; } ///////////////////////////////////////////////// // void CArray::display(int m) const ///////////////////////////////////////////////// void CArray::display(int m) const { while (m-- > 0) { //display(); //CArray::display(); //(*this).display(); this->display(); } } ///////////////////////////////////////////////// // CArray::CArray(int n) ///////////////////////////////////////////////// CArray::CArray(int n) { cout << "Constructor CArray(int n) was called\n"; if (n > ARRAY_SIZE) n = ARRAY_SIZE; this->n = n; //CArray::n = n; //(*this).n = n; for (int i=0; i<n; i++) a[i] = MIN_VALUE + rand()%(MAX_VALUE-MIN_VALUE+1); } ///////////////////////////////////////////////// // CArray::CArray(char ch) ///////////////////////////////////////////////// CArray::CArray(char ch) { cout << "Constructor CArray(char ch) was called\n"; if ('r' == ch || 'R' == ch) this->populate(); else if ('s' == ch || 'S' == ch) { this->populate(); this->sortBubble(); } else if ('d' == ch || 'D' == ch) { n = 0; int times = rand()%(ARRAY_SIZE+1); for (int i=1; i<=times; i++) { int x = MIN_VALUE + rand()%(MAX_VALUE-MIN_VALUE+1); if (!this->has(x)) a[n++] = x; } } else n = 0; } ///////////////////////////////////////////////// // void test_constructor_r(void) ///////////////////////////////////////////////// void test_constructor_r(void) { cout << "++++++++++++++++++\n"; cout << "test_constructor_r\n"; cout << "++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('r'); cout << "After CArray a1('r');\n"; a1.display(); cout << "----------------\n"; } } ///////////////////////////////////////////////// // void test_constructor_s(void) ///////////////////////////////////////////////// void test_constructor_s(void) { cout << "++++++++++++++++++\n"; cout << "test_constructor_s\n"; cout << "++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('s'); cout << "After CArray a1('s');\n"; a1.display(); cout << "----------------\n"; } } ///////////////////////////////////////////////// // void test_constructor_d(void) ///////////////////////////////////////////////// void test_constructor_d(void) { cout << "++++++++++++++++++\n"; cout << "test_constructor_d\n"; cout << "++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1('d'); cout << "After CArray a1('d');\n"; a1.display(); cout << "----------------\n"; } } ///////////////////////////////////////////////// // void test_populate(void) ///////////////////////////////////////////////// void test_populate(void) { cout << "+++++++++++++\n"; cout << "test_populate\n"; cout << "+++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1; a1.display(); a1.populate(); a1.display(); cout << "----------------\n"; } } ///////////////////////////////////////////////// // void test_sortBubble(void) ///////////////////////////////////////////////// void test_sortBubble(void) { cout << "+++++++++++++++\n"; cout << "test_sortBubble\n"; cout << "+++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1; a1.populate(); a1.display(); a1.sortBubble(); cout << "After sortBubble()\n"; a1.display(); cout << "----------------\n"; } } ///////////////////////////////////////////////// // void test_isSorted(void) ///////////////////////////////////////////////// void test_isSorted(void) { cout << "+++++++++++++\n"; cout << "test_isSorted\n"; cout << "+++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { CArray a1; a1.populate(); a1.display(); a1.sortBubble(); cout << "After sortBubble()\n"; a1.display(); if (a1.isSorted()) cout << "SORT successful\n"; else cout << "SORT NOT successful\n"; cout << "----------------\n"; } } ///////////////////////////////////////////////// // void test_constructor_n(void) ///////////////////////////////////////////////// void test_constructor_n(void) { cout << "++++++++++++++++++\n"; cout << "test_constructor_n\n"; cout << "++++++++++++++++++\n"; for (int i=1; i<=TEST_COUNT; i++) { int n = rand()%(ARRAY_SIZE*2); CArray a1(n); cout << "After CArray a1(" << n << ");\n"; a1.display(); cout << "----------------\n"; } } /* Output: +++++++++++++ test_populate +++++++++++++ Constructor CArray(void) was called a[0] = a[8] = 1 6 5 3 2 5 0 5 ---------------- Constructor CArray(void) was called a[0] = a[0] = ---------------- Constructor CArray(void) was called a[0] = a[7] = 5 6 6 0 1 6 0 ---------------- Constructor CArray(void) was called a[0] = a[9] = 4 2 2 3 6 5 6 5 5 ---------------- Constructor CArray(void) was called a[0] = a[6] = 1 1 5 1 2 0 ---------------- +++++++++++++++ test_sortBubble +++++++++++++++ Constructor CArray(void) was called a[2] = 5 0 After sortBubble() a[2] = 0 5 ---------------- Constructor CArray(void) was called a[7] = 3 3 4 4 2 5 2 After sortBubble() a[7] = 2 2 3 3 4 4 5 ---------------- Constructor CArray(void) was called a[5] = 4 1 1 4 1 After sortBubble() a[5] = 1 1 1 4 4 ---------------- Constructor CArray(void) was called a[3] = 4 3 0 After sortBubble() a[3] = 0 3 4 ---------------- Constructor CArray(void) was called a[0] = After sortBubble() a[0] = ---------------- +++++++++++++ test_isSorted +++++++++++++ Constructor CArray(void) was called a[6] = 5 1 3 4 0 1 After sortBubble() a[6] = 0 1 1 3 4 5 SORT successful ---------------- Constructor CArray(void) was called a[2] = 6 3 After sortBubble() a[2] = 3 6 SORT successful ---------------- Constructor CArray(void) was called a[10] = 0 3 6 5 0 2 3 6 5 0 After sortBubble() a[10] = 0 0 0 2 3 3 5 5 6 6 SORT successful ---------------- Constructor CArray(void) was called a[6] = 6 1 2 4 4 3 After sortBubble() a[6] = 1 2 3 4 4 6 SORT successful ---------------- Constructor CArray(void) was called a[4] = 3 5 1 2 After sortBubble() a[4] = 1 2 3 5 SORT successful ---------------- ++++++++++++++++++ test_constructor_n ++++++++++++++++++ Constructor CArray(int n) was called After CArray a1(4); a[4] = 1 0 4 0 ---------------- Constructor CArray(int n) was called After CArray a1(18); a[10] = 4 3 4 0 3 0 5 6 3 4 ---------------- Constructor CArray(int n) was called After CArray a1(17); a[10] = 3 5 0 2 3 2 4 5 5 2 ---------------- Constructor CArray(int n) was called After CArray a1(13); a[10] = 1 6 4 4 5 2 4 1 2 6 ---------------- Constructor CArray(int n) was called After CArray a1(11); a[10] = 5 1 2 1 3 1 0 6 0 3 ---------------- ++++++++++++++++++ test_constructor_r ++++++++++++++++++ Constructor CArray(char ch) was called After CArray a1('r'); a[7] = 1 2 5 2 0 5 2 ---------------- Constructor CArray(char ch) was called After CArray a1('r'); a[1] = 1 ---------------- Constructor CArray(char ch) was called After CArray a1('r'); a[9] = 3 5 3 3 5 6 4 6 2 ---------------- Constructor CArray(char ch) was called After CArray a1('r'); a[5] = 1 3 2 6 2 ---------------- Constructor CArray(char ch) was called After CArray a1('r'); a[4] = 1 2 4 4 ---------------- ++++++++++++++++++ test_constructor_s ++++++++++++++++++ Constructor CArray(char ch) was called After CArray a1('s'); a[6] = 1 1 2 4 4 6 ---------------- Constructor CArray(char ch) was called After CArray a1('s'); a[0] = ---------------- Constructor CArray(char ch) was called After CArray a1('s'); a[0] = ---------------- Constructor CArray(char ch) was called After CArray a1('s'); a[9] = 0 0 1 1 2 4 4 4 5 ---------------- Constructor CArray(char ch) was called After CArray a1('s'); a[5] = 1 4 4 6 6 ---------------- ++++++++++++++++++ test_constructor_d ++++++++++++++++++ Constructor CArray(char ch) was called After CArray a1('d'); a[1] = 2 ---------------- Constructor CArray(char ch) was called After CArray a1('d'); a[2] = 0 1 ---------------- Constructor CArray(char ch) was called After CArray a1('d'); a[4] = 6 0 1 4 ---------------- Constructor CArray(char ch) was called After CArray a1('d'); a[4] = 2 5 3 6 ---------------- Constructor CArray(char ch) was called After CArray a1('d'); a[4] = 3 5 4 0 ---------------- ++++++++ test_has ++++++++ Constructor CArray(char ch) was called a[3] = 0 3 1 Searching for 2 2 is in NOT the list ---------------- Constructor CArray(char ch) was called a[9] = 4 4 2 0 4 1 4 5 6 Searching for 3 3 is in NOT the list ---------------- Constructor CArray(char ch) was called a[4] = 5 4 3 4 Searching for 2 2 is in NOT the list ---------------- Constructor CArray(char ch) was called a[6] = 0 0 1 0 0 3 Searching for 6 6 is in NOT the list ---------------- Constructor CArray(char ch) was called a[4] = 3 2 2 6 Searching for 1 1 is in NOT the list ---------------- ++++++++++++++++++++++ test_hasDistinctValues ++++++++++++++++++++++ Constructor CArray(char ch) was called a[4] = 3 4 1 1 list does NOT have distinct values Constructor CArray(char ch) was called a[5] = 4 1 0 2 3 list has distinct values ---------------- Constructor CArray(char ch) was called a[8] = 2 3 3 2 1 4 1 4 list does NOT have distinct values Constructor CArray(char ch) was called a[0] = list has distinct values ---------------- Constructor CArray(char ch) was called a[6] = 3 1 6 4 6 4 list does NOT have distinct values Constructor CArray(char ch) was called a[5] = 3 4 5 2 6 list has distinct values ---------------- Constructor CArray(char ch) was called a[5] = 0 6 3 0 4 list does NOT have distinct values Constructor CArray(char ch) was called a[2] = 4 5 list has distinct values ---------------- Constructor CArray(char ch) was called a[10] = 5 6 6 2 0 0 6 4 4 0 list does NOT have distinct values Constructor CArray(char ch) was called a[0] = list has distinct values ---------------- ++++++++++++ test_shuffle ++++++++++++ Constructor CArray(char ch) was called a[5] = 0 2 2 2 5 After shuffle a[5] = 0 5 2 2 2 ---------------- Constructor CArray(char ch) was called a[10] = 0 0 1 1 2 2 3 3 4 6 After shuffle a[10] = 4 2 3 0 3 1 1 2 6 0 ---------------- Constructor CArray(char ch) was called a[10] = 0 1 1 1 2 2 5 5 5 6 After shuffle a[10] = 1 5 5 1 0 1 5 2 2 6 ---------------- Constructor CArray(char ch) was called a[2] = 4 5 After shuffle a[2] = 4 5 ---------------- Constructor CArray(char ch) was called a[3] = 1 1 5 After shuffle a[3] = 1 1 5 ---------------- +++++++++++++++++++ test_shuffle_friend +++++++++++++++++++ Constructor CArray(char ch) was called a[4] = 5 5 5 6 After shuffle a[4] = 5 5 5 6 ---------------- Constructor CArray(char ch) was called a[0] = After shuffle a[0] = ---------------- Constructor CArray(char ch) was called a[9] = 1 1 2 3 3 4 4 4 5 After shuffle a[9] = 4 1 3 1 2 5 4 3 4 ---------------- Constructor CArray(char ch) was called a[4] = 0 2 3 5 After shuffle a[4] = 2 5 3 0 ---------------- Constructor CArray(char ch) was called a[2] = 4 4 After shuffle a[2] = 4 4 ---------------- +++++++++++++++++++++ test_isEqualTo_friend +++++++++++++++++++++ Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[5] = 2 0 5 6 3 a2=a[6] = 5 0 1 3 1 4 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[6] = 5 0 1 3 1 4 a2=a[6] = 5 0 1 3 1 4 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[4] = 4 3 6 1 a2=a[0] = a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[0] = a2=a[0] = a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[6] = 1 1 5 3 1 2 a2=a[2] = 1 2 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[2] = 1 2 a2=a[2] = 1 2 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[1] = 2 a2=a[2] = 4 6 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[2] = 4 6 a2=a[2] = 4 6 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[1] = 0 a2=a[3] = 5 6 3 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[3] = 5 6 3 a2=a[3] = 5 6 3 a1 is equal to a2 ---------------- +++++++++++++++++++++ test_constructor_copy +++++++++++++++++++++ Constructor CArray(char ch) was called a1=a[8] = 2 5 5 2 2 1 0 5 Copy constructor CArray(CArray &second) was called a2=a[8] = 2 5 5 2 2 1 0 5 a1=a[8] = 2 5 5 2 2 1 0 5 ---------------- Constructor CArray(char ch) was called a1=a[10] = 6 2 5 6 1 5 3 0 6 3 Copy constructor CArray(CArray &second) was called a2=a[10] = 6 2 5 6 1 5 3 0 6 3 a1=a[10] = 6 2 5 6 1 5 3 0 6 3 ---------------- Constructor CArray(char ch) was called a1=a[6] = 4 5 0 3 0 6 Copy constructor CArray(CArray &second) was called a2=a[6] = 4 5 0 3 0 6 a1=a[6] = 4 5 0 3 0 6 ---------------- Constructor CArray(char ch) was called a1=a[2] = 4 6 Copy constructor CArray(CArray &second) was called a2=a[2] = 4 6 a1=a[2] = 4 6 ---------------- Constructor CArray(char ch) was called a1=a[9] = 1 2 4 0 1 5 5 6 3 Copy constructor CArray(CArray &second) was called a2=a[9] = 1 2 4 0 1 5 5 6 3 a1=a[9] = 1 2 4 0 1 5 5 6 3 ---------------- +++++++++++++++++++++ test_isEqualTo_member +++++++++++++++++++++ Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[3] = 0 5 0 a2=a[7] = 1 0 5 6 5 4 2 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[7] = 1 0 5 6 5 4 2 a2=a[7] = 1 0 5 6 5 4 2 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[4] = 6 1 1 5 a2=a[5] = 1 6 1 3 4 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[5] = 1 6 1 3 4 a2=a[5] = 1 6 1 3 4 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[5] = 6 3 1 5 4 a2=a[0] = a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[0] = a2=a[0] = a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[5] = 6 0 2 4 2 a2=a[10] = 4 1 3 4 0 1 5 1 3 3 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[10] = 4 1 3 4 0 1 5 1 3 3 a2=a[10] = 4 1 3 4 0 1 5 1 3 3 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[6] = 6 2 1 3 4 1 a2=a[0] = a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[0] = a2=a[0] = a1 is equal to a2 ---------------- +++++++++++++++++++++++ test_isEqualTo_operator +++++++++++++++++++++++ Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[0] = a2=a[10] = 4 4 2 4 3 6 0 6 4 5 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[10] = 4 4 2 4 3 6 0 6 4 5 a2=a[10] = 4 4 2 4 3 6 0 6 4 5 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[4] = 1 5 6 3 a2=a[0] = a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[0] = a2=a[0] = a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[7] = 6 1 2 5 0 4 2 a2=a[5] = 2 5 0 6 4 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[5] = 2 5 0 6 4 a2=a[5] = 2 5 0 6 4 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[0] = a2=a[3] = 5 2 3 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[3] = 5 2 3 a2=a[3] = 5 2 3 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[1] = 0 a2=a[6] = 4 1 6 4 3 1 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[6] = 4 1 6 4 3 1 a2=a[6] = 4 1 6 4 3 1 a1 is equal to a2 ---------------- ++++++++++++++++++++++++++ test_isNotEqualTo_operator ++++++++++++++++++++++++++ Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[8] = 4 5 4 6 6 2 1 1 a2=a[7] = 6 2 2 1 5 5 3 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[7] = 6 2 2 1 5 5 3 a2=a[7] = 6 2 2 1 5 5 3 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[9] = 6 4 6 3 6 6 5 0 1 a2=a[10] = 0 3 0 2 6 1 2 2 5 2 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[10] = 0 3 0 2 6 1 2 2 5 2 a2=a[10] = 0 3 0 2 6 1 2 2 5 2 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[1] = 5 a2=a[2] = 5 4 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[2] = 5 4 a2=a[2] = 5 4 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[4] = 2 3 1 3 a2=a[9] = 4 6 3 2 4 3 4 1 2 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[9] = 4 6 3 2 4 3 4 1 2 a2=a[9] = 4 6 3 2 4 3 4 1 2 a1 is equal to a2 ---------------- Constructor CArray(char ch) was called Constructor CArray(char ch) was called a1=a[3] = 1 3 3 a2=a[9] = 4 4 1 5 3 6 6 2 1 a1 is NOT equal to a2 a1 is equal to a1 After a1 = a2; a1=a[9] = 4 4 1 5 3 6 6 2 1 a2=a[9] = 4 4 1 5 3 6 6 2 1 a1 is equal to a2 ---------------- Press any key to continue */ |