Create a class called Point which can be used to set and get a point (x, y) on a X-Y coordinator. Write a program to let your client set any three points to define a triangle on the X-Y plane and determine:-
1. what type of triangle formed by client’s three points, e.g. right angle triangle, isosceles triangle and equilateral triangle,
2. whether the three points are collinear (three points are on the same line),
3. area of the triangle if the three points are not collinear.
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
class point
{
private:
int x, y;
public:
point(){}
point(int tx, int ty){x=tx;y=ty;}
int getx(){return x;}
int gety(){return y;}
};
void main()
{
point pointer;
int tempX,tempY;
double a, b, c, s, area;
cout<<"Enter the x coordinator for 1st point";
cin>>tempX;
cout<<"Enter the y coordinator for 1st point";
cin>>tempY;
point p(tempX,tempY);
cout<<"\nEnter the x coordinator for 2nd point";
cin>>tempX;
cout<<"Enter the y coordinator for 2nd point";
cin>>tempY;
point p1(tempX,tempY);
cout<<"\nEnter the x coordinator for 3rd point";
cin>>tempX;
cout<<"Enter the y coordinator for 3rd point";
cin>>tempY;
point p2(tempX,tempY);
if(p.getx()==p1.getx() && p1.getx()==p2.getx() || (p.gety()==p1.gety() && p1.gety()==p2.gety()))
cout<<"\nThe points are collinear"<<endl;
else{
/* Compute distance between p1 and p2. */
a = sqrt((p1.getx() - p.getx())*(p1.getx() - p.getx()) + (p1.gety() - p.gety())*(p1.gety() - p.gety()));
/* Print distance. */
cout<<"Distance between points p1 and p2: "<<a<<endl;
/* Compute distance between p2 and p3. */
b = sqrt((p2.getx() - p1.getx())*(p2.getx() - p1.getx()) + (p2.gety() - p1.gety())*(p2.gety() - p1.gety()));
/* Print distance. */
cout<<"Distance between points p2 and p3: "<<b<<endl;
/* Compute distance between p1 and p3. */
c = sqrt((p2.getx() - p.getx())*(p2.getx() - p.getx()) + (p2.gety() - p.gety())*(p2.gety() - p.gety()));
/* Print distance. */
cout<<"Distance between points p1 and p3: "<<c<<endl;
s = 0.5*( a + b + c );
area = sqrt( s*(s-a)*(s-b)*(s-c) );
cout<<"The area of the triangle is : "<<area<<endl;
if(a==b && b==c && a==c)
cout<<"It is an equilateral triangle."<<endl;
else
if(a==b || b==c || a==c)
cout<<"It is an isosceles triangle."<<endl;
else
if(c==sqrt(a*a + b*b) || a==sqrt(b*b + c*c) || b==sqrt(a*a + c*c))
cout<<"It is a right-angled triangle."<<endl;
}
}
Hello Everyone! I'm new here. I'm quite bad at my OOP, and the above is a qn i gotta work on. I'm extremely bad at CLASS, I'm not sure how to go abt with it. I still tried using it and the above is what i got. The progam works well but i'm not sure the CLASS part is right so do help mi please.