Working with Advanced Functions 327
10
Exercises ........................................................................................................
- Write a SimpleCircleclass declaration (only) with one member variable:
itsRadius. Include a default constructor, a destructor, and accessor methods for
radius. - Using the class you created in Exercise 1, write the implementation of the default
constructor, initializing itsRadiuswith the value^5. Do this within the initializa-
tion phase of the constructor and not within the body. - Using the same class, add a second constructor that takes a value as its parameter
and assigns that value to itsRadius. - Create a prefix and postfix increment operator for your SimpleCircleclass that
increments itsRadius. - Change SimpleCircleto store itsRadiuson the free store, and fix the existing
methods. - Provide a copy constructor for SimpleCircle.
- Provide an assignment operator for SimpleCircle.
- Write a program that creates two SimpleCircleobjects. Use the default construc-
tor on one and instantiate the other with the value 9. Call the increment operator on
each and then print their values. Finally, assign the second to the first and print its
values. - BUG BUSTERS:What is wrong with this implementation of the assignment oper-
ator?
SQUARE SQUARE ::operator=(const SQUARE & rhs)
{
itsSide = new int;
itsSide = rhs.GetSide();
return this;
}
10.BUG BUSTERS:What is wrong with this implementation of the addition
operator?
VeryShort VeryShort::operator+ (const VeryShort& rhs)
{
itsVal += rhs.GetItsVal();
return *this;
}