Description
Full Marks: 40
You are given with a partial implementation of three classes: Point2D, Circle, and Rectangle in your homework 1. Extend the implementation according to the following instructions. Note that the numbers inside brackets specify the marks allotted to each task.
Point2D: [8 Marks]
– Let, = ( , ) and = ( , ) be two points. Overload the following operators according to their definitions given:
Operator Type Expression Expression output
+ Binary + A new point = ( , ) where
= + and = + . This
operation represents a translation of the point by the amount specified by
* Binary ∗
where is a real number A new point = ( , ) where = ∗
and = ∗ . This operation represents a scaling of the point by the amount . The scaling is done with respect to the origin (0,0).
== Binary == TRUE (Boolean) if both points have same coordinates; otherwise FALSE
!= Binary ! = TRUE (Boolean) if the points are different; otherwise FALSE
Circle: [20 Marks]
-Let, and be two circles having centers and and radiuses and . Overload the following operators according to their definitions given:
Operator Type Expression Expression output
+ Binary + where is a 2D point. A new circle whose center is translated by the amount specified by the point . This operation represents a translation of the circle with respect to the origin (0,0).
* Binary ∗
where is a real number A new circle whose radius and center is scaled by the amount . This operation represents a scaling operation for the circle with respect to the origin (0,0).
+ binary + A new circle whose center is the
Homework prepared by Sukarna Barua, Asst. Professor, CSE, BUET
weighted average ∗ + ∗ (1 − ) and radius is + .
where = /( + )
– Binary − A new circle whose center is the
weighted average ∗ + ∗ (1 − ) and radius is − .
where = /( + )
== Binary == TRUE (Boolean) if both circles are of equal area; otherwise FALSE
> Binary > TRUE (Boolean) if the area of is larger than the area of ; otherwise FALSE
>= Binary >= TRUE (Boolean) if the area of is larger than or equal to the area of ; otherwise FALSE
< Binary < TRUE (Boolean) if the area of is smaller than the area of ; otherwise FALSE
<= Binary <= TRUE (Boolean) if the area of is smaller than or equal to the area of ; otherwise FALSE
++ Unary + +
+ + Increments of radius of by 1 unit. Should support both prefix and postfix version.
Rectangle: [6 Marks]
-Let, and be rectangles. Overload the following operators according to their definitions given:
Operator Type Expression Expression output
+ Binary + where is a 2D point. A new rectangle translated by point . This operation represents a translation of the rectangle with respect to the origin (0,0).
* Binary ∗
where is a real number A new rectangle whose points are scaled by the amount . This operation represents a scaling operation for the rectangle with respect to the origin (0,0).
Main: [6 Marks]
-Create suitable examples to demonstrate all functionalities as specified in the cpp file.
More practice: [For online]
-Extend your program to include facilities for other geometric objects such as square, triangle, ellipse, etc.
Homework prepared by Sukarna Barua, Asst. Professor, CSE, BUET
Reviews
There are no reviews yet.