#include<iostream>
#include<cmath>
#include "trapezoid.h"
using namespace std;
Trapezoid::Trapezoid():Quadrilateral()
{
a = Point(1,1);
b = Point(6,1);
c = Point(5,4);
d = Point(2,4);
}
Trapezoid::Trapezoid(Point &p1, Point &p2, Point &p3, Point &p4):
Quadrilateral(p1,p2,p3,p4)
{
validate();
}
void Trapezoid::SetAll(Point &p1, Point &p2, Point &p3, Point &p4)
{
Quadrilateral::SetAll(p1,p2,p3,p4);
validate();
}
double Trapezoid::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 Trapezoid::Area()
{
double side1 = a.Distance(b);
double side2 = b.Distance(c);
double side3 = c.Distance(d);
double side4 = d.Distance(a);
double shortLeg = (side1 - side3)/2;
double height = sqrt((side2 * side2) - (shortLeg * shortLeg));
return((height * (side1 + side3))/2);
}
void Trapezoid::Print()
{
cout << "I'm a Trapezoid" << endl;
Quadrilateral::Print();
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNtYXRoPgojaW5jbHVkZSAidHJhcGV6b2lkLmgiCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpUcmFwZXpvaWQ6OlRyYXBlem9pZCgpOlF1YWRyaWxhdGVyYWwoKQp7CglhID0gUG9pbnQoMSwxKTsKCWIgPSBQb2ludCg2LDEpOwoJYyA9IFBvaW50KDUsNCk7CglkID0gUG9pbnQoMiw0KTsKfQoKVHJhcGV6b2lkOjpUcmFwZXpvaWQoUG9pbnQgJnAxLCBQb2ludCAmcDIsIFBvaW50ICZwMywgUG9pbnQgJnA0KToKCQkJUXVhZHJpbGF0ZXJhbChwMSxwMixwMyxwNCkKewoJdmFsaWRhdGUoKTsKfQoKdm9pZCBUcmFwZXpvaWQ6OlNldEFsbChQb2ludCAmcDEsIFBvaW50ICZwMiwgUG9pbnQgJnAzLCBQb2ludCAmcDQpCnsKCVF1YWRyaWxhdGVyYWw6O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