Lab Exam

advertisement
Lab Exam Data Structure ) ‫( تجسير‬
Student Name:------------------------------ID:--------------------Q1: A constructor can specify the return type:
a. int.
b. string.
c. void.
d. A constructor cannot specify a return type.
ANS:.
Q2: To execute multiple statements when an if statement’s condition is true, enclose those statements in a pair of:
Parentheses, ( ).
Square Brackets, [ ].
Braces, { }.
Angle brackets, < >.
ANS:
Q3: Which of the following is a double-selection statement?
if.
if…else.
do…while.
switch.
ANS:
Q4: How many times will the following loop print hello?
i = 1;
while ( i <= 9 )
cout << "hello";
0.
9.
10.
An infinite number of times.
ANS:
Q5: Having a loop within a loop is known as:
Recursion.
Doubling up.
Nesting.
Stacking.
ANS:
Q6: If x initially contains the value 3, which of the following sets x to 7?
x
x
x
x
++ 4;
+= 4;
=+ 4;
+ 4 = x;
ANS:
Q7: Assuming that x is equal to 4, which of the following statements will not result in y containing the value 5 after execution?
y
y
y
y
=
=
=
=
5;
x++;
++x;
x + 1
ANS:
Q8: What will the following program segment do?
int counter = 1;
do
{
cout << counter << " ";
} while ( ++counter <= 10 );
a.
b.
c.
1
Print the numbers 1 through 11.
Print the numbers 1 through 10.
Print the numbers 1 through 9.
d.
ANS:.
Cause a syntax error.
Q9: Which of the following is not a valid enumeration statement?
a. Enum person { me, you, them };.
b. Enum person { me = 1, you = 2, them = 3 };.
c. Enum person { me = 0, you = 0, them = 0 };.
d. Enum person { me, you, me };.
ANS:
Q10: Which of the following is false about the following function prototype?
void functionA( void );
a.
b.
It does not receive any arguments.
It could have been written void functionA( );.
c. It does not return a value.
d.
It could have been written functionA( void );.
ANS:
Q11: The inline keyword:
a.
Increases function-call overhead.
b.
Can reduce a function’s execution time but increase program size.
c. Can decrease program size but increase the function’s execution time.
d.
Should be used with all frequently used functions.
ANS:
Q12: When an argument is passed-by-value, changes in the called function __________ affect the original variable’s value; when
an argument is passed call-by-reference, changes in the called function __________ affect the original variable’s value.
Do not, do.
Do not, do not.
Do, do.
Do, do not.
ANS:
Q13: If a set of functions have the same program logic and operations and differ only in the data type(s) each receives as
argument(s) then a(n) __________ should be used.
Overloaded function.
Recursive function.
Macro.
Function template.
ANS:
Q14: Given the following function template
template < class T >
T maximum( T value1, T value2 )
{
if ( value1 > value2 )
return value1;
else
return value2;
}
what would be returned by the following two function calls?
maximum( 2, 5 );
maximum( 2.3, 5.2 );
5 and a type-mismatch error.
5 and 5.2.
2 and 2.3.
Two error messages.
ANS:
Q15: A recursive function is a function that:
2
Returns a double.
Takes 3 arguments.
Calls itself, directly or indirectly.
Is inside of another function.
ANS:.
Q16: Assuming the following pseudocode for the Fibonacci series, what is the value of the 5th Fibonacci number (fibonacci ( 5 ))?
fibonacci( 0 ) = 0
fibonacci( 1 ) = 1
fibonacci( n ) = fibonacci( n – 1 ) + fibonacci( n – 2 )
1.
3.
5.
7.
ANS:
Q17: A class-scope variable hidden by a block-scope variable can be accessed by preceding the variable name with the class name
followed by:
::
:
.
->
ANS:
Q18: If the line:
friend class A;
appears in class B, and the line:
friend class B;
appears in class C, then:
a. Class A is a friend of class C.
b. Class A can access private variables of class B.
c. Class C can call class A’s private member functions.
d. Class B can access class A’s private variables.
ANS:
Q19: Variables defined inside a member function of a class have:
File scope.
Class scope.
Block scope.
Class or block scope, depending on whether the binary scope resolution operator (::) is used.
ANS:
Q20: The assignment operator (=) can be used to:
Test for equality.
Copy data from one object to another.
Compare two objects.
Copy a class.
ANS:
(II) Write Push () function and Pop() for a stack integer data structure with defined its class structure?
3
Download