Question

In: Computer Science

procedure Example is X: Integer; procedure First is begin Put(X); -- Print X New_Line; -- Print...

procedure Example is
                X: Integer;

        procedure First is
        begin
                Put(X);                 -- Print X
                New_Line;               -- Print a newline character
        end First;

        procedure Second is
                X: integer;

                procedure Third is
                        X: Integer;
                begin -- Third
                        x := 99;
                        First;
                end Third;

        begin -- Second
                x := 88;
                Third;
        end Second;

begin -- Example 
        x := 77;
        First;
        Second;
end Example;

a) What will be printed by this program if we assume static scope?
b) What will be printed by this program if we assume dynamic scope?

Solutions

Expert Solution

static scope:

In this approach the value assigned at program begin and the value remains same in entire program:

begin -- Example 
        x := 77;  // The value of x is 77 and it remains same through out the program
        First;
   procedure First is
        begin
                Put(X);                 -- Print 77
                New_Line;               -- Print a newline character
        end First;


        Second;
 procedure Second is
 begin -- Second
                x := 88; -- The value remains same 77
                Third;

                procedure Third is
                        X: Integer;
                begin -- Third
                        x := 99;  -- The value remains same 77
 First;
   procedure First is
        begin
                Put(X);                 -- Print 77
                New_Line;               -- Print a newline character
        end First;
                end Third;
        end Second;
end Example;

Output:

77

77

Dynamic scope:

In this approach the value changed with respect to called functions.

begin -- Example 
        x := 77;  // The value of x is 77 
        First;
   procedure First is
        begin
                Put(X);                 -- Print 77
                New_Line;               -- Print a newline character
        end First;


        Second;
 procedure Second is
 begin -- Second
                x := 88; -- The value of x is 88
                Third;

                procedure Third is
                        X: Integer;
                begin -- Third
                        x := 99;  -- The value of x is 99
 First;
   procedure First is
        begin
                Put(X);                 -- Print 99
                New_Line;               -- Print a newline character
        end First;
                end Third;
        end Second;
end Example;

Output:

77

99


Related Solutions

Begin this discussion by first stating your intended future career. Then give an example of a...
Begin this discussion by first stating your intended future career. Then give an example of a proportion that applies to two Populations for which you would like to do a Hypothesis Test in your future career. In your Hypothesis Test you will be testing the difference between these two Population proportions. Your discussion MUST include for the two target Populations along with the Population characteristic that your proportion is measuring. As shown in the text your Null and Alternative Hypotheses...
Begin this discussion by first stating your intended future career. Then give an example of a...
Begin this discussion by first stating your intended future career. Then give an example of a mean that applies to two Populations for which you would like to do a Hypothesis Test in your future career. In your Hypothesis Test you will be testing the difference between these two Population means when the two samples are independent. Your discussion MUST include the two target Populations along with the Population characteristic that your mean is computed for, and the unit that...
Let M be the integer corresponding to the first letter of your last name. For example,...
Let M be the integer corresponding to the first letter of your last name. For example, if your last name begins with "A", M=1 and if your last name begins with "Z", M=26. Let k=1/M and consider the logistic equation dy/dt = k y (M - y). Construct a single figure including Title "Logistic Equation Slope Field and Euler's Method solutions by FirstName LastName" with your actual first and last names, along the top Labels for the axes a slope...
Let M be the integer corresponding to the first letter of your last name. For example,...
Let M be the integer corresponding to the first letter of your last name. For example, if your last name begins with "A", M=1 and if your last name begins with "Z", M=26. Let k=1/M and consider the logistic equation dy/dt = k y (M - y). Construct a single figure including Title "Logistic Equation Slope Field and Euler's Method solutions by FirstName LastName" with your actual first and last names, along the top Labels for the axes a slope...
in java please: Given any integer, print an English phrase that describes the integer (e.g. “One...
in java please: Given any integer, print an English phrase that describes the integer (e.g. “One Thousand, Two Hundred Thirty Four”). An ArrayList must be used in your program.
Begin this discussion by first stating your intended future career. Then give an example from your...
Begin this discussion by first stating your intended future career. Then give an example from your intended future career of a Population Mean that you would like to do a Hypothesis Test for. The target Population of your Hypothesis Test activities must be included in your discussion along with the unit of measurement that you are using. As shown in the text your Null and Alternative hypothesis MUST include the symbol for a Population Mean along with your hypothesized claimed...
Give the value of x (x is an integer and assume integer arithmetic for all operations)....
Give the value of x (x is an integer and assume integer arithmetic for all operations). ________ 1.             x = 12 - 4 * 2 - 8; ________ 2.             x = 24 / 2 + 1 * 4; ________ 3.             x = 12 - 9 + 4 * 2 + 3 ^ 4; ________ 4.             x = 24/(3 + 2) * 4; ________ 5.             x = 2 * (5 - 3) + 7; ________ 6.             x = 12 - (15/5...
X=5,Y=7,Z=10 A. if(X<Y): print "LESS" else: print "OTHER" B. if (x == 1): print "ONE" elif...
X=5,Y=7,Z=10 A. if(X<Y): print "LESS" else: print "OTHER" B. if (x == 1): print "ONE" elif (x == 2): print "TWO" elif (x == 3): print "THREE" elif (x == 4): print "FOUR" elif (x == 5): print "FIVE" elif (x == 6): print "SIX" else: print "OTHER" C. if (X<Z): print X X = X + 1 D. while (X<Z): print X X = X + 1 Q11. What is the final value of X in D Q12. Is...
On Python a) Use format() method to print an integer value entered by the user and...
On Python a) Use format() method to print an integer value entered by the user and its cube root with two decimal places. b) Print the same values as part (a) using format() function with keyword arguments and labels number and cubeRoot as in: format(number=n,cubeRoot=cr) c) Switch the order of keyword arguments and show that this has no effect on the output.
Begin this discussion by first stating your intended future career.(Network Administrator) Then give an example from...
Begin this discussion by first stating your intended future career.(Network Administrator) Then give an example from your intended future career of a proportion that applies two Populations for which you would like to do a Hypothesis Test. In your Hypothesis Test you will be testing the difference between these two Population proportions. Your discussion MUST include the two target Populations along with the Population characteristic that your proportion is measuring.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT