I'm working on assignment dealing with a class file. the constructor creates a dynamically allocated array of users choice of size. where i have set member functions for the different elements in the new array. I have no trouble with the storing and retrieving of element values, but when i come to my get functions to return the highest, lowest and average values it wants to display the first elements value; and "inf" for the average....some help would be greatly appreciated. Thanks!
Disch - Sorry i failed to mention that when the constructor is called that it accepts an int argument to declare the size of the array. so wouldn't 'SIZE' already be initialized if the constructor were to be used in the beginning? such as:
The 'SIZE' member declared on line 9 and the 'SIZE' parameter on line 18 are two completely different variables. Just giving the parameter the same name as your member does not make them the same (it just makes it a little confusing).
I'd give the two different names, then assign the member:
1 2 3 4 5 6 7 8 9 10 11 12
class Number
{
private:
int SIZE;
//...
public:
Number(int s) // <- change the name to 's'
{
SIZE = s; // <- now initialize your 'SIZE' member
ptr = newfloat [SIZE];
}