Solved

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

Posted on 2012-03-18
3
345 Views
Last Modified: 2012-03-20
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.
0
Comment
Question by:lillie62
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 37736641
A few notes :

(a) DataSet is NOT a type. It is an instance/variable.

(b) DataSet is just ONE three-dimensional array, NOT three arrays.

(c) When specifying the size of an array as 4, the array can hold only 4 items, not 5.

Other than that, what is your question ? What did you try ? Where did you get stuck ?
0
 
LVL 33

Expert Comment

by:sarabande
ID: 37737194
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
0
 
LVL 30

Expert Comment

by:Axter
ID: 37743845
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.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question