Exam 2 Multiple Choice Questions - Elementary Program Concepts | EECS 183, Exams of Electrical and Electronics Engineering

Material Type: Exam; Professor: Dorf; Class: Elem Prog Concepts; Subject: Electrical Engineering And Computer Science; University: University of Michigan - Ann Arbor; Term: Fall 2011;

Typology: Exams

2011/2012

Uploaded on 01/04/2012

azhexembay
azhexembay 🇺🇸

1 document

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
EECS 183 Fall 2011 Exam 2
Part 1 (80 points)
Closed Book Closed Notes Closed Electronic Devices Closed Neighbor
Turn off Your Cell Phones
Multiple Choice Questions
Form 1
Instructions: Read Carefully!
1. This is a closed book exam. You may not refer to any materials during the exam.
2. Please turn off your cell phones before the start of the exam.
2. Some questions are not simple, therefore, read carefully.
3. Assume all code and code fragments compile, unless otherwise specified.
4. Assume/use only the standard ISO/ANSI C++.
5. On the scantron sheet, circle your name and UMID.
6. On the scantron sheet, circle Form 1.
7. On the scantron sheet, sign your name to indicate the honor pledge below:
I have neither given nor received aid on this examination, nor have I concealed any
violations of the Honor Code.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Exam 2 Multiple Choice Questions - Elementary Program Concepts | EECS 183 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

EECS 183 Fall 2011 Exam 2

Part 1 (80 points)

Closed Book Closed Notes Closed Electronic Devices Closed Neighbor

Turn off Your Cell Phones

Multiple Choice Questions

Form 1

Instructions: Read Carefully!

  1. This is a closed book exam. You may not refer to any materials during the exam.
  2. Please turn off your cell phones before the start of the exam.
  3. Some questions are not simple, therefore, read carefully.
  4. Assume all code and code fragments compile, unless otherwise specified.
  5. Assume/use only the standard ISO/ANSI C++.
  6. On the scantron sheet, circle your name and UMID.
  7. On the scantron sheet, circle Form 1.
  8. On the scantron sheet, sign your name to indicate the honor pledge below:

I have neither given nor received aid on this examination, nor have I concealed any violations of the Honor Code.

(20 questions * 4 points per question = 80 points)

  1. Consider the following code fragment:

int i=0, x;

do { i++; cin >> x; } while (x >= 0);

cout << i << endl;

If the user types 10 20 -30 40 and presses enter at the standard input, what does the above code fragment print? a) 0 b) 1 c) 2 d) 3 e) 4

  1. Consider the following code fragment:

int i=0, x;

cin >> x; while (x >= 0) { i++; cin >> x; }

cout << i << endl;

If the user types 10 20 -30 40 and presses enter at the standard input, what does the above code fragment print? a) 0 b) 1 c) 2 d) 3 e) 4

  1. Consider the following code fragment:

int i; for (i = 16; i == 3; i = i / 3) { // do nothing in the loop body } cout << i << endl;

What does the above code fragment print? a) 16 b) 3 c) 1 d) the evaluation goes into an infinite loop e) none of the above

  1. Consider the following code fragment:

int i; for (i = 16; i != 3; i = i / 3) { // do nothing in the loop body } cout << i << endl;

What does the above code fragment print? a) 16 b) 3 c) 1 d) the evaluation goes into an infinite loop e) none of the above

  1. Which of the following is a valid array declaration? a) const int N = 100; int a[N]; b) int n = 100; int a[n]; c) int n; cin >> n; int a[n]; d) all of the above e) none of the above
  1. Consider the following code fragment:

for (int i = 0; i < 3; i++) { for (int j = 3; j > 0; j --) { cout << i + j << " "; } }

What does the above code fragment print? a) 3 4 5 2 3 4 1 2 3 b) 3 2 1 4 3 2 5 4 3 c) 3 2 1 0 4 3 2 1 5 4 3 2 d) 3 2 1 0 4 3 2 1 5 4 3 2 6 5 4 3 e) none of the above

  1. Consider the following code fragment:

int a[7] = {1,1,1,1,1,1,1};

for (int i = 2; i < 7; i++) a[i] = a[i-1] + a[i-2];

for (int i = 0; i < 7; i++) cout << a[i] << " ";

What does the above code fragment print? a) 1 1 1 1 1 1 1 b) 1 1 2 2 2 2 2 c) 1 1 2 3 5 8 13 d) the result is unpredictable because the above code makes an out of bounds array access e) none of the above

10.Which of the following C++ expressions evaluates to true if and only if x is a character between ' 0 ' and ' 9 ' inclusive? a) 0 <= x <= 9 b) '0' <= x <= '9' c) 0 <= x && x <= 9 d) '0' <= x && x <= '9'

13.Consider the following program:

#include using namespace std;

void triple(int a0, int a1, int a2, int a3);

int main() { int a0 = 0; int a1 = 1; int a2 = 2; int a3 = 3;

triple(a0,a1,a2,a3);

cout << a0 << a1 << a2 << a3;

return 0; }

void triple(int a0, int a1, int a2, int a3) { a0 = 3 * a0; a1 = 3 * a1; a2 = 3 * a2; a3 = 3 * a3; }

What does the above program print? a) 0000 b) 0123 c) 0369 d) none of the above

14.Consider the following program:

#include using namespace std;

void triple(int& a0, int& a1, int& a2, int& a3);

int main() { int a0 = 0; int a1 = 1; int a2 = 2; int a3 = 3;

triple(a0,a1,a2,a3);

cout << a0 << a1 << a2 << a3;

return 0; }

void triple(int& a0, int& a1, int& a2, int& a3) { a0 = 3 * a0; a1 = 3 * a1; a2 = 3 * a2; a3 = 3 * a3; }

What does the above program print? a) 0000 b) 0123 c) 0369 d) none of the above

18.Consider the following code fragment:

ifstream f; f.open("file.txt");

int x=5, y=5, z=5; f >> x >> y >> z;

cout << z;

What does the above code fragment print, if file.txt does not exist? a) 5 b) the program terminates without printing anything c) the program terminates with an error message indicating that the file does not exist

19.Consider the following C++ function prototype along with its specifications:

// Requires: n >= 0 // Effects: Returns the square root of n

double squareRoot(double n);

Which of the following is an invalid function call? a) double x = squareRoot(0); b) double x = squareRoot(1); c) double x = squareRoot(-1); d) none of the above

20.Consider the following C++ function:

int square(int& n) { n = n * n; return n; }

If a variable x of type int is initialized to 2 , what does the C++ expression square(x) + square(x) evaluate to? a) 8 b) 20 c) none of the above