#include<iostream>
#include<cmath>
#include "quadrilateral.h"
#include "trapezoid.h"
#include "parallelogram.h"
#include "rectangle.h"
#include "square.h"
using namespace std;
bool Equals(double xVal, double yVal)
{
const double epsilon = 10e-10;
if(abs(xVal - yVal) <= epsilon * abs(xVal))
{
return true;
}
return false;
}
int main()
{
double a1, a2, b1, b2, c1, c2, dx, dy, p1, p2, q1, q2, r1, r2, t1, t2;
Point a, b, c, d, p, q, r, t;
Quadrilateral quad;
Trapezoid trap;
Parallelogram par;
Rectangle rect;
Square sq;
int number;
//Point a(-4,-1), b(4,-1), c(4,7), d(-4,7);
double s1 = b.Slope(a), s2 = c.Slope(b), s3 = d.Slope(c), s4 = a.Slope(d);
double d1 = a.Distance(b), d2 = b.Distance(c), d3 = c.Distance(b);
double d4 = d.Distance(a);
/*cout << "Test for Point" << endl;
cout << "------------------" << endl;
cout << "Enter the coordinates for point p: ";
cin >> p1 >> p2;
p.SetAll(p1,p2);
cout << "Enter the coordinates for point q: ";
cin >> q1 >> q2;
q.SetAll(q1,q2);
cout << "Enter the coordinates for point r: ";
cin >> r1 >> r2;
r.SetAll(r1,r2);
cout << "Enter the coordinates for point t: ";
cin >> t1 >> t2;
t.SetAll(t1,t2);
cout << "Point p: " << "(" << p.GetX() << "," << p.GetY() << ")" << endl;
cout << "Point q: " << "(" << q.GetX() << "," << q.GetY() << ")" << endl;
cout << "Point r: " << "(" << r.GetX() << "," << r.GetY() << ")" << endl;
cout << "Point t: " << "(" << t.GetX() << "," << t.GetY() << ")" << endl;
cout << "Slope: " << q.Slope(p) << endl;
cout << "Distance: " << p.Distance(q) << endl;
cout << endl;
if(q.Slope(p) == t.Slope(r))
{
cout << "Two lines are parallel lines" << endl;
}
else if((((q.Slope(p)) * -(r.Slope(q))) == -1)
|| (((q.Slope(p)) == UNDEFINED && (r.Slope(q)) == 0)
|| ((r.Slope(q)) == UNDEFINED && (q.Slope(p)) == 0)))
{
cout << "Two lines are perpendicular" << endl;
}
cout << endl;*/
cout << "Test for different shapes" << endl;
cout << "---------------------------" << endl;
cout << "Enter the coordinates for the first point: ";
cin >> a1 >> a2;
cout << "Enter the coordinates for the second point: ";
cin >> b1 >> b2;
cout << "Enter the coordinates for the third point: ";
cin >> c1 >> c2;
cout << "Enter the coordinates for the fourth point: ";
cin >> dx >> dy;
quad.SetAll(a, b, c, d);
trap.SetAll(a, b, c, d);
par.SetAll(a, b, c, d);
rect.SetAll(a, b, c, d);
sq.SetAll(a, b, c, d);
cout << "Enter 0 for quadrilateral, 1 for trapezoid," << endl;
cout << "2 for paralleogram, 3 for rectangle, or 4 for square: ";
cin >> number;
if(number == 0)
{
quad.Print();
cout << "Perimeter of quadrilateral: " << quad.Perimeter() << endl;
cout << "Area of quadrilateral: " << quad.Area() << endl;
}
else if(number == 1)
{
trap.Print();
if(Equals(s1,s3))
{
cout << "Perimeter of trapezoid: " << trap.Perimeter() << endl;
cout << "Area of trapezoid: " << trap.Area() << endl;
}
else
{
cout << "The lines are not parallel." << endl;
}
}
else if(number == 2)
{
par.Print();
if(Equals(s1,s3) && Equals(s2,s4) && Equals(d1,d3) && Equals(d2,d4))
{
cout << "Perimeter of parallelogram: " << par.Perimeter() << endl;
cout << "Area of parallelogram: " << par.Area() << endl;
}
else
{
cout << "The lines are not parallel or the sides" << endl;
cout << "are not the same length." << endl;
}
}
else if(number == 3)
{
rect.Print();
if(Equals(s1,s3) && Equals(s2,s4) && Equals(d1,d3) && Equals(d2,d4)
&& (((s1 * -s2) == -1) || ((s1 == UNDEFINED && s2 == 0)
|| (s2 == UNDEFINED && s1 == 0))) && (((s2 * -s3) == -1)
|| ((s2 == UNDEFINED && s3 == 0) || (s3 == UNDEFINED && s2 == 0)))
&& (((s3 * -s4) == -1) || ((s3 == UNDEFINED && s4 == 0)
|| (s4 == UNDEFINED && s3 == 0))) && (((s4 * -s1) == -1)
|| ((s4 == UNDEFINED && s1 == 0) || (s1 == UNDEFINED && s4 == 0))))
{
cout << "Perimeter of rectangle: " << rect.Perimeter() << endl;
cout << "Area of rectangle: " << rect.Area() << endl;
}
else
{
cout << "The lines are not parallel or the" << endl;
cout << "sides are not the same length to the opposites." << endl;
}
}
else if(number == 4)
{
sq.Print();
if(Equals(s1,s3) && Equals(s2,s4) && Equals(d1,d2) && Equals(d1,d3)
&& Equals(d1,d4) && Equals(d2,d3) && Equals(d2,d4) && Equals(d3,d4)
&& (((s1 * -s2) == -1) || ((s1 == UNDEFINED && s2 == 0)
|| (s2 == UNDEFINED && s1 == 0))) && (((s2 * -s3) == -1)
|| ((s2 == UNDEFINED && s3 == 0) || (s3 == UNDEFINED && s2 == 0)))
&& (((s3 * -s4) == -1) || ((s3 == UNDEFINED && s4 == 0)
|| (s4 == UNDEFINED && s3 == 0))) && (((s4 * -s1) == -1)
|| ((s4 == UNDEFINED && s1 == 0) || (s1 == UNDEFINED && s4 == 0))))
{
cout << "Perimeter of square: " << sq.Perimeter() << endl;
cout << "Area of square: " << sq.Area() << endl;
}
else
{
cout << "The lines are not parallel or the sides" << endl;
cout << "are not the same length to each other." << endl;
}
}
else
{
cout << "There was an error for input." << endl;
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNtYXRoPgojaW5jbHVkZSAicXVhZHJpbGF0ZXJhbC5oIgojaW5jbHVkZSAidHJhcGV6b2lkLmgiCiNpbmNsdWRlICJwYXJhbGxlbG9ncmFtLmgiCiNpbmNsdWRlICJyZWN0YW5nbGUuaCIKI2luY2x1ZGUgInNxdWFyZS5oIgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKYm9vbCBFcXVhbHMoZG91YmxlIHhWYWwsIGRvdWJsZSB5VmFsKQp7Cgljb25zdCBkb3VibGUgZXBzaWxvbiA9IDEwZS0xMDsKCWlmKGFicyh4VmFsIC0geVZhbCkgPD0gZXBzaWxvbiAqIGFicyh4VmFsKSkKCXsKCQlyZXR1cm4gdHJ1ZTsKCX0KCXJldHVybiBmYWxzZTsKfQoKaW50IG1haW4oKQp7Cglkb3VibGUg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