Code:
#include <iostream>
using namespace std;
class numericArray
{
private:
double *array;
double average;
int pick, high, low;
public:
numericArray(int, int );
~numericArray()
{delete [] array;
cout << "bye";}
void setValue(double [], int);
void setAverage(double [], int);
void setHiLow(double [], int);
double getValue()
{cout << "hi\n";
return array[pick];}
double getHigh()
{ cout << "high index = " << high << endl;
return array[1];}
double getLow()
{cout << "\n\nlow blow\n";
return array[low];}
double getAverage()
{cout << "This is the average " << average << endl;
return average;}
};
numericArray::numericArray(int ray, int v)
{
array = new double[ray];
pick = v;
for(int v = 0; v < ray; v++)
array[v] = 0;
}
void numericArray::setValue(double array[], int u)
{
double p;
cout << "Please enter the value you wish to store in this subscript: ";
cin >> p;
array[u] = p;
}
void numericArray::setAverage(double array[], int u)
{
int _Average = 0;
for(int c = 0; c < u; c++)
{
_Average += array[c];
}
average = _Average;
}
void numericArray::setHiLow(double array[], int u)
{
int greatest = 0, lowest = 0;
for(int x = 0; x < (u - 1); x++)
{
if(array[x + 1] > array[x])
greatest = x + 1;
else greatest = x;
if(array[x+1] < array[x])
lowest = x + 1;
else lowest = x;
}
cout << array[u];
high = greatest;
low = lowest;
}
int main()
{
int amount,num;
cout << "You are going to need to enter the amount of numbers\n\n"
"you'd like to enter. Then I'll show you the highest,\n\n"
"lowest, and the average of the numbers you entered. \n\n"
"Also you can pick which subscript(which place its held at\n\n"
"in memory)\n";
system("pause");
system("cls");
cout << "Please enter the amount of numbers you'd like to store: ";
cin >> amount;
while(amount < 0)
{
cout << "You cannot enter a negative value.\n"
<< "Enter a positive number: ";
cin >> amount;
cout << "\n";
}
system("pause");
system("cls");
cout << "Ok, now enter which subscript(what number inbetween \n\n"
<< amount - 1 << " and 0 : ";
cin >> num;
while (num < 0 || num > amount)
{
cout << "Invalid input!\a\a" << "Enter number between 0 and "
<< amount - 1 << ": \n";
cin >> num;
cout << "\n";
}
numericArray crap(amount, num);
cout << "The object was created..." << endl;
cout << crap.getHigh();
return 0;
}
The trouble im having is void getHiLow() function is the only one executing, but setValue(), and setAverage() aren't executing, and I need them to before getHiLow(). How does the class start running after the constructor is finished doing its job? Can anybody please explain to me why the heck the other ones are doing their jobs?
p.s incase your wondering, i put the cout statements in some of the functions to see if they ran or not.