quiz1 - Name: 1.124 Quiz 1 Time: 1 hour 15 minutes Answer...

Info iconThis preview shows pages 1–4. 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
Question 1. Show how you would initialize the member pi in class Ball . Answer: Question 2. Write the copy constructor for class Ball . Answer: Question 3. Show how you would overload the += operator, so that the following code increments the radius of b by 2. Ball b; b += 2; Answer:
Background image of page 2
Question 4. Complete the definition of the member function set_radius() . void Ball::set_radius(int radius) { Answer: } Question 5. What should the = operator return so that the code
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.

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 - Name: 1.124 Quiz 1 Time: 1 hour 15 minutes Answer...

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