HW6 - 152114002: Object Oriented Programming I, Spring 2010...

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

View Full Document Right Arrow Icon
152114002: Object Oriented Programming I, Spring 2010 1 HOMEWORK 6: Due: May 13, 2010, at 1:00pm 1. Mark the lines in main() that will not compile. Explain. What values will be printed by the other cout statements of this program? #include <iostream> using namespace std; class Base{ private: int i; protected: int j; int get_i() { return i;} public: int k; Base() {i=2; j=4; k=6;} }; class Der1: public Base{ public: Der1(){k = 17;} int getI() {return get_i();} }; class Der2: public Der1{ public: Der2(){k = 15;} }; int main() { Base b; Der1 d1; Der2 d2; cout << b.i << endl; cout << b.j << endl; cout << b.k << endl; cout << b.get_i(); cout << endl; cout << d1.i << endl; cout << d1.j << endl; cout << d1.k << endl; cout << d1.get_i(); cout << endl; cout << d1.getI(); cout << endl; cout << d2.i << endl; cout << d2.j << endl; cout << d2.k << endl; cout << d2.getI(); cout << endl; return 0; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
152114002: Object Oriented Programming I, Spring 2010 2 2. Show the output of the following programs and explain the each statement in main. (a)
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 / 3

HW6 - 152114002: Object Oriented Programming I, Spring 2010...

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