class cMyClass
{
public:
void MyFunction(int MyArray) {//declaration of what to do};
};
int main
{
cMyClass InstanceOfMyClass;
int MyArray[10];
InstanceOfMyClass.MyFunction(MyArray) // no rectangular brakets if you need the whole array
}
thanks for the example!
but what if i have the value of array elements from 0-9 inputed from the main function, how can i access the value or even the address of the array on each of the member function of the class..
i tried this example but i got an error of "invalid conversion from int to int" and it says initializing argument 1 of void cMyClass::MyFunction(int)..
#include <iostream>
usingnamespace std;
class cMyClass{
public:
void MyFunction(int MyArray[]) {//declaration of what to do (You need [] here)
for (int i=0; i<10; i++){
cout << MyArray[i] << endl;
}
}
};
int main(){
cMyClass InstanceOfMyClass;
int MyArray[10];
for (int i=0; i<10; i++){
MyArray[i] = i;
}
InstanceOfMyClass.MyFunction(MyArray); // no rectangular brakets if you need the whole array
}
You need the brackets in the function so it will know that it is gonna recieve an array...
Can you tell me what's wrong with this program?? it doesn't work the way it should be
#include<iostream>
using namespace std;
class Computation
{
public:
int getSum(int MyArray[])
{
int sum;
for(int n=0;n<10;n++)
{
sum+=MyArray[n];
}
return sum;
}
int getProduct(int MyArray[],int z)
{
int prod=1;
for(int z=0;z<10;z++)
{
prod=prod*MyArray[z];
}
return prod;
}
int getFactorial(int s[0], int d[9])
{
int a=1;
for(int y=1;y<=s[0];y++)
{
a=(a) *(s[0]);
s[0]--;
}
cout<<"The factorial of the first array is:"<<a<<endl;
int x=1;
for(int y=1;y<=d[0];y++)
{
x=x*d[9];
d[9]--;
}
cout<<"The factorial of the last array is:"<<x<<endl;
}
};
int main()
{
Computation math;
int MyArray[10];
int y, a;
for(y=0;y<10;y++)
{
a =MyArray[y];
cout<<"Enter a number:";
cin>>a;