EECS 183 Winter 2014 Exam 1
Closed Book Closed Notes Closed Electronic Devices Closed Neighbor
Turn off Your Cell Phones
We will confiscate all electronic devices that we see – including cell phones, calculators, etc.
Multiple Choice Questions
(20 questions * 5 points per question = 100 points)
Key 1
Instructions: Read Carefully!
1. You may have one personally handwritten 3 x 5 notecard.
2. Some questions are not simple, therefore, read carefully.
3. Assume all code and code fragments are syntactically valid, unless otherwise specified.
4. Assume/use only the standard C++11.
5. In all the given code, if any character looks like a space, it is one.
6. On the scantron sheet, bubble in your name and UMID -‐-‐ 10 pts off for incorrect UMID.
7. On the scantron sheet, bubble in Key 1 -‐-‐ zero on exam if key not bubbled in.
8. Sign below and print your uniqname -‐-‐ 10 pts off if we cannot read your uniqname
I have neither given nor received aid on this examination, nor have I concealed any violations of the Honor Code.
_________________________________________________________________________________________________________
1
(Intentionally left blank such that you may use if needed)
2
1
What does the following expression evaluate to?
5 / 3 * 3 A)
B)
C)
D)
2
Which of the following evaluates to an odd number?
A)
B)
C)
D)
E)
3
3 * 6 / 2 / 2
6 * 3 / 2 / 2
6 / 2 / 3 * 2
6 / 3 * 3 / 2
None of the above
Which of the following code fragments will assign the number 4.5 to variable y? A)
B)
C)
D)
E)
4
0
3
5
None of the above
double y = 2.0 + 5 % 2;
double y = 2 + 5 / 2;
double y = 2.0 + 5 / 2;
double y = 2.0 + 1.0 * 5 / 2;
double y = 2.0 + 5 / 1.0 * 2;
What does the expression 1234 / 10 / 10 % 10 evaluate to?
A)
B)
C)
D)
E)
1
2
3
4
None of the above
3
5
If the user types: 2.5 # 3.5 <enter>, what does the following code snippet output?
A)
B)
C)
D)
E)
6
5.5
6
7
7.5
None of the above
If the user types: 2.5 # 3.5 <enter>, what does the following code snippet output? (Note: this is a different question than the one above -‐-‐ really it is -‐-‐ read closely)
A)
B)
C)
D)
E)
7
double x = 3;
int y = 2;
char ch = '6';
cin >> x >> ch >> y;
cout << x * y;
double x = 3;
int y = 2;
char ch = '6';
cin >> y >> x >> ch;
cout << x * y;
0
1
2
2.5
None of the above
If the user types: Go Blue <enter>, what does the following code snippet output?
string str; getline(cin, str); cout << str;
A)
B)
C)
D)
E)
Go
Blue
G
Go Blue
None of the above
4
8
Consider the following function:
bool isCoronationDay(int num) {
if (num % 100 == 0) {
if (num % 400 == 0) {
return true;
} else {
return false;
}
} else if (num % 4 == 0) {
return true;
} else {
return false;
}
}
Which of the following test suites thoroughly test the above function by testing every path through the function?
A) 1999, 2000, 2001
B) 1899, 1900, 1901, 1902
C) 1800, 2000, 2008
D) 1900, 1930, 1960, 2000
9
What does the following line of code print?
cout << "\"//Some people are /";//"worth melting for -‐-‐ Olaf";
A)
B)
C)
D)
E)
\
"
"//Some people are /
None of the above
Compilation Error
10 Consider the following C++ function:
int oaken(int x) {
return x + 1;
}
What does the expression oaken(oaken(3)) evaluate to?
A)
B)
C)
D)
3
4
5
6
5
11 What does the following code print?
#include <iostream>
using namespace std;
int kristoff(int x);
int anna(int x);
int main() {
cout << kristoff(1) + anna(2);
return 0;
}
int kristoff(int x) {
++x;
return anna(x);
}
int anna(int x) {
x = x + 2;
return x;
}
A)
B)
C)
D)
E)
5
6
7
8
9
12 Which of the following calls to the function frozen are valid (i.e., will compile), if frozen has the function prototype: void frozen(int x, char y); A)
B)
C)
D)
E)
frozen(1, '*');
cout << frozen(1, '*');
int x = frozen(10, '*') + 3;
All of the above
A and B
6
13 What does the following C++ program print?
#include <iostream> using namespace std;
void olaf(int x, int y);
int main() {
int x = 1;
int y = 3;
olaf(x, y);
cout << x << ", " << y;
return 0;
}
void olaf(int x, int y) {
int temp = x;
x = y;
y = temp;
return;
}
A)
B)
C)
D)
1, 1
1, 3
3, 1
3, 3
14 What does the following code fragment print if the user
enters: -‐5 12<enter> int temperature, amount; cin >> temperature >> amount;
if (temperature > 0) {
if (amount >= 10) {
cout << "Build me a friend" << endl; } else {
cout << "Oh no! It's too cold to snow" << endl; }
} A) Build me a friend
B) Oh no! It's too cold to snow
C) None of the above
7
15 What does the following C++ program print?
#include <iostream> using namespace std;
int main() {
int x = 42;
if (x >= 0) {
cout << "I don't have a skull. Or bones.";
} else if (x <= 42) {
cout << "I'm Olaf and I like warm hugs.";
} else {
cout << "It's so cute. Like little baby unicorn";
}
return 0;
cout << "Oh, look at that. I've been impaled.";
}
A)
B)
C)
D)
E)
I don't have a skull. Or bones.
I'm Olaf and I like warm hugs.
It's so cute. Like little baby unicorn
Oh, look at that. I've been impaled.
It will run with no errors, but print nothing.
16 Consider the following function marshmallow:
int marshmallow(bool p, bool q) {
int x = 0;
int y = 2;
return ((x > 1) || p) && ((y < 3) || q);
}
What does the function marshmallow return?
A) 0
B) 1
C) The return value depends on the values of both p and q
D) The return value depends on the value of p but not q
E) The return value depends on the value of q but not p
8
17 What does the following code snippet print?
int x = 1; while (x < 5) { x *= x + 1; }
cout << x << " ";
A)
B)
C)
D)
E)
1
5
6
1 2 6
2 6
18 Given the following function implementation, what does bulda(5) return?
int bulda(int n) {
int i = 0;
while (i < n) {
i = i + 1;
n = n + 1;
}
return i;
}
A)
B)
C)
D)
4
5
6
Behavior is undefined -‐-‐ may or may not stop
9
19 If the user types 20 60 0 70 <enter> what does the following code print?
int x;
int sven = 0;
cin >> x;
while (x > 0) {
if (x > sven) {
sven = x;
}
cin >> x;
}
cout << sven ;
A)
B)
C)
D)
20
60
0
70
20 Which of the following is a complement of the C++ expression (temperature < 10 || temperature > 80)? A) (temperature > 10 && temperature < 80)
B) (10 <= temperature <= 80) C) (10 <= temperature && temperature <= 80)
D) (temperature >= 10 || temperature <= 80)
E) None of the above
10
© Copyright 2025 Paperzz