quiz1_solutions

quiz1_solutions - Name: 1.124 Quiz 1 Time: 1 hour 15...

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

View Full Document Right Arrow Icon
Name: 1.124 Quiz 1 Thursday October 5, 2000 Time: 1 hour 15 minutes Answer all questions. All questions carry equal marks. #include <iostream.h> class Ball { private: const float pi; int radius; public: Ball(int r=1) { radius = r; } void set_radius(int radius); const Ball& operator=(const Ball& b); static int count; virtual void print() { cout << radius << endl; } }; int Ball::count = 0; class BuckyBall: public Ball { private: int color; public: BuckyBall(int radius, int c) { color = c; } void print() { cout << color << endl; } };
Background image of page 1

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

View Full DocumentRight Arrow Icon
Show how you would initialize the member pi in class Ball . ) : pi(3.14159f) { radius = r; } Answer: Use an initialization list in the constructor: Ball(int r=1 Question 2. Write the copy constructor for class Ball . Within the public part of the Ball ) : pi(b.pi) { radius = b.radius; } Answer: class declaration: Question 3. Show how you would overload the += operator, so that the following code increments the radius of b by 2. Ball b;
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.

This note was uploaded on 12/04/2011 for the course ESD 1.124 taught by Professor Kevinamaratunga during the Fall '00 term at MIT.

Page1 / 6

quiz1_solutions - Name: 1.124 Quiz 1 Time: 1 hour 15...

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