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