Create a program that reads coordinates of four points A B C
Create a program that reads coordinates of four points (A, B, C and D) in 2D from the
x y
A 1.2 3.6
B 1.8 2.9
C 3.6 5.7
D 9.9 3.2
and reports the user the followings:
1: Each length of sides of the triangle of points A, B and C
2: Total length of sides of the triangle
in c++
Solution
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double x1,x2,x3,x4;
double y1,y2,y3,y4;
cout<<\"enter point A\";
cout<<\"\ x : \";
cin>>x1;
cout<<\"\ y:\";
cin>>y1;
cout<<\"enter point B\";
cout<<\"\ x : \";
cin>>x2;
cout<<\"\ y:\";
cin>>y2;
cout<<\"enter point C\"
cout<<\"\ x : \";
cin>>x3;
cout<<\"\ y:\";
cin>>y3;
cout<<\"enter point D\";
cout<<\"\ x : \";
cin>>x4;
cout<<\"\ y:\";
cin>>y4;
double ab,bc,ca;
ab=sqrt(pow((x1-x2),2)+pow((y1-y2),2));
bc=sqrt(pow((x3-x2),2)+pow((y3-y2),2));
ca=sqrt(pow((x1-x3),2)+pow((y1-y3),2));
double total;
total=ab+bc+ca;
cout<<total<<\"\\t\"<<ab<<\"\\t\"<<bc<<\"\\t\"<<ca;
return 0;
}

