1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
// A Sophisticated Rectangle Class
#include <iostream>
#include <stdexcept>
#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:\n";
std::cout << "length = " << r1.length();
std::cout << "\nwidth = " << r1.width();
r1.perimeter();
r1.area();
std::cout << "\nThe rectangle "
<< (r1.square() ? "is" : "is not")
<< " a square.\n";
Rectangle r2{j, k, m, n};
std::cout << "\nRectangle 2:\n";
std::cout << "length = " << r2.length();
std::cout << "\nwidth = " << r2.width();
r2.perimeter();
r2.area();
std::cout << "\nThe rectangle "
<< (r2.square() ? "is" : "is not")
<< " a square.\n";
}
|