S10_midterm_key

S10_midterm_key - PIC 10C MIDTERM EXAM May 3, 2010 KEY You...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
PIC 10C MIDTERM EXAM May 3, 2010 KEY You have 50 minutes to complete this exam. You are allowed to use notes, your book, and any resources on the internet. Show all work. Incomplete, illegible, or unintelligible answers may receive no credit. There are a total of 50 points on this exam. PAGE POSSIBLE POINTS SCORE 1 6 2 9 3 9 4 6 5 20 TOTAL 50
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1 WRITTEN PART 1.) [2 points] What is a virtual function and when is it used? When a member function in a base class is declared as virtual, the program will first look for a member function with the same name in the derived class. We use this when we want to force the usage of a more specific version of a function. 2.) [2 points] When is it appropriate to make a variable protected rather than private? We make the variables protected if we want them directly accessible by member functions of derived classes. 3.) [2 points] What is meant by upcasting and downcasting? Are both operations valid in C++? Upcasting is converting an object in the derived class to an instance of the base class. This is valid in C++, but we lose any extra information that was in the derived class but not in the base class. Downcasting converts a base class object to the derived class. This is generally not a valid operation in C++, unless it is done carefully through pointers.
Background image of page 2
2 4.) [6 points] Write a single line of C++ code that accomplishes the following task. You may use the <algorithm> library and the STL constainers. a.) Print the number of times 42 occurs in a queue Q of integers. cout << count (Q.begin(), Q.end(), 42);
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

S10_midterm_key - PIC 10C MIDTERM EXAM May 3, 2010 KEY You...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online