Solved

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

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now