1. You are prohibited from copying or reproducing this test.
2. Copy the template, attached to the note sent to you today, to your personal computer. 3. Do not write in the spaces that are colored green.
4. Type your name on the template, in the AUTHOR IDENTIFICATION BLOCK, in the space labeled NAME.
5. Type your student identification number, on the template, in the AUTHOR IDENTIFICATION BLOCK, in the space labeled STUDENT ID NUMBER.
6. Type your e-mail address, on the template, in the AUTHOR IDENTIFICATION BLOCK, in the space labeled E-MAIL ADDRESS.
7. Type your CRN, on the template, in the AUTHOR IDENTIFICATION BLOCK, in the space labeled CRN.
7.1. Type 11229 if you are enrolled in the on-campus section of CMSC 4023 – Programming Languages.
7.2. Type 13853 if you are enrolled in the IVE section of CMSC 4023 – Programming Languages.
7.3. Type 11230 if you are enrolled in the on-campus section of CMSC 5023 – Programming Languages.
7.4. Type 13855 if you are enrolled in the IVE section of CMSC 5023 – Programming Languages.
8. You are prohibited from consulting anyone to answer the questions on the test. You must answer all questions on this without help from any source on the internet. You will be assigned a score of zero if you fail to comply with this requirement. Identical solutions to this examination are a prima facie case for academic dishonesty.
9. Enter the best selection that satisfies the question. If selection b is better that selections a and d, then enter selection b. Enter only one selection.
10. Answer all 50 questions.
11. Attach the template to note that you will send to me [email protected].
11.1. Name the template your_CRN-your_last_name-your_first_name-t03.xlsx. For example, if you are Niklaus Wirth and you are enrolled in CRN 11229, then name the template containing your answers 11229-Wirth-Niklaus-t03.xlsx. Likewise, if you are Ada Lovelace and you are enrolled in CRN 13853, then name the template containing your answers 13853-Lovelace-Ada-t03.xlsx.
11.2. Make the subject of this note similar to the name of this document. Again, if you are Niklaus Wirth and you are enrolled in CRN 11229, then the subject of your note to me would be 11229-Wirth-Niklaus-t03. Similarly, if you are Ada Lovelace and you are enrolled in CRN 11229, then the subject of your note to me would be 11229-Lovelace-Ada-t03.
11.3. Your completed template must be received by me no later than Tuesday, December 8, 2020, at 9:45 p.m.
1. (Ch. 11) What detail of C++ classes fail to satisfy the requirements of an ideal abstract data type?
a. Pointers must be employed to implement classes requiring aggregate data. b. The internal structure of the class is visible to the client program.
c. Unnecessary details of the type are hidden from units outside the enclosure that use the type.
d. The class definition includes only the data representation needed for the type.
2. (Ch. 1) What programming language has dominated scientific computing over the past 50 years?
a. C b. Lisp c. Fortran d. APL
3. (Ch. 1) What does orthogonality mean in the context of language evaluation criteria? a. A relatively small set of primitive constructs can be combined in a relatively small
number of ways to build the control and data structures of the language.
b. The characteristic allows a program to perform to its specifications under all conditions. c. The ability to define and then use complicated structures or operations in ways that
allow many of the details to be ignored.
d. The ability of language to express computation conveniently, rather than in a cumbersome way.
4. (Ch. 1) Which of the following is NOT a phase of compilation? a. lexical analysis
b. semantic analysis c. syntax analysis d. static analysis
5. (Ch. 3) Given the grammar in the figure below, select the leftmost derivation of the string (a+b)*c. e → t e → e+t e → e-t t → f t → t*f t → t/f t → t%f f → (e) f → id
a. Step Sentential Form Explanation 1 e 2 t 3 t*f 4 t*c 5 f*c 6 (e)*c 7 (e+t)*c 8 (e+f)*c 9 (e+b)*c 10 (t+b)*c 11 (f+b)*c 12 (a+b)*c
b. Step Sentential Form 1 e 2 t 3 t*f 4 f*f 5 (e)*f 6 (e+t)*f 7 (t+t)*f 8 (f+t)*f 9 (a+t)*f 10 (a+f)*f 11 (a+b)*f 12 (a+b)*c
c. Step Sentential Form Explanation 1 e 2 t 3 t*f 4 f*f 5 (e)*f 6 (e+t)*f 7 (e+t)*c 8 (e+f)*c 9 (e+b)*c 10 (t+b)*c 11 (f+b)*c 12 (a+b)*c
d. Step Sentential Form Explanation 1 e 2 t 3 t*f 4 t*c 5 f*c 6 (e)*c 7 (e+t)*c 8 (t+t)*c 9 (f+t)*c 10 (a+t)*c 11 (a+f)*c 12 (a+b)*c
6. (Ch. 3) Select the parse tree for the sentence a/b-c in the grammar shown below.
e → t e → e+t e → e-t t → f t → t*f t → t/f f → (e) f → id
e
-t
t
/
f
t
f
f
id( c )
id( a )
id( b )
a.e
e
-
t
t
t
f
/
f
f
id( a )
id( c )
id( b )
b.e
e
-
t
t
t
/
f
f
f
id( a )
id( b )
id( c )
c.
e
e
-t
t
t
/
f
f
f
id( c )
id( b )
id( a )
d.7. (Ch. 3) Compute the weakest precondition for the given assignment statement with the condition that 𝑎𝑎, 𝑏𝑏 ∈ ℤ. 𝑎𝑎 = 2 × (𝑏𝑏 − 1) − 1 {𝑎𝑎 > 0} a. 𝑏𝑏 > 0 b. 𝑏𝑏 >32 c. 𝑏𝑏 > 1 d. 𝑏𝑏 >12
8. (Ch. 1.) What is the most important criterion employed to evaluate the idea of a single language for all programming domains?
a. Cost b. Value c. Innovation d. Reliability
9. (Ch. 4) Which of the following grammars is NOT pairwise disjoint?
Id LHS RHS Id LHS RHS 1 A → aB 1 A → aB 2 A → bAb 2 A → Ba 3 A → Bb 3 A → bB 4 B → cB 4 B → cB 5 B → d 5 B → d a. b.
Id LHS RHS Id LHS RHS 1 A → Ba 1 A → Ba 2 A → bAb 2 A → a 3 A → bB 3 B → b 4 B → cB 4 C → c 5 B → d c. d.
10. (Ch. 4) How many symbols are popped from the parse stack when ACTION[𝒔𝒔𝒎𝒎, 𝒂𝒂𝒊𝒊]=R3 given
the grammar shown below. ID LHS RHS 1 E → E + T 2 E → T 3 T → T * F 4 T → F 5 F → ( E ) 6 F → id a. 0 b. 2 c. 4 d. 6
11. (Ch. 1) Which of the following is NOT a programming language evaluation criterion according to Sebesta?
a. Portability b. Readability c. Writability d. Reliability
12. (Ch. 4) Find the FIRST sets for the grammar shown below. (Note. 𝜆𝜆 is the empty string)
L → TL’ L’ → ∨TL’ L’ → 𝜆𝜆 T → FT’ T’ → ∧FT’ T’ → 𝜆𝜆 F → <L> F → 𝜶𝜶
Nonterminal FIRST set Nonterminal FIRST set L {L’} L {<,𝜶𝜶} L’ {L’} L’ {∨} T {T’} T {<,𝜶𝜶} T’ {T’} T’ {∧} F {),id} F {<,𝜶𝜶} a. b.
Nonterminal FIRST set Nonterminal FIRST set
L {T} L {<,𝜶𝜶} L’ {∨,𝝀𝝀 } L’ {∨,𝝀𝝀 } T {F} T {<,𝜶𝜶} T’ {∧,𝝀𝝀} T’ {∧,𝝀𝝀} F {<,𝜶𝜶} F {<,𝜶𝜶} c. d.
13. (Ch. 4) Which of the following is a limitation of the LL grammar class? a. must be implemented by employing a recursive descent parser b. lexical analysis must be implemented using finite automata c. must be implemented using a pushdown automaton d. left recursion must be eliminated
14. (Ch. 4) Find the order in which rules of the grammar were reduced from the start symbol to terminal symbols given the actions of an LR parser.
ACTION shift reduce by F → id reduce by T → F shift shift shift reduce by F → id reduce by T → F reduce by E → T shift shift reduce by F → id reduce by T → F reduce by E → E + T reduce by F → ( E ) reduce by T → T * F reduce by E → T
a. 1 𝐸𝐸 → 𝑇𝑇 2 𝐸𝐸 → 𝐸𝐸 + 𝑇𝑇 3 𝐹𝐹 → (𝐸𝐸) 4 𝐸𝐸 → 𝑇𝑇 ∗ 𝐹𝐹 5 𝑇𝑇 → 𝐹𝐹 6 𝐹𝐹 → 𝐢𝐢𝐢𝐢 7 𝐸𝐸 → 𝑇𝑇 8 𝑇𝑇 → 𝐹𝐹 9 𝐹𝐹 → 𝐢𝐢𝐢𝐢 10 𝑇𝑇 → 𝐹𝐹 11 𝐹𝐹 → 𝐢𝐢𝐢𝐢 b. 1 𝐸𝐸 → 𝑇𝑇 ∗ 𝐹𝐹 2 𝑇𝑇 → 𝐹𝐹 3 𝐹𝐹 → (𝐸𝐸) 4 𝐸𝐸 → 𝐸𝐸 + 𝑇𝑇 5 𝑇𝑇 → 𝐹𝐹 6 𝐹𝐹 → 𝐢𝐢𝐢𝐢 7 𝐸𝐸 → 𝑇𝑇 8 𝑇𝑇 → 𝐹𝐹 9 𝐹𝐹 → 𝐢𝐢𝐢𝐢 10 𝑇𝑇 → 𝐹𝐹 11 𝐹𝐹 → 𝐢𝐢𝐢𝐢 c. 1 𝐹𝐹 → 𝐢𝐢𝐢𝐢 2 𝑇𝑇 → 𝐹𝐹 3 𝐹𝐹 → 𝐢𝐢𝐢𝐢 4 𝑇𝑇 → 𝐹𝐹 5 𝐸𝐸 → 𝑇𝑇 6 𝐹𝐹 → 𝐢𝐢𝐢𝐢 7 𝑇𝑇 → 𝐹𝐹 8 𝐸𝐸 → 𝐸𝐸 + 𝑇𝑇 9 𝐹𝐹 → (𝐸𝐸) 10 𝑇𝑇 → 𝑇𝑇 ∗ 𝐹𝐹 d. 1 𝐸𝐸 → 𝑇𝑇 2 𝑇𝑇 → 𝑇𝑇 ∗ 𝐹𝐹 3 𝐹𝐹 → (𝐸𝐸) 4 𝐸𝐸 → 𝐸𝐸 + 𝑇𝑇 5 𝑇𝑇 → 𝐹𝐹 6 𝐹𝐹 → 𝐢𝐢𝐢𝐢 7 𝐸𝐸 → 𝑇𝑇 8 𝑇𝑇 → 𝐹𝐹 9 𝐹𝐹 → 𝐢𝐢𝐢𝐢 10 𝑇𝑇 → 𝐹𝐹 11 𝐹𝐹 → 𝐢𝐢𝐢𝐢 15. (Ch. 5) Select the correct storage type for variable m.
#include <iostream> #include <iomanip> using namespace std; int max(int A[],int N) { int m=A[0];
for (int i=1;i<N;i++) if (A[i]>m) m=A[i]; return m;
}
int main()
{ int A[]={17,2,-3,11,5,-7,-13};
cout << max(A,7) << endl; return 0;
}
a. Static variable
b. Stack-Dynamic variable
c. Explicit Heap-Dynamic variable d. Implicit Heap-Dynamic variable
16. (Ch. 5) What is printed by the program assuming dynamic scope?
#include <iostream> using namespace std; int a,b;
void print(void){cout << "a=" << a << " b=" << b;} void r(void){int b=3; a=4;}
void q(void){int b=5;int a=6; r();print();} void p(void){int a=1; int b=2; q();} int main(){a=3; b=7;p();return 0;} a. a=4 b=3
b. a=3 b=2 c. a=6 b=5 d. a=1 b=7
17. (Ch. 5) What is printed by the program assuming static scope? #include <iostream>
using namespace std; int a,b;
void print(void){cout << "a=" << a << " b=" << b;} int p(int& a){int p=2;a=0;b=1;return p;}
void q(void){int b=4;a=3;print();} int main(){a=p(a);q();return 0;} a. a=3 b=1
b. a=3 b=4 c. a=2 b=4 d. a=1 b=3
18. (Ch. 3) Select the table that correctly specifies the precedence and associativity of the operators given in the grammar shown below. Please note that the highest precedence is one (1). e → t e → e+t e → e-t t → f t → t*f t → t/f f → p f → p ^ f p → (e) p → u u → -u u → id
op name precedence associativity
+ addition 1 left - subtraction 1 left * multiplication 2 left / division 2 left ^ exponentiation 3 right () parenthesis 4 n/a
- unary minus 5 right
a.
op name precedence associativity
- unary minus 1 left
() parenthesis 2 n/a ^ exponentiation 3 left * multiplication 4 right / division 4 right + addition 5 right - subtraction 5 right b.
op name precedence associativity + addition 1 right - subtraction 1 right * multiplication 2 right / division 2 right ^ exponentiation 3 left () parenthesis 4 n/a
- unary minus 5 left
c.
op name precedence associativity
- unary minus 1 right
() parenthesis 2 n/a ^ exponentiation 3 right * multiplication 4 left / division 4 left + addition 5 left - subtraction 5 left d.
19. (Ch. 5) Select the correct storage type for variable A. #include <iostream>
#include <iomanip> using namespace std; int max(int A[],int N) { int m=A[0];
for (int i=1;i<N;i++) if (A[i]>m) m=A[i]; return m;
}
int main()
{ int *A=new int[7];
A[0]=17; A[1]=2; A[2]=-3; A[3]=11; A[4]=5; A[5]=-7; A[6]=-13;
cout << max(A,7) << endl; return 0;
}
a. Static variable
b. Stack-Dynamic variable
c. Explicit Heap-Dynamic variable d. Implicit Heap-Dynamic variable
20. (Ch. 6) Assume that each element of array A is an integer and occupies 4 bytes, array A has 5 rows whose indexes are 1, 2, …, 5 and 3 columns whose indexes are 1, 2, …, 3. Array A is allocated in row-major order. Without subscripts A is the address of the first byte allocated. Given that the first byte of the array is stored at address 256, what is the address of the first byte of element A[4][2]?
a. 296 b. 40 c. 320 d. 280
21. (Ch. 6) Which of the following is NOT a string length option discussed in our text? a. static length string
b. limited dynamic length string c. dynamic length string
22. (Ch. 6) Which kind of type checking makes type X equivalent to type Y? type X=array[1..10] of integer; type Y=array[1..10] of integer;
a. dynamic b. referential c. structural d. static
23. (Ch. 6) Which code fragment produces a dangling pointer? #include <iostream>
using namespace std; int* f(void){return new int;} int main() { int* p=f(); int q; p=&q; return 0; } #include <iostream> using namespace std; int* f(void) { int d; return &d; } int main() { int* p=f(); return 0; } a. b. #include <iostream> using namespace std; int* f(void){return new int;} int main() { int* p=f(); p=new int; return 0; } #include <iostream> using namespace std; int main()
{ int* p=new int; int* q=p; delete q; return 0; }
c. d.
24. (Ch. 6) What is the difference between a pointer and a reference?
a. A pointer can refer to any address in memory whereas a reference can only point to an address in the heap.
b. A reference permits arithmetic operations whereas such operations are prohibited on pointers.
c. A pointer refers to an address in memory, while a reference refers to an object or a value in memory.
d. Reference variables can only be assigned to class instances while pointers are not so restricted.
25. (Ch. 3) Which of the following grammars is NOT ambiguous? a. 𝐸𝐸 → 𝐸𝐸 + 𝑇𝑇 | 𝑇𝑇 𝑇𝑇 → 𝑇𝑇 ∗ 𝑇𝑇 | 𝐹𝐹 𝑇𝑇 → (𝐸𝐸) 𝑇𝑇 → 𝐢𝐢𝐢𝐢 b. 𝐸𝐸 → 𝐸𝐸 𝐴𝐴 𝐸𝐸 | (𝐸𝐸) | 𝐢𝐢𝐢𝐢 𝐴𝐴 → + | ∗ c. 𝐸𝐸 → 𝐸𝐸 + 𝑇𝑇 | 𝐸𝐸 ∗ 𝐸𝐸 | (𝐸𝐸) 𝐢𝐢𝐢𝐢 d. 𝐸𝐸 → 𝐸𝐸 + 𝑇𝑇 | 𝑇𝑇 𝑇𝑇 → 𝑇𝑇 ∗ 𝐹𝐹 | 𝐹𝐹 𝑇𝑇 → (𝐸𝐸) | 𝐢𝐢𝐢𝐢
26. (Ch. 7) For which of these operators is there a compelling argument to associate left to right?
a. post-decrement b. unary minus c. assignment d. pre-increment
27. (Ch. 7) Which of the following code fragments contains an example of coercion? #include <iostream> using namespace std; int main() { char A=0x20; A = A << 1 | 0x01; cout << A << endl; return 0; } #include <iostream> using namespace std; int main() { double x=1.0; double y=x+1; return 0; } a. b. #include <string> using namespace std; int main() { string s="tomat"; char c='o'; s=s+c; return 0; } #include <iostream> using namespace std; int main() { double x=1.0; double y=2.0; int i=(int)(x+y); return 0; } c. d.
28. (Ch. 5) Which of the following statements is NOT true regarding the binding times of the given C++ statement?
count = count + 5; a. The type of count is bound at compile time.
b. The set of possible values of count is bound at compiler design time. c. The value of count is bound at execution time.
d. The internal representation of the literal 5 is bound at compile time.
29. (Ch. 7. p. 321) Assume the following rules of associativity and precedence for expressions.
Operators Precedence Associativity
*, /, not highest left to right
+, - & mod left to right
- (unary) right to left
=, /=, <, <=, >=, > left to right
and left to right
or, xor lowest left to right
Show the order of evaluation of the expression in the shaded box below by parenthesizing all sub-expressions and placing a superscript on the right parenthesis to indicate the order. For example, for the expression
a + b * c + d
the order of evaluation would be represented as ((a + (b * c)1)2 + d)3
(a – b) / c & (d * e / a – f) a. (((a-b)1/c)2&(((d*e)3/a)4-f)5)6
b. (((a-b)1/c)5&(((d*e)2/a)3-f)4)6 c. (((a-(b/c)1)2&(((d*e)3/a)4-f)5)6 d. (((a-b)4/c)5&(((d*e)1/a)2-f)3)6
30. (Ch. 7) What is printed by the program if operands on lines 9 and 11 are evaluated right to left? 1. #include <iostream> 2. using namespace std; 3. int fun(int* k) 4. { *k += 4; 5. return 3 * (*k) -1; 6. } 7. int main() 8. { int i=5,j=7,sum1,sum2; 9. sum1=(i/2)+fun(&i); 10. cout << " sum1=" << sum1; 11. sum2=fun(&j)+(j/2); 12. cout << " sum2=" << sum2; 13. cout << endl; 14. return 0; 15. } a. sum1=30 sum2=37 b. sum1=28 sum2=37 c. sum1=28 sum2=35 d. sum1=30 sum2=35
31. (Ch. 8) What programming language feature illustrated in the code fragment below is prohibited in C#? switch (value) { case -1: Negatives++; break; case 0: Zeros++; goto case 1; case 1: Positives++; default: Console.WriteLine(“Default\n”); }
a. implicit execution of more than one selectable segment b. unary assignment operators ++ and --.
c. goto statements d. negative case values.
32. (Ch. 8) What programming language contains the grammar given below for a for-statement?
for-statement → for loop-variable in object statement
for-statement → for loop-variable in object statement else statement
a. Python b. CLU c. Ada d. Perl
33. (Ch. 8) What is the value of variable Count after the Ada code fragment given below exits the loop?
Count: Float:=2.0; for Count in 2..10 loop
Sum:=Sum+Count; end loop; a. 54 b. 2 c. 11 d. 2.0
34. (Ch. 8. p. 354) In what language is the following example prohibited? if (sum==0) if (count==0) result=0; else result=1; a. Perl b. Java c. C# d. C++
35. (Ch. 8. p. 388) The multiple-selection statement given in the shaded box is translated to a multiple-selection statement in the unshaded box below. What is the language employed in the unshaded box?
if ((k == 1) || (k == 2)) j = 2 * k – 1 if ((k == 3) || (k == 5)) j = 3 * k + 1 if (k == 4) j = 4 * k – 1 if ((k == 6) || (k == 7) || (k == 8)) j = k - 2 case k is when 1..2=> j=2*k-1; when 3| 5=> j=3*k+1; when 4=> j=4*k-1; when 6..8=> j=k-2; end case; a. Ruby b. Ada c. Fortran 95 d. Python
36. (Ch. 9 p 427-429) What characteristic of nested subprograms makes this feature undesirable in modern programming languages?
a. Nested subprograms present a challenge for non-local references when subprograms can be parameters because of the ambiguity of which locality is to be placed in the static chain. Omitting nested subprograms eliminates the need for a static chain making subprogram invocation and return simpler and faster.
b. Many programming languages do not allow nested subprograms because it is believed that it will lead to ambiguity within the program as well as error compilations. If someone were to declare a subroutine that needed to access variables for two
subprograms and they declare those variables in the global scope, this would be unsafe because there already may be a variable of the same name there. In this case, global variables would be a hindrance to readability.
c. Nested subprograms have the potential to cause additional problems over those that are not nested. Nested subprograms introduce complexity with parameters involving scope such as whether parameters from one subprogram can be passed to another and which version of a variable has precedence. Many contemporary languages use more of an object-oriented approach to abstraction which makes it desirable for each part of a program to do one and only one thing. Nested subprograms tend to widen that scope so abstraction is lost and multiple operations are happening at once. Often side effect – unwanted ones for the most part – tend to creep into any more complex section of code. Not only does complexity increase but with nested subprograms, often,
readability diminishes. With any increase in chance of error, any unwanted side effect, or decrease in readability the efficiency of the program and of those working with decreases.
d. Nested subprograms are possibly not included in contemporary languages for two possible reasons. The first being that nested subprograms can lead to ambiguity in the programs. The second reason is that nested subprograms can cause serious compilation errors.
37. (Ch. 9) Determine the parameter passing method for the code shown in the unshaded box given that the values of local variables after the last call to function swap and before exiting function main is as shown in the shaded box.
void swap(int a, int b) { int temp temp=a; a=b; b=temp; } int main() { int value=2,list[5]={1,3,5,7,9}; swap(value,list[0]); swap(list[0],list[1]); swap(value,list[value]); return 0; } value=2 list={3,2,1,7,9} a. Pass-by-value b. Pass-by-reference c. Pass-by-result d. Pass-by value-result.
38. (Ch. 7) Identify the expressions evaluated and values assigned in the C++ code fragment shown below. Please note that expressions are evaluated in the order in which they appear from left to right. Expressions are separated by commas in the selections below.
int a=0; int b=5;
a>=0||b<5?a=5:b=0; a. a>=0, b<5, a=5, b=0 b. a>=0, b<5, a=5, c. a>=0, a=5 d. a>=0, b<5, b=0
39. (Ch. 9. p 433) What is printed by the program shown below? #include <iostream>
using namespace std;
template <class T>T mx(T u,T v){return u>v?u:v;} #define Mx(u,v)((u)>(v))?(u):(v) int main() { int a(1),b(0); int c=Mx(a++,b); cout << " a=" << a; cout << " b=" << b; int d=mx(a--,b); cout << " a=" << a; cout << " b=" << b; cout << endl; return 0; } a. a=2 b=0 a=1 b=0 b. a=3 b=0 a=2 b=0 c. a=2 b=0 a=2 b=0 d. a=1 b=0 a=0 b=0
40. (Ch. 9, p 428-429) Assuming that deep binding is used to establish the referencing environment, what is printed by the program shown below?
program q40; var x:integer; procedure p1; var x:integer;
procedure p2; begin{p2} writeln('x=',x) end{p2}; procedure p3; var x:integer; begin x:=3; p4(p2); end{p3}; procedure p4(procedure px); var x:integer; begin x:=4; px; end{p4}; begin{p1} x:=1; p3 end{p1}; begin x:=2; p1 end. a. x=2 b. x=3 c. x=4 d. x=1
41. (Ch. 10, p 466) Select the figure showing the stack with all activation record instances, including static and dynamic chains, when execution reaches position 1 in the following skeletal program. Assume Bigsub is at level 1?
procedure Bigsub is procedure A is procedure B is begin -- B … <---1 end; -- B procedure C is begin -- C … B; … end; -- C begin -- A … C; … end; -- A begin -- Bigsub … A; … end; -- Bigsub dynamic link dynamic link dynamic link dynamic link static link static link static link static link return to return to Bigsub return to A return to C
ARI for Bigsub ARI for A ARI for C ARI for B dynamic link dynamic link dynamic link dynamic link static link static link static link static link return to return to Bigsub return to A return to B
ARI for Bigsub ARI for A ARI for B ARI for C
dynamic link dynamic link dynamic link dynamic link static link static link static link static link return to return to Bigsub return to A return to C
ARI for Bigsub ARI for A ARI for C ARI for B dynamic link dynamic link dynamic link dynamic link static link static link static link static link return to return to Bigsub return to A return to B
ARI for Bigsub ARI for A ARI for B ARI for C
c d
42. (Ch. 10) What is the maximum number of activation records allocated to execute the program shown below?
program p; var a:integer;
function f(n:integer):integer;
begin{f} if n<=0 then f:=1 else f:=n*f(n-1) end{f}; begin{p} a:=f(5) end{p}. a. 5 b. 2 c. 6 d. 7
43. (Ch. 10) Mark the selection that identifies all the characteristics required to implement FORTRAN activation records.
a. storage for the return address and the static link b. storage for static and dynamic links
c. storage for local variables, parameters, and the return address d. storage for local variables, the static and dynamic link
44. (Ch. 10) Mark the selection that identifies all the characteristics required to implement Ada activation records.
a. static links, storage for local variables, storage for the return address, storage for the return value.
b. static links, dynamic links, storage for local variables, storage for the return address c. static links, dynamic links, storage for the return address, storage for the return value. d. static links, dynamic links, storage for local variables, storage for the return value. 45. (Ch. 10) Mark the selection that describes deep access.
a. A reference to a nonlocal stack dynamic local variable is resolved by searching through the activation record instances, by following the static link, of the other subprograms that are currently active, beginning with the one most recently activated.
b. A reference to a nonlocal variable is resolved by searching the stack of values for that variable.
c. A reference to a nonlocal stack dynamic local variable is resolved by searching through the activation record instances, by following the dynamic link, of the other subprograms that are currently active, beginning with the one most recently activated.
d. A reference to a nonlocal variable is resolved by retrieving the value on top the stack of for that variable.
46. (Ch. 11) What is one way that a C++ client program CANNOT reference a name from a namespace defined in a header file assuming the namespace name is MyStack and the variable is named topPtr?
a. MyStack::topPtr.
b. namespace::MyStack::topPtr c. using MyStack::topPtr d. using namespace MyStack
47. (Ch. 11) Which of the following is a valid implementation of the member function that implements division in a class complex that defines the representation and implementation of complex variables?
class Complex { double real, imag; public:
Complex operator/(const Complex& x)const { double d=x.real*x.real-x.imag*x.imag; double r=(real*x.real+imag*x.imag)/d; double i=(imag*x.real-real*x.imag)/d; return Complex(r,i); } . . . }; a. class Complex {
double real, imag; public:
Complex operator/(const Complex& x)const { double d=x.real*x.real+x.imag*x.imag; double r=(real*x.real+imag*x.imag)/d; double i=(imag*x.real-real*x.imag)/d; return Complex(r,i); } . . . }; b. class Complex {
double real, imag; public:
Complex divide(const Complex& c) { Complex comp;
comp.real = this->real / c.real;
comp.imag = this->imag / c.imag; return comp;
} . . . };
class ComplexNumbers{
ComplexNumbers(){}
float div(float n1, float n2}{return n1/n2;} . . .
};
d.
48. (Ch. 11) Which of the following are NOT programming language requirements needed to implement abstract data types?
a. The subprograms that implement the operations on the type must appear inside the syntactic unit.
b. The programming language must provide a syntactic unit that encloses the declaration of the type and the prototypes of the subprograms that implement the operations on the type.
c. The syntactic unit enclosing the declaration and its subprograms must be visible to clients.
d. The representation of the type must be hidden. 49. (Ch. 11) What is NOT in an Ada package specification?
a. The package name. b. The class name.
c. The type name.
50. (Ch. 9 p. 412) Assume that all values in the FORTRAN program shown are passed strictly by reference to enhance performance. What is printed by the program?
PROGRAM MAIN IMPLICIT NONE INTEGER :: I I = 5 CALL S(1,I) I = I + 1 WRITE(*,*) I CONTAINS SUBROUTINE S(A,B)
INTEGER, INTENT (INOUT) :: A, B A = 2
B = 3
END SUBROUTINE S END PROGRAM MAIN
a. 2 b. 3 c. 6 d. 5