void test15() { cout << "15. Sum of two arrays assigned to third array: IntArray a(1, 5);" << endl; cout << " IntArray b(4, 8);" << endl; cout << " IntArray c = a + b;" << endl << endl; IntArray a(1, 5); for(int i = a.low(); i <= a.high(); i++) a[i] = i * 10; a.setName("a"); cout << a << endl; IntArray b(4, 8); for(int i = b.low(); i <= b.high(); i++) b[i] = i * 10; b.setName("b"); cout << b << endl; IntArray c = a + b; c.setName("c"); cout << "C has a range of " << c.low() << " to " << c.high() << endl; cout << c << endl; cout << "A has a range of " << a.low() << " to " << a.high() << endl; cout << a << endl; cout << "B has a range of " << b.low() << " to " << b.high() << endl; cout << b << endl; IntArray d(-20); cout << d << endl; }
// if intArrays have the same # of elements and those elements are equal bool IntArray::operator==(IntArray ia) { if (length() == ia.length()) { for (int i = 0; i < ia.length(); i++) { if (num[a+i-1] != ia[ia.low()+i]) return false; } return true; } else return false; }
void test5() { system("clear"); cout << "5. Array declared with no integers: IntArray z;" << endl << endl; IntArray z; for(int i = z.low(); i <= z.high(); i++) z[i] = i * 10; z.setName("z"); cout << z << endl; }
bool IntArray::operator+=(IntArray ia) { // cout << *this << endl; if (length() == ia.length()) { for (int i = 0; i <= length(); i++) { num[i] += ia[ia.low()+i]; } return true; } cout << "totally simulating a halt" << endl; return false; }
void test1() { IntArray a; int low = a.low(); int high = a.high(); int size = a.getSize(); cout << "Low is " << low << endl; cout << "High is " << high << endl; for (int i=low; i<=high; i++) a[i] = i * 10; cout << "Array has " << size << " elements " << endl; cout << a << endl; }