1) Suppose a whole bunch of monkeys line up and throw poo at a rhino
from the trees. What should the
rhino do?
2) The function main returns an int. Write a line of code that
ends main and returns the value '12'.
3) Suppose I want to say the line below. Which file should I
include?
assert(a > 0 &&
1/a > 0);
4) (Yes/No) Is there any possibility of getting a 'divide-by-zero'
error on the assert line above?
5) What will the line below print. Be VERY PICKY and put ONE CHAR
per blank space.
cout <<
"\"Hello\"\nworld\n";
_ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _
6) What is the value of 'a' after this code runs? What is the
type of 'a'?
double a = 1/2+3/4+5/6+7;
value _____________________
type _____________________
7) How do Rhinos make babies
A very large stork
Behind closed doors
Rhinos come onto the planet
fully grown
9) Assuming that c is a char, i is an int, d is a double, s is a short
and f is a float, which of the
lines below will compile as written?
c =
i; i =
c;
d = i;
d =
i; i =
f;
d = f;
f =
i; i =
s;
d = c;
10) Recall the fraction object we worked on in class. Given that
class, will the following lines of code
compile?
Fraction f;
f = (Fraction)1.2;
11) How many bytes are needed to store the string "12345"?
a) Five
b) Some other number
12) How closely are rhinos and triceratops related?
Very, they are both horned grazers animals way too
large for a preditor to eat.
Not, birds are more closely related to tricaratops
than rhinos.
13) I want to read a single char from cin. Which of these lines
should work?
char c = cin.get();
char c = cin.getch();
char c = cin.getchar();
char c; cin >> c;
14) (Word/Line/File) Consider the code below. Does the loop
iterate once per word, per line, or per file?
char buffer[100];
while (cin >> buffer) {
cout << "I'm
iterating\n";
}
15) Write me a line of code that prints the number contained in thre
variable 'a' to the stream cin. It
should also print 'coconuts' starting on the 12th space.
Sample output might be "12.4567 coconuts". Note
that output has 4 spaces. Also note that 'a' contains
a random floating point value.
16) You have a file already opened for input. Unfortunately for
you the Venusians are launching
antimatter bombs. Luckily your computer is in a Martian built
shielded. Unluckily the file resides on a
hard drive without shielding. Write code that prints "Dang Venus"
if and only if the file stream is no
longer available for reading.
17) Which of the following lines of code will compile. Assume
that i is a pointer to int, c is a pointer
to char and d is a pointer to double.
i =
c;
i =
*i;
*d = *c;
i =
d;
c =
*c;
*d= *i;
c =
d;
d =
*d;
*d = *d;
18) At the end of this code, where does 'p' point?
char *c = new char[10];
int *p = (int *)c;
p = p + 10;
19) Back before Columbus, why were there no rhinos in the New World?
Ancient humans hunted them
to extinction
Rhinos have no denfense
against wolves
A complete inabilty to swim
major oceans
20) Write me a signature for the function operator+ of the class Rhino
as invoked below.
Rhino r1,r2,r3;
r3 = r1 + r2;
21) (Rhino/Hippo) Which has a larger large intestine, a rhino or a
hippo?
22) (Yes/No) Does C++ give you a default operator=?
23) (Yes/No) Does C++ give you a default no argument contructor?
24) What is the difference between a deep and a shallow copy?
25) I have a class Time, which stores things in hours-minutes-seconds
format. How many function
invocations might happen in the the lines below?
Min _____________
Max ____________
Time t1(1,2,3);
Time t2(6,7,8);
Time t3;
t3 = t1 - t2;
26) The variable 'r' is a Rhine and 'a' is an Animal. Rhino
inherits from Animal. Which of the lines
below should compile.
r = a;
a = r;
27) Suppose I want to add an element to an unordered linked list
containing a bazillion elements. How
long will this take
About a bazillion time units
About half a bazillion time
units
About sqrt(bazillion) time
units
About log(bazillion) time
unites
Dang quick
28) Suppose I want to binary search for an element in a bazillion sized
array. How long will this take.
About a bazillion time units
About half a bazillion time
units
About sqrt(bazillion) time
units
About log(bazillion) time
unites
Dang quick
29) (Yes/No) Can one reasonably binary search on an ordered linked list?
30) Why don't rhinos fly in planes?
Weight
Inadaquate bathroom
facilities for rhino special needs
Difficult to start the
engines without fingers