{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

quiz1

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

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

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; } };

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

View Full Document
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:
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 Ball a, b(2), c(3); a = b = c; behaves as expected? Explain your answer.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern