The class constructor.
General facts about constructors:
- The constructor initializes (all) the data members of the class.
- It must have the same name as the class.
- A class can have more than one constructor, but the input parameters of two different constructors must be different
- A constructor does not have a return type
- The constructor must always be a public method!
- The constructor can (and often does) call other member functions
- In an application program you create a new instance of a class by calling one of the class's constructors.
- Each separate instance of the class is called an object.
The input parameters to the Statistics class are-
Parameters:
-
arrayLengthIn:
|
The length of the array which stores the samples |
arrayIn:
|
The array in which the samples are stored
|
The constructor uses the input parameters to initialize
the private data members Statistics::arrayLength and Statistics::array
Then it calls other member functions to compute the values of the private data members
- Statistics::minimum
- Statistics::maximum
- Statistics::mean
- Statistics::variance
- Statistics::standardDeviation
- Statistics::median
Question: What is wrong with the declaration
Statistics(int arrayLength, double *array); |