// arraymain.cpp - demo for CS 32 // Question: Where's the memory leak? // cmc, 11/2/2011 #include #include "intarray.h" using namespace std; int sumArray(const IntArray array); IntArray newArray(int size, int start, int step); int main() { cout << "**Section 1**" << endl; IntArray a, b(4); b.set(0,10); b.set(1,20); b.set(2,30); b.set(3,40); cout << "a: " << a << endl; cout << "b: " << b << endl; cout << "**Section 2**" << endl; IntArray c = b, d(c); cout << "c: " << c << endl; cout << "d: " << d << endl; cout << "**Section 3**" << endl; a = a; a = b; cout << "a: " << a << endl; cout << "b: " << b << endl; cout << "**Section 4**" << endl; cout << "sum of elements in a: " << sumArray(a) << endl; cout << "**Section 5**" << endl; IntArray e = newArray(5, 8, 8); cout << "e:" << e << endl; cout << "**DONE**" << endl; return 0; } IntArray newArray(int size, int start, int step) { IntArray *result = new IntArray(size); for (int i=0; iset(i, start + step * i); return *result; } int sumArray(const IntArray array) { int sum = 0; for (int i=0; i