The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

ada question

Raziel078Raziel078 Registered User regular
edited May 2009 in Help / Advice Forum
So I've got this hw question and I'm pretty sure I'm missing it. I've got the notes I've read the relevant section in the book. But its still escaping me. So I'm going to post the question and my answer.

Let p be the following procedure, written using Ada syntax:

procedure P(X: in out Integer; Y: out Integer) is
begin
I := I + 1;
X := X + 1;
Y := I + 1;
end P;

I is global to this procedure. Now, suppose that the following statements are executed:
I := 1;
A(1) := 10;
A(2) := 20;
A(3) := 30;
P(I, A(I));

For each of the following sets of assumptions, show the values of I, A(1), A(2), and A(3) after the call of P.

(a) X is passed by reference and Y is passed by reference
(b) X is passed by reference and Y is passed by result
(c) X is passed by value-result and Y is passed by reference
(d) X is passed by value-result and Y is passed by result

my answer:

1. I A(1) A(2) A(3)
a 3 11 20 30
b 3 10 20 31
c 2 11 20 30
d 2 10 21 30

again I'm pretty sure this is wrong but I wasn't in class the day we went over this stuff. (took papa to the ER, so it wasn't me just being lazy). And this teacher has a really bad habit of teaching in class and not mentioning it in the notes. Thanks if you can help. Or at least explain what I did wrong.

I would like to put something clever and about me but I fear my company will find it
Raziel078 on

Posts

  • jclastjclast Registered User regular
    edited May 2009
    We won't do your homework for you. You should go to office hours, explain why you weren't in class, and say something like "I tried to do the homework, and I think I'm not sure I understand. Here's what I've got. If I'm wrong could you point me in the right direction? Or maybe lead me through a similar example problem?"

    jclast on
    camo_sig2.png
  • Raziel078Raziel078 Registered User regular
    edited May 2009
    are you kidding me? I've got my damned answer posted below it. If someone knows more about passing values I'd appreciate it. If on the other hand you just feel like sounding like a smug dick I"m uninterested in your dickery.

    Raziel078 on
    I would like to put something clever and about me but I fear my company will find it
  • wasted pixelswasted pixels Registered User regular
    edited May 2009
    jclast wrote: »
    We won't do your homework for you. You should go to office hours, explain why you weren't in class, and say something like "I tried to do the homework, and I think I'm not sure I understand. Here's what I've got. If I'm wrong could you point me in the right direction? Or maybe lead me through a similar example problem?"

    The OP is absolutely fine and kosher under the H/A rules. He's asking for someone to help him with syntax, not to give him answers.

    wasted pixels on
  • Raziel078Raziel078 Registered User regular
    edited May 2009
    I appreciate the backup wasted pixels

    Raziel078 on
    I would like to put something clever and about me but I fear my company will find it
  • jclastjclast Registered User regular
    edited May 2009
    This is a better explanation than I could think of for the different types of passing and how they affect what variables are assigned when.

    Sorry. Didn't mean to sound like a dick earlier. I just figured that the professor would be more help than random folks on the Internet.

    jclast on
    camo_sig2.png
Sign In or Register to comment.