C++ Function Prototype? [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I had this on a test this week and got it wrong. I asked the professor for help and he said we'd go over it next Thursday. I really don't want to wait that long. Can any one on here walk me through it?
Perform the task specified by the following statements:
Write the function prototype for function "doit" that takes an integer array parameter "list" and an integer "size" parameter and returns a boolean value.
Thanks in advance for any help

bool doit(int list[], int size);
The function doit takes an array of integers as first parameter, and the size of the array (which is an integer) as second parameter. It returns a boolean (true or false).
This sort of function prototype is typically used to access each element of the array within a for loop (with size as terminating condition). The boolean return value could inform of the presence or absence of some value in the array for example, or if some work could or could not be performed.

A little bit of help is there :
RETURN_TYPE FUNCTION_NAME (ARGUMENT1_TYPE ARGUMENT1,ARGUMENT2_TYPE ARGUMENT2);
It's not a big deal , it's just a prototype :)
I wrote the answer and removed it, u should try looking for the answer in the internet :)

Here you go:
+ doit(list : int[], size : int) : boolean

Related

Reading automatically generated documentation for DOLFIN c++ library [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to read the documentation of the DOLFIN c++ library for finite element modelling located on this link:
https://fenicsproject.org/olddocs/dolfin/1.3.0/python/programmers-reference/index.html
but the documentation is hard to read, so for someone without c++ knowledge how you will read the following specification of parameters for the c++ method eval_cell() of the Expression class (https://fenicsproject.org/docs/dolfin/2017.2.0/python/programmers-reference/cpp/function/Expression.html):
Parameters:
double > & values (Array<) – (Array<double>) The values at the point.
Array< double > & x (const) – (Array<double>) The coordinates of the point.
ufc::cell & cell (const) – (ufc::cell) The cell which contains the given point.
After taking a look at the page t.niese linked in the comments I think this is a automatically generated documentation, with a really bad generator (like really really bad).
So, if we fix the butchered first line, realign some braces here and there and fix the position of const it might become clearer:
Parameters
const Array<double>& values1 – The values at the point.
const Array<double> &x – The coordinates of the point.
const ufc::cell &cell – The cell which contains the given point.
Meaning
You are dealing with a function that takes three parameters, the first and second are of type Array<double>, which seems to be generic container. The third parameter is of type ufc::cell, whatever this is. All three parameters are passed by reference (see the & before each variable name) and not by value. But they are not just passed as reference but actually as const reference (see the const), meaning that the function can't modify the objects you give to it.
I can't however say much about the comments for each parameter.
1 I assume the first parameter is also const, because it got the brackets, where the const is noted in the other two parameters, but this is just guessing.

How to test the end of an array of unsigned char? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How can we test the end of an array of unsigned char ? With a string char it's easy, I can just make a test like
while (str[i] != '\0')
or just
while (str[i])
But with an array of unsigned char that doesn't work and I don't really understand why. That's an example where I need help
BYTE* a = getB();
int i=0;
while(a[i]!=0)
{
printf("%C", a[i]);
i++;
}
Thanks
It is completely up to you.
That is, you define what the end of an array means.
Conventionally, sure, the end of a character array is a "null byte", signifiying the terminating position. There's no reason you can't do that with an array of unsigned char.
But, just like with char, this need not necessarily be the case. Maybe you signify the end of the array by counting its elements (specifying a size), or by declaring that some other character is the final one.
We cannot tell you what that is. Only the person who creates the data (as far as we're concerned here, that's you) can do so.
So, either consult the documentation for the library that gave you the array, or reach into your memory. :)
#eugenesh is right. You can't do do it. Either you need to have extra space at the end and add some kind of delimiter or keep a count of charactera

C++ : How to arrange 4 values in an ascending order? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Hello I know it may be a beginners question but I need help.
I need to compare between 4 values added by the user and arrange them in am ascending order by using a function that takes 2 inputs and return the smaller one. I know it can be done by arrays but I must not do it. I already have the function but I don't know how to use to do the trick without having a very long code. Thanks
This seems to me to be an obvious "homework question," so let me answer it cryptically in order to maybe push you in the right direction.
First, the hint: divide and conquer.
Second hint: the "Towers of Hanoi" problem.
You have a function that can compare two values. Okay, then: "four elements" can be viewed as "two groups of two values each." Given that either of the two input to your comparison-function can be the result obtained by a nested call to the same function . . . you can, indeed, solve this problem, in one line of code, without using arrays.
I'm trying here to "teach you to fish," so I'm not handing you the fish on a platter.
If you know c++ then you can use sort function. But for this you have to include algorithm as:
#include <algorithm>
and sort function will be used as:
sort(array, array+N);
where array is the array name and N is the size of array.After this operation you will get a sorted array in ascending order and return first element.Now the function will look like as:
int smallest(int *array) {
int size = sizeof(array) / sizeof(array[0]);
sort(array, array+size);
return (array[0]);
}
And now call this function from main()

How to write a function prototype? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
my question is write function prototypes for
A function, isAbleToVote, which accepts the age of a potential voter (as a double). The
function should return true if the value of the double is greater than 18 and return false
otherwise.
I wrote bool isAbleToVote(double)
A function, named printPrice, to print a product name and its price to the screen. Both
outputs (i.e., the product name and its price) are passed in as arguments.
I wrote Void printPrice(string product_name, double price)
A function, sizeOf, which accepts a string as its argument. The function should return the length of the string.
I wrote string.length sizeOf(string)
4.A function, named getInt, to print the following message to the screen “Please enter an integer”, and to return the value of the user input.
I wrote cout getInt("please enter an integer")
Am I write? if not what am i doing wrong?
You did well on 1 and 2, those are function prototypes. Though remember, C and C++ function prototypes are followed by a semicolon (to be pedantic)
3 is close, but string.length isn't a return type. Find the return type that best represents the length of a string (hint check the std::string::length() function or strlen() function).
4 is not a prototype. It is a statement. prototypes are simple the signature, without any code body. Read the requirement again and think of the minimal input and output data for the function. Hint there is nothing wrong with a void function that takes no arguments, if you don't need any input or output values.

c++ error: term does not evaluate to a function taking 1 arguments [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm getting the error 'term does not evaluate to a function taking 1 arguments' on the following line in my code:
steerToSpiralRefPoint(m_CentrePos);
But I'm not sure why this is... Is it that the function will only take 1 argument as a parameter, but since the 'm_centrePos' variable holds more than 1 attribute, the function is effectively receiving several parameters?
I have defined 'steerToSpiralRefPoint' with the line:
CDirectOverflyItem steerToSpiralRefPoint = new CDirectOverflyItem::SteerStep(const CHeloData aHeloData);
'm_CentrePos' has been assigned the value 'cCentrePos' at the start of this file ('cCentrePos' is a variable of type 'CCoordinate', which has a number of attributes- latitude, longitude, altitude, etc).
'CDirectOverflyItem's also has a number of attributes- ground speed, wind speed, wind angle, etc.
Can anyone point out to me why I'm getting this error, and how I should correct it?
This expression
steerToSpiralRefPoint(m_CentrePos);
is a postfix expression of a function call. However as it follows from your post steerToSpiralRefPoint is not a function (or function pointer) but a pointer to an object. If you want to assign a value to the pointer then you have to write
steerToSpiralRefPoint = m_CentrePos;
Or if there is an operator function for this type then the code should look as
( *steerToSpiralRefPoint )( m_CentrePos );
And this construction
CDirectOverflyItem steerToSpiralRefPoint = new CDirectOverflyItem::SteerStep(const CHeloData );
is also invalid. You may not use qualifiers before variables in expressions. They may be used only in declarations.
It seems that the issue was that I was trying to pass the wrong data type into the parameter- it was expecting a 'CHeloData', but I was trying to give it a 'CCoordinate'.