Solutions for Exam 1 - Elementary Programming 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 2010;

Typology: Exams

2010/2011

Uploaded on 10/05/2011

zi-chuen
zi-chuen 🇺🇸

1 document

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
The University of Michigan
EECS 183: Elem. Programming Concepts
Fall 2010
Exam 1: Part 1
Professor ML Dorf
Professor E Soloway
Wednesday October 6, 2010
6:00 to 7:30 pm
Max: 85 points
Instructions
Part 1 of the exam consists of twenty five multi-choice questions. Questions 1-15
are worth 3 points each; questions 16-25 are work 4 points each)
The exam is closed book. No books, notes or the like may be used. No computers,
calculators, PDAs, cell phones or other electronic devices may be used
The exam is closed neighbor. No 'partner' on this -- only on projects
Some questions are not simple, therefore, read carefully
Assume all code and code fragments compile, unless otherwise specified.
Assume/use only the standard ISO/ANSI C++.
Within the following questions, the term valid means: code uses standard
ISO/ANSI C++, code is explicit on all typing, i.e., does not make use of default
settings.
This course operates under the rules of the College of Engineering Honor Code.
Your signature endorses the pledge below. After you finish your exam, sign your
scantron sheet to indicate the statement 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

Partial preview of the text

Download Solutions for Exam 1 - Elementary Programming Concepts | EECS 183 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

The University of Michigan

EECS 183: Elem. Programming Concepts

Fall 2010

Exam 1: Part 1

Professor ML Dorf Professor E Soloway Wednesday October 6, 2010 6 :00 to 7 :30 pm

Max: 85 points

Instructions

  • Part 1 of the exam consists of twenty five multi-choice questions. Questions 1- are worth 3 points each; questions 16-25 are work 4 points each)
  • The exam is closed book. No books, notes or the like may be used. No computers, calculators, PDAs, cell phones or other electronic devices may be used
  • The exam is closed neighbor. No 'partner' on this -- only on projects
  • Some questions are not simple, therefore, read carefully
  • Assume all code and code fragments compile, unless otherwise specified.
  • Assume/use only the standard ISO/ANSI C++.
  • Within the following questions, the term valid means: code uses standard ISO/ANSI C++, code is explicit on all typing, i.e., does not make use of default settings.
  • This course operates under the rules of the College of Engineering Honor Code. Your signature endorses the pledge below. After you finish your exam, sign your scantron sheet to indicate the statement below

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

  1. Consider the following code fragment:

int x = 18 / 5 – 5 / 2; cout << x;

What does the above code print? a) - b) 1 c) 1. d) 1. e) the above code causes a division by zero error

  1. Consider the following code fragment:

double x = 18 / 5 – 5 / 2; cout << x;

What does the above code print? a) - b) 1 c) 1. d) 1. e) the above code causes a division by zero error

  1. Consider the following code fragment:

double x = 18.0 / 5 – 5 / 2; cout << x;

What does the above code print? a) - b) 1 c) 1. d) 1. e) the above code causes a division by zero error

  1. What does the C++ expression 3 / 2 + 3 % 2 evaluate to? a) 2 b) 2. c) 3 d) none of the above
  2. Which of the following code fragments outputs the number 7 to the screen? a) cout << 2 + 3 * 4 / 2; b) cout << 2 * 3 + 4 / 2; c) cout << 2 * (3 + 4) / 2; d) cout << 2 / 3 * 4 + 2;
  1. What prints? int x = 3; foo(x); cout << x; a) 3 b) 4 c) 5 d) none of the above
  2. Given:

bool x = true; bool y = false;

Which expression evaluates to true? a) x && y b) !(x && y) c) x && y && x d) y || !x

  1. Consider the following code fragment: int x = 3; if ( ( 3 == x ) && ( x / 0 == 4 ) ) cout << ”true”; else cout << ”false”;

What does the above code print? a) false b) true c) the above code causes a division by zero error d) none of the above

  1. Consider the following code fragment:

int x = 3; if ( ( 3 == x ) || ( x / 0 == 4 ) ) cout << ”true”; else cout << ”false”;

What does the above code print? a) false b) true c) the above code causes a division by zero error d) none of the above

  1. Given: if (age < 5) { cout << "You will attend kindergarten soon." << endl; } else if (age < 10) { cout << "You are in elementary school." << endl; } else if (age < 15) { cout << "Congrats you are in middle school." << endl; } else if (age < 18) { cout << "Almost there ..." << endl; } else { cout << "Go BLUE! " << endl; }

What is the last line of the output if the age variable is 15? a) You will attend kindergarten soon. b) You are in elementary school. c) Congrats you are in middle school. d) Almost there ... e) GO BLUE!

  1. Given: if (age < 5) cout << "You will attend kindergarten soon." << endl; if (age < 10) cout << "You are in elementary school." << endl; if (age < 15) cout << "Congrats you are in middle school." << endl; if (age < 18) cout << "Almost there ..." << endl; else cout << "Go BLUE! " << endl;

What is the last line of the output if the age variable is 10? a) You will attend kindergarten soon. b) You are in elementary school. c) Congrats you are in middle school. d) Almost there ... e) GO BLUE!

  1. What does the following print? cout << "" ; //this is a comment!" a)
    b) " ; c) " ; //this is a comment! d) none of the above
  1. Given the following code fragment:

int main() { string eyeColor; string favoriteColor; eyeColor = "green"; favoriteColor = "green"; if(eyeColor == "brown" || favoriteColor == eyeColor) { printStuff("red","green"); } else if(eyeColor == "green" || favoriteColor == "green") { cout << "My favorite color and my eye color are the same." << endl; } else { cout << "GO BLUE!" << endl; } return 0; }

void printStuff(string eyeColor, string favoriteColor) { cout << "Eye Color: " << eyeColor << " " << "Favorite Color: " << favoriteColor << endl; }

What is the output? a) Eye Color: brown Favorite Color: green b) My favorite color and my eye color are the same. c) GO BLUE! d) Eye Color: red Favorite Color: green e) None of the above

  1. If the desired output is four times the input, which code fragment accomplishes this given the code below: #include using namespace std;

int f(int a, int b);

int main( ) { int x; cout<<"Enter an integer: "; cin >> x; cout << f( x, f( x, f( x, x ) ) ); return 0; }

int f(int a, int b) { [code fragment] }

What [code fragment] will print a value four times the input? For instance,

Enter an integer: 2 8

[code fragment]: a) return a * b; b) return a + b; c) return a / b; d) return a - b;