[Solved] COSC450/550 HW 4

30 $

File Name: COSC450/550_HW_4.zip
File Size: 150.72 KB

SKU: [Solved] COSC450/550 HW 4 Category: Tag:

Or Upload Your Assignment Here:


1. Consider the following JavaScript skeletal program:// The main programvar x;function sub1() {var x;function sub2() {…}}function sub3() {…}Assume that the execution of this program is in the following unit order:main calls sub1sub1 calls sub2sub2 calls sub3a. Assuming static scoping, in the following, which declaration of x is the correct onefor a reference to x?i. sub1ii. sub2iii. sub3b. Repeat part a, but assume dynamic scoping.2. Assume the following JavaScript program was interpreted using static-scoping rules.What value of x is displayed in function sub1? Under dynamic-scoping rules, what valueof x is displayed in function sub1?var x;function sub1() {document.write (“x = “ + x + “”);}function sub2() {var x;x = 10;sub1();}x = 5;sub2();COSC450/550 HW 43. Consider the following JavaScript program:var x, y, z;function sub1() {var a, y, z;function sub2() {var a, b, z;…}…}function sub3() {var a, x, w;…}List all the variables, along with the program units where they are declared, that arevisible in the bodies of sub1, sub2, and sub3, assuming static scoping is used.4. Consider the following program, written in JavaScript-like syntax:// main programvar x, y, z;function sub1() {var a, y, z;…}function sub2() {var a, b, z;…}function sub3() {var a, x, w;…}Given the following calling sequences and assuming that dynamic scoping is used, whatvariables are visible during execution of the last subprogram activated? Include withvisible variable the name of the unit where it is declared.a. main calls sub1; sub1 calls sub2; sub2 calls sub3.b. main calls sub1; sub1 calls sub3.c. main calls sub2; sub2 calls sub3; sub3 calls sub1.d. main calls sub3; sub3 calls sub1.e. main calls sub1; sub1 calls sub3; sub3 calls sub2.f. main calls sub3; sub3 calls sub2; sub2 calls sub1.COSC450/550 HW 45. Consider the following skeletal C program:void fun1(void); /* prototype */void fun2(void); /* prototype */void fun3(void); /* prototype */void main() {int a, b, c;…}void fun1(void) {int b, c, d;…}void fun2(void) {int c, d, e;}void fun3(void) {int d, e, f;…}Given the following calling sequences and assuming that dynamic scoping is used, whatVariables are visible during execution of the last function called? Include with eachvisible variable the name of the function in which it was defined.a. main calls fun1; fun1 calls fun2; fun2 calls fun3.b. main calls fun1; fun1 calls fun3.c. main calls fun2; fun2 calls fun3; fun3 calls fun1.d. main calls fun3; fun3 calls fun1.e. main calls fun1; fun1 calls fun3; fun3 calls fun2.f. main calls fun3; fun3 calls fun2; fun2 calls fun1.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COSC450/550 HW 4
30 $