Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE THE MAIN PROVIDED AS THE TEST CASE. PLEASE CODE THE rectangle.hpp. PLEASE CODE IN C++ ------------------------------------------------------------------------------------ For the assignment, we will create a

PLEASE USE THE MAIN PROVIDED AS THE TEST CASE. PLEASE CODE THE rectangle.hpp. PLEASE CODE IN C++

------------------------------------------------------------------------------------

For the assignment, we will create a sophisticated Rectangle class. This class stores only the Cartesian coordinates of the four corners of the rectangle. The constructor calls a set function that accepts four sets of coordinates and verifies that each of these is in the first quadrant with no single x- or y-coordinate larger than 20.0. The set function also verifies that the supplied coordinates do, in fact, specify a rectangle.

Provide member functions that calculate the length, width, perimeter and area. The length is the larger of the two dimensions.

Include a predicate function square that determines whether the rectangle is a square.

Provide these public member functions for Rectangle that perform the following tasks:

length: return the longer side

width: return the shorter side

perimeter: return the sum of four sides

area: return the area of the rectangle.

square: return true/false

setCoord: take 4 points as parameters and set your member variables. Arrangement of points on your own, such as

p4.........p3

. .

. .

p1.........p2

Consider creating separate point objects within the Rectangle class. Consider setters and getters, among other things in this class. Consider using fabs for the side calculations.

---------------------------------------------------------------------------------------

MAIN:

#include #include #include "Rectangle.hpp" // include definition of class Rectangle

/*

Create a sophisticated Rectangle class. This class stores only the Cartesian coordinates of the four corners of the rectangle. The constructor calls a set function that accepts four sets of coordinates and verifies that each of these is in the first quadrant with no single x- or y-coordinate larger than 20.0. The set function also verifies that the supplied coordinates do, in fact, specify a rectangle.

Provide member functions that calculate the length, width, perimeter and area. The length is the larger of the two dimensions.

Include a predicate function square that determines whether the rectangle is a square. */

int main() { Point w{1.0, 1.0}; Point x{5.0, 1.0}; Point y{5.0, 3.0}; Point z{1.0, 3.0}; Point j{0.0, 0.0}; Point k{1.0, 0.0}; Point m{1.0, 1.0}; Point n{0.0, 1.0};

Rectangle r1{z, y, x, w}; std::cout << "Rectangle 1: "; std::cout << "length = " << r1.length(); std::cout << " width = " << r1.width(); r1.perimeter(); r1.area(); std::cout << " The rectangle " << (r1.square() ? "is" : "is not") << " a square. ";

Rectangle r2{j, k, m, n}; std::cout << " Rectangle 2: "; std::cout << "length = " << r2.length(); std::cout << " width = " << r2.width(); r2.perimeter(); r2.area(); std::cout << " The rectangle " << (r2.square() ? "is" : "is not") << " a square. ";

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

What are their resources?

Answered: 1 week ago