EECS 183 Winter 2010
Exam 1
Part 1 (78 points)
Closed Book
Closed Notes
Closed Electronic Devices
Closed Neighbor
Multiple Choice Questions
26 questions -- 3 pts each
Instructions: Read Carefully!
1. This is a closed book exam. You may not refer to any materials during 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. 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.”
Here are a number of concepts one might want to represent in a program. Help our programmer by
selecting the most appropriate data type.
1.
2.
Number of fish in your aquarium.
A) bool
B) char
D)
double
E)
string
C) int
D)
double
E)
string
The scientific name of a type of bear.
A) bool
B) char
C) int
D)
double
E)
string
Whether a person is right-handed.
A) bool
B) char
C) int
D)
double
E)
string
The number of molecules in a gram of water.
A)
3.
4.
C) int
bool
B)
char
What is the value of x as a result of the following expressions?
int x = 7 * 12 / 3 - 3 / 2;
5.
A) 26.5
B) 27
A) 26.5
B) 27
B) 7.666666
C) 26
D) 27.0
E) None of the above
C) 8.0
D) 5
E)None of the above
C) 10
D) 9
E)None of the above
int x = 7 % 3 * 2 + 8;
A) 12.66666
9.
E) None of the above
double x = 2 / 5 / 3.0 * 8 * 10 / 4 + 5;
A) 5.0
8.
D) 27.0
double x = 7 * 12 / 3 - 3 / 2;
6.
7.
C) 26
B) 12
A syntax error is signaled by which one of the following:
A) compiler
B) linker
C) operating system
D) nobody, you should catch your own syntax errors
E) the Force (may the Force be with you)
10. Which of the following code fragments will not compile? Select all choices that apply.
A)
B)
C)
D)
int
int
int
int
x; x = 7;
x = 7;
x(7);
x{7};
2
11.
If given the following:
bool x = true;
bool y = false;
Which expression is evaluated to true in the following?
A) x && y
B) !(x && y)
C) x && y && x
D) y || !x
12. Which of the following are valid function prototypes? Select all choices that apply.
A) int y = squareRoot(x);
B) int maximum(x,y);
C) int calc(void x);
D) char sign(double x);
13. Which of the following calls to the function process are valid, if process has the function
prototype: void process(char y);? Select all choices that apply.
A) process('A');
B) cout << process('A');
C) x = process('A');
D) process("A");
14. Which of the following is a complement of the C++ expression
citizen && age >= 18
Recall that if a boolean expression is true, its complement is false and vice versa.
A)
B)
C)
D)
!citizen
!citizen && age < 18
!citizen || age < 18
none of the above
15. What prints?
int x,z;
char y;
cin >> x >>
cout << x +
y >> z;
z << endl;
If the user types 3.5 + 3.5 and presses return at the standard input, what does the above code
fragment print? Note that there is a white space before and after + (with the input).
A) 5
B) 6
C) 7
D) 8
3
16. What prints?
string x,y,z;
cin >> x >> y >>
cout << x << endl;
z;
If the user types 3.5 + 3.5 and presses return at the standard input, what does the above code
fragment print? Note that there is a white space before and after + (with the input).
A) x
B) 3.5
C) 3.5 + 3.5
D) 7
E) none of the above
17. Consider the following code fragment:
if ((3 == 4) && (3 /0 == 4))
cout << "true" << endl;
else
cout << "false" << endl;
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
18. What prints?
#include<iostream>
using namespace std;
int main()
{
int x = 0;
if(x=0)
cout << "false" << endl;
else
cout << "true" << endl;
return 0;
}
A) false
B) true
C) the above code causes a division by zero error
D) none of the above
4
19. What prints? (no it isn't the same question as above)
#include<iostream>
using namespace std;
int main()
{
int x = 0;
if(x==0)
cout << "false" << endl;
else
cout << "true" << endl;
return 0;
}
A) false
B) true
C) the above code causes a division by zero error
D) none of the above
20. What is the 1st line printed?
#include<iostream>
using namespace std;
int main()
{
int today = 10, examday = 10;
bool i_studied = false;
if(i_studied)
if(today == examday)
cout << "I'll do fine \n";
else cout << "I should have studied and not read blogs!\n ";
cout << "Thank You, Stroustrup!\n";
return 0;
}
A)
B)
C)
D)
I'll do fine
I should have studied and not read blogs!
Thank You, Stroustrup
none of the above
5
21.
Given the code below what is the value of y that will be printed.
#include <iostream>
using namespace std;
int f( int x );
int main( )
{
int x = 5;
int y = f( x);
cout << y << endl;
return 0;
}
int f(int x)
{
return x-1;
}
What value of y is printed:
A) 6
B) 5
C) 4
D) none of the above
22. What prints?
int count
= 4;
while(count < 9)
{
if(count%2)
cout << "Hip-" ;
count = count+3;
}
cout << "Hurray!";
A)
B)
C)
D)
E)
HipHurray!
Hip-Hurray!
Hip-Hip-Hurray!
None of the above
6
23.
Given the code fragment below, what is printed?
int main( )
{
int x = 5, y = 15;
cout << x << " " << y << " ";
showVals(x, y);
return 0;
}
void showVals (int y, int x)
{
cout << x << " " << y << "
}
A)
B)
C)
D)
E)
24.
";
5 15 5 15
5 15 15 5
neither of the above
compile error
GO BLUE
Given the code fragment below, what is printed?
int main()
{
int x = 5, y = 15;
cout << x << " " << y << "
showVals(x, y);
return 0;
}
void showVals (int a, int b)
{
cout << x << " " << y << "
}
A)
B)
C)
D)
E)
";
";
5 15 5 15
5 15 15 5
neither of the above
compile error
GO BLUE!
7
25. Consider the following C++ function:
int f(int x)
{
return x+1;
}
What does the C++ expression f(f(3)) evaluate to?
A) 3
B) 4
C) 5
D) 6
26. For this question consider yourself a rabbit caretaker. You need to purchase bundles of carrots
for the rabbits. There are two types of rabbits: grey and spotted. Each grey rabbit needs 2 carrots
and each spotted rabbit needs 3 carrots. Each bundle contains 4 carrots. Choose which code
fragment will purchase the minimum number of bundles such that all of the rabbits can eat. Here
ceil is the ceiling function which rounds a number up to the nearest integer and floor is the
floor function which rounds a number down to the nearest integer.
#include <iostream>
#include <cmath>
using namespace std;
int requiredBundles(int grey, int spotted);
int main( )
{
int grey;
int spotted;
cout << "Enter the number of grey rabbits: ";
cin >> grey;
cout << "Enter the number of spotted rabbits: ";
cin >> spotted;
cout << " Bundles of carrots: "
<< requiredBundles( grey, spotted) << endl;
return 0;
}
int requiredBundles(int grey, int spotted)
{
[code fragment]
}
Choose the correct code fragment:
A) return static_cast<int>(ceil((2.0 * grey + 3.0 * spotted)/4.0));
B) return static_cast<int>(ceil((3.0 * grey + 2.0 * spotted)/4.0));
C) return static_cast<int>(floor((2.0 * grey + 3.0 * spotted)/4.0));
D) return static_cast<int>(floor((3.0 * grey + 2.0 * spotted)/4.0);
8
9
© Copyright 2026 Paperzz