{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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; } };
Image of page 1

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

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

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern