For this question, select and name a high-level language you will be discussing. Diagrams might help in your
a) Explain how the computer passes control to a subroutine (or procedure) and returns it to the main
routine once the task has been completed.
b) Explain, giving a relevant example, how a subroutine (or procedure) can be used several times in the
same program, each time accepting different data values and passing back different results.
c) ABS and INT are two numeric data handling functions found in many languages. Explain what EACH of
the following achieves:
i Z = ABS (X – Y)
ii IF 5 * INT(A / 5) – A = 0 THEN …….

7
Contributors
7
Replies
69
Views
3 Years
Discussion Span
Last Post by Taywin

Don't expect to get the answer while you haven't tried to solve it by yourself.
Show what you have done so far...

i understand and sory

Excerpt from the rules :

Do provide evidence of having done some work yourself if posting questions from school or work assignments

i understand and sory

Ivzirnalsradeys, you keep asking us to do your homework for you. If we do that, then what do you learn? Make a proper effort to solve the problems, show what you have done, describe the errors you are getting, and THEN we may decide to help you sort this stuff out. Until then, you are on your own!

i understand and sory

PLease provide evidence that you have worked on this.

My optimism in others' good intentions is battling with my pessimism about help vampires (which the OP is quickly proving herself to be). Still, in the hope of giving her at least a leg up, I'll try to give what advice I may.

a) Explain how the computer passes control to a subroutine (or procedure) and returns it to the main routine once the task has been completed.

The basic mechanism, inside the compiled code, consists of saving the address of the location in memory just past where the function call is made, and jumping to the function. When the function ends, it retrieves the address and jumps back to the location it was called from. There are a few different ways this can be done, such as linkage registers and function windows, but the usual method is to save the return address on the hardware stack. There! That's enough information to get you started, but not by any means a full explanation.

b) Explain, giving a relevant example, how a subroutine (or procedure) can be used several times in the same program, each time accepting different data values and passing back different results.

Hint: All of the standard C and C++ I/O stream operations are actually library functions. Have you ever used `printf()` or `cout <<` more than once in a program?

c) ABS and INT are two numeric data handling functions found in many languages. Explain what EACH of the following achieves:

``````i Z = ABS (X – Y)
``````

OK, here you aren't really given enough information to actually compute the result, so the professor must be looking for an explanation of passing arguments to a function and returning values from one. You don't even need to know what `abs()` does, in fact (though that's easy enough to look up). They probably aren't looking for the exact mechanism (that would depend on the computer's specific instruction set architecture), just a general 'what happens at point so-and-so' type of answer.

``````ii IF 5 * INT(A / 5) – A = 0 THEN …….
``````

Similarly, the instructor seems to want you to explain how the boolean expression is evaluated and used in the conditional statement. In other words, they want you to explain (in general terms) how `if` works.

I might finally add that this probably should have been posted to the 'Software Development' or 'Computer Science' fora rather than 'C++', since it really isn't anything specific (or even related) to C++.

Edited by Schol-R-LEA

Hmmn, I gather from the downvote that I went a bit too far in helping this particular person. Either that, or the fact that I did a favor for a help vampire like the OP offended someone. In either case, I do apologize, and will be more circumspect in the future.

@Schol-R-LEA, just to let you know one thing when I see a girl pic/avatar (especially the one with OK to good looking) in newbie profile, it means that the person intends to put it there in order to get sympathy from others. This is, to me, a red flag for any type of forum... In other words, the person is very likely to expects someone (or people) to fall for the trick... I usually do not give even a hint to the answer to this type of profile.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.