Preview

Cs 125 Midterm 1 FA 2012 Solutions

Good Essays
Open Document
Open Document
775 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Cs 125 Midterm 1 FA 2012 Solutions
If you feel confident, please change the answers to what you think is right, otherwise, xuse Ctrl­Alt­M to comment.
0125
All coding questions are on the codeshare link.
Multiple Choice
1.
d is correct
// d) derefrencing garbage? ie no memory actually allocated //
2.
c) // d) neither winner() nor loser() can make the assignment
//I think 2 is c, because it is a virtual function but not a pure virtual function, so we can call it from the base class
3.
c) an insidious runtime memory error CAN SOMEONE EXPLAIN WHY because compiler doesn’t know that b’s memory is freed before the code is actually running. so it has to be a runtime error. dereferencing to NULL always results in a runtime error
4.
a) This code is horrible because it returns the memory address of a local variable
5.
c) 15 is sent to standard out //d) spring09 MC3 has a similar question, check?
//it should be 15, I ran the code.
6.
c) Growl Run! Stomp stomp stomp ­ Just got word from a TA that by calling Bear beary;, we are initializing beary using the default constructor CAN SOMEONE
EXPLAIN HOW STOMP STOMP STOMP PRINTS? My guess is that Stomp stomp stomp prints because beary goes out of scope and needs to be deleted, so the destructor is called
7.
b) operator= ­ must be set sbased on
Rule of 3 Shouldn’t a no parameter constructor need to be implemented? Otherwise you’d never be able to actually create an object of that class
8.
c) 9.
d) Parts a and b cause compile errors because the create modPNG’s// What’s wrong with (a) though? Calling a constructor of an abstract base class is not allowed (there is nothing to initialize).
//you can’t do “modPNG a” since it is an abstract base class since it has a pure virtual function. // You can’t create an object from an abstract class but you can create a ptr to point to a derived class.
10.
e) //a) animal class has no constructor that only take 1 param? I think it’s a. Question 2
a)

You May Also Find These Documents Helpful