Question

In: Computer Science

QUESTION 1 Consider the following program: var x = 0; function sub1() {    var x =...

QUESTION 1

Consider the following program:

var x = 0;
function sub1() {
   var x = 1;
   function sub2() {
      function sub3() {
         print x;
      }
      sub3();
   }
   function sub4() {
      var x = 2;
      sub2();  
   }
   sub4();
}
sub1();
If this code uses static scoping, when it is executed what is printed?

0

1

2

QUESTION 2

Consider the following program:

var x = 0;
function sub1() {
   var x = 1;
   function sub2() {
      function sub3() {
         print x;
      }
      sub3();
   }
   function sub4() {
      var x = 2;
      sub2();  
   }
   sub4();
}
sub1();
If this code uses dynamic scoping, when it is executed what is printed?

0

1

2

QUESTION 3

Consider the following program:

void fun1 (void);
void fun2 (void);
void fun2 (void);

void main() {
   int a, b, c;
}

void fun1() {
   int b, c, d;
}

void fun2() {
   int c, d, e;
}

void fun3() {
   int d, e, f;
}
and the following call sequence: main calls fun2; fun2 calls fun1; fun1 calls fun3.

Assuming dynamic scoping, what are the variables visible within fun3?

d, e, and f from fun3

d, e, and f from fun3; a, b, anc c from main

d, e, and f from fun3; b and c from fun 1; a from main

QUESTION 4

Consider the following program:

void fun1 (void);
void fun2 (void);
void fun2 (void);

void main() {
   int a, b, c;
}

void fun1() {
   int b, c, d;
}

void fun2() {
   int c, d, e;
}

void fun3() {
   int d, e, f;
}
and the following call sequence: main calls fun1; fun1 calls fun3; fun3 calls fun2.

Assuming dynamic scoping, what are the variables visible within fun2?

a, b , and c from main; d from fun 1; e and f from fun3

a from main; b from fun1; f from fun 3; c, d, and e from fun2

c, d, and e from fun2

Solutions

Expert Solution


Related Solutions

Determine the output of the following program: var x; function bar() { writeln(x); } function foo()...
Determine the output of the following program: var x; function bar() { writeln(x); } function foo() { var x; x = 3; bar(); } function oof() { var x; x = 7; foo(); } x = 5; oof(); (a) if the static scoping rule is used? What is the reason?. (b) if the dynamic scoping rule is used? What is the reason?.
Question Consider the function ?(?) = ??2 and x = 0, 0.25, 0.5, 1. Then use...
Question Consider the function ?(?) = ??2 and x = 0, 0.25, 0.5, 1. Then use the suitable Newton interpolating polynomial to approximate f(0.75). Also, compute an error bound for your approximation Dont use a sheet to solve thanks numerical methods
1. Consider the following function F(x) = {2x / 25 0<x<5            {0 otherwise a) Prove...
1. Consider the following function F(x) = {2x / 25 0<x<5            {0 otherwise a) Prove that f(x) is a valid probability function. b) Develop an inverse-transformation for this function. c) Assume a multiplicative congruential random number generator with parameters: a: 23, m: 100, and xo: 17. Generate two random variates from the function for (x).
If Var(X) = 1, Var(Y) = 2 and Cov(X,Y) = 0, what is Cov(X-2Y, Y-X2)?
If Var(X) = 1, Var(Y) = 2 and Cov(X,Y) = 0, what is Cov(X-2Y, Y-X2)?
      Show that     Var(x-a/)=1/h^2 Var(x)
      Show that     Var(x-a/)=1/h^2 Var(x)
Prove Var(|X|) <= Var(X)
Prove Var(|X|) <= Var(X)
  Consider a discrete random variable with the following probability mass function x 0 1 2 3...
  Consider a discrete random variable with the following probability mass function x 0 1 2 3 4 5 p(x) 0.1 0.1 0.2 0.3 0.2 0.1 Generate a random sample of size n =10000 from this distribution. Construct a bar diagram of the observed frequencies versus the expected frequencies.(using R)
Consider the function ?(?) = ??2and x = 0, 0.25, 0.5, 1. Then use the suitable...
Consider the function ?(?) = ??2and x = 0, 0.25, 0.5, 1. Then use the suitable Newton interpolating polynomial to approximate f(0.75). Also, compute an error bound for your approximation.
Consider the function f(x) = x - xcosx, which has a root at x = 0....
Consider the function f(x) = x - xcosx, which has a root at x = 0. Write a program to compare the rates of convergence of the bisection method (starting with a = -1, b = 1) and Newton’s method (starting with x = 1). Which method converges faster? Why?
a. Consider the following distribution of a random variable X X – 1 0 1 2...
a. Consider the following distribution of a random variable X X – 1 0 1 2 P(X) 1/8 2/8 3/8 2/8                 Find the mean, variance and standard deviation b. There are 6 Republican, 5 Democrat, and 4 Independent candidates. Find the probability the committee will be made of 3 Republicans, 2 Democrats, and 2 Independent be selected? c. At a large university, the probability that a student takes calculus and is on the dean’s list is 0.042. The probability...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT