Link to home
Start Free TrialLog in
Avatar of lillie62
lillie62Flag for United States of America

asked on

write the heading function that take two arrays, and return a bool result in C++ program

I had write the three arrays type called DataSet with three arrays: input, output, and working. Each array hole 5  float values.

                 const MY_INPUT =4;
                const MY_OUTPUT = 4;
                const MY_WORKING = 4;
                 float DataSet[MY_INPUT][MY_OUTPUT][MY_WORKING];
                 float input;
                 float output;
                 float working;
And now I need to write a heading function called Equals that take two arrays for the DataSet type and returns a bool result. The array parameters should be const, as they are input-only parameters to the function , but I got stuck on it, could you help me for the solution to complete this part. Thank you very much for your help.
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you want a type holding three arrays then do.

const int MY_INPUT = 5;
const int MY_OUTPUT = 5;
const int MY_WORKING = 5;
typedef struct THREE_ARRAYS_TAG
{
     float input[MY_INPUT];
     float output [MY_OUTPUT];
     float working[MY_WORKING];
}  THREE_ARRAYS;

Open in new window


you could pass any of those arrays by defining a variable of type  THREE_ARRAYS
and then use the member variable like

THREE_ARRAYS ta;
/* fill the arrays */
 ...
if (func(ta.input,  MY_INPUT ))
     ...

Open in new window


the function could be defined as 'bool func(const float* input , int elements)';

Sara
You can use typdef to define the 3d type.
Example:
const int MY_INPUT =4;
const int MY_OUTPUT = 4;
const int MY_WORKING = 4;

typedef float MY_3D_DATASETTYPE[MY_INPUT][MY_OUTPUT][MY_WORKING];

bool MyFunction(MY_3D_DATASETTYPE &DataSet)
{
	return false;
}

// ... Some code usage:
	float DataSet[MY_INPUT][MY_OUTPUT][MY_WORKING] = {0};
	MyFunction(DataSet);

Open in new window


I would recommend using vector< vector< vector<float> > > type over C style 3D array type.