LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2010, 03:39 PM   #1
gargolajr
LQ Newbie
 
Registered: Nov 2010
Posts: 1

Rep: Reputation: 0
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
 
Old 11-22-2010, 04:01 PM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
In which language this "function" was wrote?
 
Old 11-22-2010, 04:23 PM   #3
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by gargolajr View Post
How can i translate this function to C++ code?
What you have presented is actually a detailed description of the function signature of the C++ function and a detailed description of how it should work.

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.
 
Old 11-23-2010, 10:19 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 11-23-2010, 11:19 AM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by gargolajr View Post
How can i translate this function to C++ code?
I expect that means you haven't learned C yet either.

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:
PARAMETER 3: An integer specifying the ending index
In C and C++ programming it is common, but not universal, to interpret an "end" index as the index of the first item not included, meaning one beyond the last item included. But it is also possible that an "end" index represents the last item included.

A good spec should make clear for any "end" pointer or index whether it means last included vs. one past the last included.

Quote:
Loop around until currentIndex is equal to ending index
That sounds like "end" means first not included, but it still is not clearly unambiguous (English rarely is). Do you know whether "end" is the last included vs. one past the last included?

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.

Last edited by johnsfine; 11-23-2010 at 11:29 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
OSE system call functions to Linux Sytem Call functions required roshantraj30 Linux - General 0 06-08-2009 02:06 AM
LXer: OpenOffice.org Calc functions, part 1: Understanding functions LXer Syndicated Linux News 0 03-31-2007 12:01 PM
Slackpkg: missing something in /usr/libexec/slackpkg/functions.d/dialog-functions.sh michelino Slackware 4 03-20-2007 12:22 PM
Converting php5 socket functions to php3 socket functions mrobertson Programming 0 06-23-2005 09:11 AM
pointers to functions/member functions champ Programming 2 03-28-2003 06:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration