#include<iostream>
#include<fstream>
#include<cmath>
#include "quadrilateral.h"
using namespace std;
void Quadrilateral::validate()
{
Quadrilateral p1, p2, p3, p4;
if(p1.x < p2.x && p1.y == p2.y && p4.x < p3.x && p4.y == p3.y)
{
a = p1;
b = p2;
c = p3;
d = p4;
}
else
{
cout << "Incorrect order. Here are the coordinates";
cout << " in the correct order:" << endl;
Quadrilateral();
}
}
Quadrilateral::Quadrilateral()
{
a = Point(-1,-1);
b = Point(3,0);
c = Point(2,2);
d = Point(1,1);
}
Quadrilateral::Quadrilateral(Point &p1, Point &p2, Point &p3, Point &p4)
{
SetAll(p1,p2,p3,p4);
validate();
}
void Quadrilateral::SetA(Point &p1)
{
a = p1;
return;
}
void Quadrilateral::SetB(Point &p2)
{
b = p2;
return;
}
void Quadrilateral::SetC(Point &p3)
{
c = p3;
return;
}
void Quadrilateral::SetD(Point &p4)
{
d = p4;
return;
}
void Quadrilateral::SetAll(Point &p1, Point &p2, Point &p3, Point &p4)
{
a = p1;
b = p2;
c = p3;
d = p4;
validate();
return;
}
Point Quadrilateral::GetA(void) const
{
return a;
}
Point Quadrilateral::GetB(void) const
{
return b;
}
Point Quadrilateral::GetC(void) const
{
return c;
}
Point Quadrilateral::GetD(void) const
{
return d;
}
double Quadrilateral::Perimeter()
{
double side1 = a.Distance(b);
double side2 = b.Distance(c);
double side3 = c.Distance(d);
double side4 = d.Distance(a);
return(side1 + side2 + side3 + side4);
}
double Quadrilateral::Area()
{
double side1 = a.Distance(b);
double side2 = b.Distance(c);
double side3 = c.Distance(a);
double side4 = c.Distance(d);
double side5 = d.Distance(a);
double semi1 = (side1 + side2 + side3)/2;
double semi2 = (side3 + side4 + side5)/2;
double area1 = sqrt(semi1 * (semi1 - side1) *
(semi1 - side2) * (semi1 - side3));
double area2 = sqrt(semi2 * (semi2 - side3) * (semi2 - side4)
* (semi2 - side5));
return(area1 + area2);
}
void Quadrilateral::Print()
{
Quadrilateral p1, p2, p3, p4;
cout << "I'm a Quadrilateral" << end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