Solved

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

Posted on 2012-03-18
3
359 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

729 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