As
seeplus points out, a lot of what you're trying to do is available in the standard library. If you can't do that, then here are some comments on your latest version of the code.
Line 29. Why the
else
? You always want to allocate p_arr, so delete lines 29 and 32. This means you can also delete line 24.
Line 39: I'd always delete p_arr. It's legal to delete a null pointer.
Why does the default constructor create an array with no elements, but Array(0) creates an array with 5? That's inconsistent. It seems to me that the default constructor should also make an array with 5 elements. Read the assignment carefully on this point.
Speaking of the assignment, you should post the whole thing here. It's very VERY common for students to miss critical aspects of an assignment. Usually every single word of the text means something to the code.
create_array() sure looks lonely. If you don't call it then why do you need it? If you need it then where should you call it? I suspect that what you really need is something that will resize the array, not simply create it.
I don't think maximum() or find_avrg() should print their results. Whatever calls them should print it.
Speaking of maximum, just change max_pos to the index of the max item:
1 2 3 4 5 6 7 8 9 10 11 12
|
int Array::maximum()
{
if (size == 0)
return -1;
int max_pos = 0
for (int i = 1; i < size; ++i) {
if (p_arr[i] > p_arr[max_pos]) {
max_pos = i;
}
}
return max_pos;
}
|
You don't have any code to access items in the array. Does the assignment require them?