how do i convert the min_max function to the method of the IntArray class?
class IntArray
{private :
int a[];
int n;
..........
};
void min_max(int n,int a[],int&mini,int &maxi)
{
mini=a[0];
maxi=a[0];
for (int i=1; i<n; i++)
{
if (mini>a[i])
mini=a[i];
if (maxi<a[i])
maxi=a[i];
And your instructor probably intends that you remove the n and int a[] parameters of the function as well, since they are now accessible from the class scope.
int main()
{ int maxi,mini;
IntArray ia;
ia.citire();
ia.afisare();
IntArray::min_max(int&mini,int&maxi);
cout<<"media este "<<ia.media()<<endl;
cout<<"deviatia este "<<ia.devstd();
cout<<"minimul este "<<ia.a[mini] << '\n';
cout<<"maximul este "<<ia.a[maxi] << '\n';
return 0;
}
Which is very strange, because on line 4 and line 5, you correctly call a class member function. Why has it all gone wrong on line 6? How did you forget how to call a member function, even though you just did it on line 4 and line 5?
Remember, the function min_max has parameters. Have you ever called a function before that has parameters?