//* Grouping data in classes *

#include <iostream> #include <cmath> using namespace std; class Point { public: double x, y; }; double sqr(double x); double DIST(Point a, Point b); double AREA(double a, double b, double c); double TRIA(Point x, Point y, Point z); int main() { cout << "Please enter the coordinates of the triangle vertices and press ENTER." << endl; Point p1, p2, p3; cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y; double area=TRIA(p1, p2, p3); cout << "The area of the triangle is " << area << endl; return(0); } double sqr(double x) { return(x*x); } double DIST(Point a, Point b) { return( sqrt( sqr(a.x-b.x)+sqr(a.y-b.y) ) ); } double AREA(double a, double b, double c) { // Hero's formula for the triangle area double p=(a+b+c)/2.0; double ar=sqrt(p*(p-a)*(p-b)*(p-c)); return(ar); } double TRIA(Point x, Point y, Point z) { double leg1=DIST(x,y); double leg2=DIST(x,z); double leg3=DIST(y,z); double area=AREA(leg1, leg2, leg3); return(area); }