Skip to content

Instantly share code, notes, and snippets.

Created October 20, 2014 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/37882c732268e332f20c to your computer and use it in GitHub Desktop.
Save anonymous/37882c732268e332f20c to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <cmath>
#include <iostream>
using namespace std;
double a = 0, b = 0, c = 0, A = 0, B = 0, C = 0;
double angle(double a, double b, double c);
double side(double Xa, double Xb, double Xc, double Ya, double Yb, double Yc);
int main()
{
double Xa, Xb, Xc;
double Ya, Yb, Yc;
double deg = 57.324;
cout << "Enter the value of X of point a: "; cin >> Xa;
cout << "Enter the value of Y of point a: "; cin >> Ya;
cout << "Enter the value of X of point b: "; cin >> Xb;
cout << "Enter the value of Y of point b: "; cin >> Yb;
cout << "Enter the value of X of point c: "; cin >> Xc;
cout << "Enter the value of Y of point c: "; cin >> Yc;
side(Xa, Xb, Xc, Ya, Yb, Yc);
angle(a, b, c);
if (((a + b) < c) && ((b + c) < a) && ((a + c) < b)) {
cout << "\nThe side a is " << a << ", the side b is " << b << ", the side c is " << c << endl;
cout << "\nThe angle A is " << A << "RAD "; cout << A*deg << "DEG" << endl;
cout << "\nThe angle B is " << B << "RAD "; cout << B*deg << "DEG" << endl;
cout << "\nThe angle C is " << C << "RAD "; cout << C*deg << "DEG" << endl;
} else {
cout << "\nPlease enter different values." << endl;
}
return 0;
}
double angle(double a, double b, double c)
{
double aa = (a*a + b*b - c*c) / (2 * b*c);
double bb = (b*b + a*a - c*c) / (2 * a*c);
double cc = (c*c + b*b - a*a) / (2 * a*b);
A = acos(aa);
B = acos(bb);
C = acos(cc);
}
double side(double Xa, double Xb, double Xc, double Ya, double Yb, double Yc)
{
a = sqrt(((Xc - Xb)*(Xc - Xb)) + ((Yc - Yb)*(Yc - Yb)));
b = sqrt(((Xa - Xc)*(Xa - Xc)) + ((Ya - Yc)*(Ya - Yc)));
c = sqrt(((Xb - Xa)*(Xb - Xa)) + ((Yb - Ya)*(Yb - Ya)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment