Study Guides (238,407)
Canada (115,131)
CS 246 (16)
Ric Holt (3)

Final + Solution of Winter 2008 useful for practice

12 Pages
Unlock Document

University of Waterloo
Computer Science
CS 246
Ric Holt

UNIVERSITY WATERLOO CS246, INTER2008 CS246 Winter 2008 Final Exam Thursday, 4 April 2008 Instructor: M. W. Godfrey Time allowed: 150 minutes No aids allowed (i.e., closed book). There are 6 questions for a total of K marks. Plan your time wisely. In the immortal words of the late Douglas Adams, dont panic! Answer all of the questions on this exam sheet. Use the blank exam booklets ONLY as scratch paper. Name: SOLUTION (Underline your last name) Student Number: (For marking purposes only) Page 1 of 12 FINALEXAM UNIVERSITY OFWATERLOO CS246, WINTER2008 1. [20 total marks] True / false For each statement, circle T (true) or F (false), or do nothing. You get 2 points for a correct answer, 0 points for no answer, and 1 for a wrong answer. However, you cannot get less than 0 on this page. You may provide a short explanatory statement to support your answer if you desire, but it is not required. T F If a method is not declared as virtual in a parent class, then its illegal to (a) override it in a child class. T F If a class embodies a aggregation relationship, then its destructor should almost (b) certainly call the destructor of all of its heap-based aggregate parts. T F If your code might encounter an exception being thrown, then you should use a (c) smart pointer class such as auto pointer to refer to stack-based objects to ensure that they dont become memory leaks. (d) T F The time complexity of performing an append onto the end of an instance of std::list is best described as amortized constant time. (e) T F An implementation-only class is one in which the constructors are public, but all other methods (esp. inherited ones) are made private. (f) T F Copying a composite involves making a deep copy of the objects structure and parts. T F Suppose class C inherits from class P, and that both provide a fully dened (g) method named m(). According to what we learned in class, the precondition of C::m() should be stronger than (or the same as) that of P::m(). (h) T F If the destructor of a class is declared as private, its likely because the designer intended for no client to create objects of that class. (i) T F In C++, std::string::operator== uses object-identity semantics as its model. (j) T F If a method is declared as virtual, then static dispatch will be used to resolve the call for an object on the stack. Page 2 of 12 FINAL EXAMUNIVERSITY OFWATERLOO CS246, W INTER2008 2.[22 total marks] Short answer (a) [2 marks] What is a memory leak? ANS: A memory leak is a dead object that was allocated on the heap but whose storage was never returned to the heap when the objects use ended. There are no longer any pointers or references to the object; it is completely inaccessible to the running program. (b) [2 marks] Consider the code below. What is the general term for this? (Im not referring to exception handling.) void f (Parent * p) { Child c = dynamic_cast(p); * * if (c==NULL) { // do something drastic, like throw an exception } else { // happily
More Less

Related notes for CS 246

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.