# include & ltiostream & gt
Use the header file in the namespace std//. If you are using VC6.0, just write # include.
//Don't write using the namespace std; ;
Class array {
Private:
Int array [10];
Public:
int GetData(int i)
{
int j;
for(j = 0; j & lt 10; j++)
{
if(i==array[j])
Return (1);
}
}
The Array(int *a)// constructor is used to initialize data members. For example, if you don't write, the system defaults to 0;
{
int I;
for(I = 0; I< 10; i++)
{
array[I]= a[I];
}
Cout & lt& lt "Data member initialization completed!" & lt& ltendl
}
};
//The following is the main () function to test the Array class:
void main()
{
Cout & lt& lt "Please enter the 10 value of the data member:"; //Create an array to initialize the data members of the array;
int i,a[ 10];
for(I = 0; I< 10; i++)
{
CIN & gt; & gta[I];
}//Input completed;
Array b (a); //Define an object. The parameter is the array just entered, which is used to assign values to the data one by one.
//Each element of the member array;
Cout & lt& lt "Please enter the value of the element whose subscript you want to know:"; //Let the user input the value of the element he wants to know;
int j;
CIN & gt; & gtj;
for(I = 0; I< 10; I++) // Compare the input value with the array one by one.
{
If(j==a[i]) // If an equivalent element is found, send it to the GetData function.
Cout & lt& lt "element"
Else if(j==9) // If the last one has been found, it still hasn't been found, which means there is no such element, and it's over;
Cout & lt& lt "element"
}
}