Lab4 Objects
Lab4 Objects
Exercise 1a - Rectangle
Let’s say you need to write a program that enables you to calculate
the area of a rectangle, and there is already a Rectangle class
defined for you. The attribute and behaviour of objects of this
class is described in the following table.
Rectangle Description
- height : int •Height of rectangle
- width : int •Width of rectangle
+ Rectangle(h : int, w: int) •Create rectangle with given values of height
and width
You only need to write a client program that will interact with objects
of this class.
How do you write your program?
Exercise 1b - Rectangle
Given the complete class interface of Rectangle is as follows:
Rectangle Description
- height : int •Height of rectangle
- width : int •Width of rectangle
+Rectangle() Create a Rectangle with height& height = 0
+ Rectangle(h : int, w: int) Create rectangle with given values of height and
width
+ setHeight(h : int) : void Set the height to the given value