Problem Statement:
Write a function to compute the distance between two points
and use it to develop another function that will compute the
area of the triangle whose vertices are A(x1, y1), B(x2, y2),
and C(x3, y3).
and use it to develop another function that will compute the
area of the triangle whose vertices are A(x1, y1), B(x2, y2),
and C(x3, y3).
Solution:
//Ahmad Furqan
//P5.j
#include <iostream>
#include <conio.h>
using namespace std;
float pdist(int x1, int y1, int x2, int y2)
{
float dist;
dist = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
return dist;
}
float triarea(float a, float b, float c)
{
float s;
float area;
s = (a + b + c) / 2;
area = sqrt(s*(s - a)*(s - b)*(s - c));
return area;
}
void main(void)
{
int x1, x2, x3, y1, y2, y3;
float a, b, c;
cout << "Enter point 1: ";
cout << "Enter x: ";
cin >> x1;
cout << "Enter y:";
cin >> y1;
cout << "Enter point 2:";
cout << "Enter x:";
cin >> x2;
cout << "Enter y";
cin >> y2;
cout << "Enter point 3:";
cout << "Enter x:";
cin >> x3;
cout << "Enter y:";
cin >> y3;
a = pdist(x1, y1, x2, y2);
b = pdist(x2, y2, x3, y3);
c = pdist(x1, y1, x3, y3);
cout << "Area of triangle bounded by these points is: " << triarea(a, b, c);
_getch();
}
No comments:
Post a Comment