C++ functions
How can i translate this function to C++ code? thanks
FUNCTION minimumIndex PARAMETER 1: An integer array PARAMETER 2: An integer specifying the starting index PARAMETER 3: An integer specifying the ending index RETURNS : An integer representing the index of the minimum value in the array from the starting index to the ending index BODY of minimumIndex Set the minimumIndex to be the starting index Set the currentIndex to be one more than the starting index Loop around until currentIndex is equal to ending index If element at currentIndex is less than minimumIndex Set minimumIndex to be the currentIndex END If END Loop Return minimumIndex END BODY of minimumIndex |
In which language this "function" was wrote?
|
Quote:
Due to the level of detail, it should be easy for you to write the corresponding C++ function. This looks a lot like homework and you will learn a lot more by doing it yourself. |
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
Quote:
If you know even a little C, it should be easy to code that function in C. If you know even a little C++, you should know that function has no significant reason to be different in C++ from the same function in C. But before coding, make sure you resolve the ambiguity in the problem statement: Quote:
A good spec should make clear for any "end" pointer or index whether it means last included vs. one past the last included. Quote:
Other than the above comments, I'm not going to do your homework for you. If there is a specific detail of C++ syntax that is giving you trouble, please feel free to post what you have done so far and the specific question or problem that you have. But please do not ask for someone to do the entire assignment for you. BTW, regarding my statement that this function would the same in C vs. C++, I want to add one qualification. I don't use C enough to even try to remember which versions of C restrict the declaration of local variables to places other than where good C++ style would place them. In my opinion, good C++ style usually includes declaring most local variables at the natural point where they first receive a value. In older versions of C, you may be forced to declare local variable earlier. In C++, you can declare variables as if you were in an older version of C, but you shouldn't. |
All times are GMT -5. The time now is 12:31 AM. |