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

The following questions refer to the skeletal C++ program shown below. (a) Assum

ID: 3804488 • Letter: T

Question

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 f1, which calls f2. (Assume that f1 calls f2 on Line 3.) List all variables, along with the functions in which they are declared, that are visible at Line 5 in the program. void f1(); void f2(); int a, b; int main() {int c, d, e;//Line 1} void f1() {int b, c, e; if () {int b, d;//Line 2}//Line 3} void f2() {int a c, e; if () {int b, e;//Line 4}//Line 5} A sample answer to one part of the problem might look like this: a (global), b (declared in if block in f1), c (declared in f1)

Explanation / Answer


inside main function()
these varibales scope limted with in the main method only
c(declared in main)
d(decalred in main)
e(decalred main function)inside main function()


inside f1()

d(decalred in main)
e(decalred main function)


inside the f1 method's if block

these variable scope is with in the if block only
b(declared inside if block of f1())
d(declared inside if blockof f1())

inside f1() method

these variable scope is with in f1 method only
b(declared inside the f1 method)
c(declared inside the f1 method)
e(declared inside the f1 method)

inside the f2 method's if block

these variable scope is with in if block only
b(declared inside the if block of f2())
e(declared inside the if blockof f2())

inside f2 method

these variable scope is with in f2 method only
a(declared inside the f2 method)
c(declared inside the f2 method)
e(declared inside the f2 method)


f)assuming
main()
{
   f1();

}
f1()
{
   f2();
line 3
}
f2()
{
line 5;  
}

the variables

inside main function()
these varibales scope limted with in the main method only
c(declared in main)
d(decalred in main)
e(decalred main function)inside main function()

inside f1() method

these variable scope is with in f1 method only
b(declared inside the f1 method)
c(declared inside the f1 method)
e(declared inside the f1 method)


inside f2 method

these variable scope is with in f2 method only
a(declared inside the f2 method)
c(declared inside the f2 method)
e(declared inside the f2 method)