





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 9
This page cannot be seen from the preview
Don't miss anything!






The University of Michigan
Professor ML Dorf Professor E Soloway Wednesday October 6, 2010 6 :00 to 7 :30 pm
I have neither given nor received aid on this examination, nor have I concealed any violations of the Honor Code.
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
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
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
bool x = true; bool y = false;
Which expression evaluates to true? a) x && y b) !(x && y) c) x && y && x d) y || !x
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
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
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!
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!
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
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;