S08_midterm_key

S08_midterm_key - PIC 10C MIDTERM EXAM May 5, 2008 KEY You...

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

View Full Document Right Arrow Icon
PIC 10C MIDTERM EXAM May 5, 2008 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 10 2 8 3 7 4 25 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 the difference between a private and a protected data field? Both private and protected fields are accessible to the member functions of the class, but protected fields are accessible to any inherited classes as well. 2.) [8 points] Suppose the Manager class is derived from a base Employee class. We create two variables e and m as below: Employee e ("Homer Simpson", 22222.22); Manager m ("Waylon Smithers", 44444.44, "Accounting Department"); For each line of C++ code below, explain what happens and what data is stored. (It might give a compile error.) a.) e = m; This compiles and stores the name and salary, but any extra information in m (department) is lost. b.) m = e; Gives compile error. Cannot assign a derived class to a base class object. c.) Employee* p = &m; Works fine because the base class pointer is polymorphic. No data is lost. d.)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

S08_midterm_key - PIC 10C MIDTERM EXAM May 5, 2008 KEY You...

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

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