Solved

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

Posted on 2012-03-18
3
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

623 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