MULTIPLE CHOICE Questions. Circle the Letter of Your One Answer
Total Page:16
File Type:pdf, Size:1020Kb
MULTIPLE CHOICE questions. Circle the letter of your one answer
1 (5 pts) Given these functions definitions:
int fffff( double bbb ) { // some code is here } void fffff( double bbb ) { // some code is here } Which is true? (Circle the letter of your one answer)
a) This code will compile
b) This code will not compile
2 (5 pts) Given these functions definitions: void fffff( double bbb ) { // some code is here } void ggggg( double bbb ) { // some code is here } Notice that the functions have different names but the parameters have the same name. Which is true? (Circle the letter of your one answer)
a) This code will compile
b) This code will not compile
3 (5 pts) Given this function prototype and these variables: float fix(int& , float ); int someInt = 10; float someFloat = 4.3; which of the following function calls would be syntactically correct? (Circle the letter of your one answer) a) fix(someInt, 6.85); b) someFloat = fix(24,6.85); c) someFloat = 0.3 * fix(someInt, 6.85); d) fix(someInt + 5,someFloat); e) all of the above f) a) and c) above g) b) and d) above h) none of the above
WRITE PROGRAM IN BLUE BOOK page 1 of 5 pages (counting the cover sheet) 4 (5 pts) Assuming that a and b are integer variables such that a < b, assuming that srand has been called, which of the following produces a random integer in the closed interval [a, b]? (Circle the letter of your one answer) a) rand() % (b - a) b) rand() % (b - a + 1) c) a + rand() % (b - a) d) a + rand() % (b - a + 1) e) none of the above
5 (5 pts) Given this function definition: void SomeFunc( /* parameters would be here*/ ) { float alpha; /* rest of function is here */ } which of the following statements about alpha is FALSE? (Circle the letter of your one answer)
a) The memory allocated to alpha is deallocated when the function returns. b) A parameter in the function heading can also be named alpha. c) The caller of the function cannot initialize alpha. d) alpha cannot be accessed directly from code outside the function. e) None of these is false.
6 (5 pts) Which of the following statements is TRUE? (Circle the letter of your one answer) a) A void function can contain exactly one return statement. b) A void function can have more than one return statement. c) A return statement can be placed anywhere inside a void function. d) A void function must contain at least one return statement. e) A void function cannot contain any return statement. f) a), b) and c) only g) a) and c) only h) None of the above choices is true.
WRITE PROGRAM IN BLUE BOOK page 2 of 5 pages (counting the cover sheet) WHAT IS THE OUTPUT question.
7 (5 pts [no partial credit] ) What is the output? int i(6); cout << "one " << i++ << ", two " << i+1 << endl; cout << "tres " << --i << ", four " << i-1 << endl; cout << "fiv " << i << endl; Write your answer here:
one 6, two 8 tres 6, four 5 fiv 6
FILL IN THE BLANK QUESTIONS
8 (5 pts) Fill in the blank below to rewrite the statement shown using the conditional operator (?:). The same assignment must happen if( y > 12 ) x = 13; else x = 14;
Rewritten using the conditional operator:
x = (y > 12) ? 13 : 14;
WRITE PROGRAM IN BLUE BOOK page 3 of 5 pages (counting the cover sheet) WHAT IS THE OUTPUT question.
9 (15 pts) Given:
int bar( int& some, int& other ) { cout << "bar\n"; some = other * 2; other = 3; return 100; other = 77;
} void foo( int first, int & second ) { cout << "foo\n"; first = 5; second = first + bar( first, second ); }
This code compiles and runs. Use it as it is written.
What is the output of this code? int j = 6, k = 3; cout << j << " , " << k << endl; foo( j, k ); cout << j << " , " << k << endl;
Write your answer here:
6 , 3 foo bar 6 , 106
WRITE PROGRAM IN BLUE BOOK page 4 of 5 pages (counting the cover sheet) WHAT IS THE OUTPUT question.
10 (15 pts) What is the output of the following program?
#include
Write your answer here:
4 11 16 6 15 15 9 10 15 5 10 15
WRITE PROGRAM IN BLUE BOOK page 5 of 5 pages (counting the cover sheet)