The following questions refer to the skeletal C++ program show below. Assume tha
ID: 646367 • Letter: T
Question
The following questions refer to the skeletal C++ program show below.
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.
Repeat part (a), but list the variables that are visible at Line 2.
Repeat part (a), but list the variables that are visible at Line 3.
Repeat part (a), but list the variables that are visible at Line 4.
Repeat part (a), but list the variables that are visible at Line 5.
Assume that dynamic scoping is used, and that main calls f1, which calls f2, which calls f3. (Assume that f2 calls f3 on Line 4.) 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();
void f3();
int a, b;
int main()
{
int b, c, d;
... // Line 1
}
void f1()
{
int a, c;
... // Line 2
}
void f2()
{
int b, d;
if (...) {
int a, e;
... // Line 3
}
... // Line 4
}
void f3()
{
int a, e;
... // Line 5
}
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)
Please explain how you get each answer
Explanation / Answer
Msg = ReceiveMessage(); switch (pMsg->type) { case FREQUENT_MSG1: handleFrequentMsg1(); break; case FREQUENT_MSG2: handleFrequentMsg2(); break; . . . case FREQUENT_MSGn: handleFrequentMsgn(); break; default: // Nested switch statement for handling infrequent messages. switch (pMsg->type) { case INFREQUENT_MSG1: handleInfrequentMsg1(); break; case INFREQUENT_MSG2: handleInfrequentMsg2(); break; . . . case INFREQUENT_MSGm: handleInfrequentMsgm(); break; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.