Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming language concept - H Please let me know if you need more time. The f

ID: 648231 • Letter: P

Question

Programming language concept - H

Please let me know if you need more time.

The following questions refer to the skeletal C++ program shown below. (a) Assume that static scoping is used. List all variables, along with the functions in which they are declared, that are visible at Line 1 in the program. (b) Repeat part (a), but list the variables that are visible at Line 2. (c) Repeat part (a), but list the variables that are visible at Line 3. (d) Repeat part (a), but list the variables that are visible at Line 4. (e) Repeat part (a), but list the variables that are visible at Line 5. (f) Assume that dynamic scoping is used, and that main calls fi, which calls f2, which calls f 3. (Assume that f 2 calls f 3 on Line 4.) List all variables, along with the functions in which they are declared, that are visible at Line 5 in the program. A sample answer to one part of the problem might look like this: A (global), b (declared in f2), e (declared in if block in f2)

Explanation / Answer

(a)
Line 1:
"a" (declared globally)
"b" (declared in main())
"c" (declared in main())
"d" (declared in main())

(b)
Line 2:
"a" (declared in f1())
"b" (declared globally)
"c" (declared in f1())

(c)
Line 3:
"a" (declared in the if block in f2())
"b" (declared in f2())
"d" (declared in f2())
"e" (declared in the if block in f2())

(d)
Line 4:
"a" (declared globally)
"b" (declared in f2())
"d" (declared in f2())

(e)
Line 5:
"a" (declared in f3())
"b" (declared globally)
"e" (declared in f3())

(f)
Line 5:
"a" (declared in f3())
"b" (declared globally)
"e" (Declared in f3())