Question: Need help with this question please! I have included the relevant header dile Rectangle.h in the image below. WILL UPVOTE! Need to Implement Rectangle.cpp a.
Need help with this question please! I have included the relevant header dile Rectangle.h in the image below. WILL UPVOTE!
Need to Implement Rectangle.cpp
a. Constructor and destructor: The constructor takes four Point objects as
parameters and calls setAll() function to set them. It also displays a message
that a specific points constructor is being called.
Destructor displays a similar
message. Conform to the output formats given in the sample output below.
b. Setters and getters: implement setAll() to set all the points at once. This
function calls formRectangle(). If it returns false setAll throws an
invalid_argument exception. Otherwise it sets the data members to the
parameter values. Getters return the data member values.
c. formRectangle(): This function checks whether the given coordinates of the
points form a rectangle and returns true or false based on the resulting
calculations. The following rule must hold for four points to be a rectangle:
Given points a, b, c, d for a rectangle, opposite sides and diagonals of a
rectangle must be of equal length.
You may use the following formula to calculate the length of a side between
two points:
Length of a side between points a and b = !|a. x b. x|( + |a. y b. y|(
You may use fabs() function to get the absolute value, sqrt() function to get
the square root and pow() function to calculate exponentiation. While fabs()
and sqrt() functions accept only one argument, pow() function accepts two
arguments: base and exponent. They are all part of the cmath standard library.
Add the following to your code to use this library:
#include
d. calculateArea(): This function returns the area of the rectangle. To calculate
area, you must first calculate the length of sides of the rectangle.
e. calculatePerimeter(): This function returns the perimeter of the rectangle. To
be able to calculate that you must again calculate sides of the rectangle.
Rectangle.h #ifndef Rectangle_h #define Rectangle_h #include "Point.h" class Rectangle { public: Rectangle(Point &, Point &, Point &, Point &); Rectangle(); void setAll(Point &, Point &, Point &, Point &); Point & getPoint(); Point & getPointB(); Point & getPoint(); Point & getPointD(); double calculateArea() const; double calculatePerimenter() const; private: Point pointA; Point pointB; Point pointc; Point pointD; bool formRectangle(Point &, Point &, Point &, Point &); }; #endif /* Rectangle_h */
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
