Second Worksheet: Classes
- Add a default constructor to your Rectangle class that
initializes the length to 1 and the width to 1.
- Add a constructor to your Rectangle class that has two float
parms. The constructor will initialize the length to the value
given in the first parm, and the width to the value given in
the second parm.
- Add a member function sameArea that has one parm of type
Rectangle. sameArea returns true if the two Rectangles have
the same area, and returns false if they don't.
- Write client code to create one Rectangle object which
is not initialized, and another Rectangle object
which is initialized to have length 4 and width 3.
Display each Rectangle and its area and perimeter.
Check whether the two Rectangles have the same area and
print a message indicating the result.
Set the length and width of the first rectangle to
2 and 6.
Display each Rectangle and its area and perimeter again.
Again, check whether the two Rectangles have the same area and
print a message indicating the result.
- Modify your constructors so they are inline functions.
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2006