This course teaches how to install and configure Windows Server 2012 R2. It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

#include <iostream>

#include <fstream>

#include <stdlib.h>

#include <conio.h>

#include <ctype.h>

#include <cmath>

class Coords

{

public:

void DisplayCoords();

void SetCoords(int X, int Y);

void GetCoords();

void SetLine(Line &AB, Coords A, Coords B);

void DisplayLine(Line AB);

float LineSlope(Line AB);

double LineLength(Line AB);

int x;

int y;

};

main()

{

Coords A, B;

Line AB;

cout<<"A: "<<endl;

A.GetCoords();

cout<<"B: "<<endl;

B.GetCoords();

SetLine(AB, A, B);

DisplayLine(AB);

cout<<"The length of the line is: "<<LineLength(AB)<<endl;

cout<<"The slope of the line is: "<<LineSlope(AB)<<endl;

getch();

}

void Coords::GetCoords()

{

int X, Y;

cout<<">>";

cin>>X;

cout<<">>";

cin>>Y;

SetCoords(X, Y);

}

void Coords::SetCoords(int X, int Y)

{

x = X;

y = Y;

}

void Coords::DisplayCoords()

{

cout<<"("<<x<<", "<<y<<")";

}

void Coords::SetLine(Line &AB, Coords A, Coords B)

{

AB.A = A;

AB.B = B;

}

void Coords::DisplayLine(Line AB)

{

cout<<endl<<"{";

DisplayCoords(AB.A);

cout<<", ";

DisplayCoords(AB.B);

cout<<"}"<<endl;

}

Can someone help me to find the area, linelength, lineslope, and circumstances of the triangle in the rectangular coordinate.

#include <fstream>

#include <stdlib.h>

#include <conio.h>

#include <ctype.h>

#include <cmath>

class Coords

{

public:

void DisplayCoords();

void SetCoords(int X, int Y);

void GetCoords();

void SetLine(Line &AB, Coords A, Coords B);

void DisplayLine(Line AB);

float LineSlope(Line AB);

double LineLength(Line AB);

int x;

int y;

};

main()

{

Coords A, B;

Line AB;

cout<<"A: "<<endl;

A.GetCoords();

cout<<"B: "<<endl;

B.GetCoords();

SetLine(AB, A, B);

DisplayLine(AB);

cout<<"The length of the line is: "<<LineLength(AB)<<endl;

cout<<"The slope of the line is: "<<LineSlope(AB)<<endl;

getch();

}

void Coords::GetCoords()

{

int X, Y;

cout<<">>";

cin>>X;

cout<<">>";

cin>>Y;

SetCoords(X, Y);

}

void Coords::SetCoords(int X, int Y)

{

x = X;

y = Y;

}

void Coords::DisplayCoords()

{

cout<<"("<<x<<", "<<y<<")";

}

void Coords::SetLine(Line &AB, Coords A, Coords B)

{

AB.A = A;

AB.B = B;

}

void Coords::DisplayLine(Line AB)

{

cout<<endl<<"{";

DisplayCoords(AB.A);

cout<<", ";

DisplayCoords(AB.B);

cout<<"}"<<endl;

}

Can someone help me to find the area, linelength, lineslope, and circumstances of the triangle in the rectangular coordinate.

1. use pythagorean formula for length

2. slope is too easy. (y2-y1)/(x2-x2)

3. area: find the signed area under curve for all three sides in either clockwise or anticlockwise direction and add it up (this actually works for all shapes, concave or convex but without holes)

4. circumcircle(?) is a little bit complex to calculate. you will need:

i. equations for perpendicular bisectors for at least two sides

ii. find their intersection. this is the circumcenter

iii. distance from circumcenter to any vertex is the radius of circumcircle.

now try to translate this into C++. define the data structures you might need. this is not very complex but non-trivial problem. attempt one thing at a time. if the results don't match expected output, post ur code and we will be glad to help.

jaydutt

double LineLength(Line AB) {

return sqrt( pow(AB.A.x-AB.B.x,2.0) + pow(AB.A.y-AB.B.y,2.0) );

}

for slope you can use the atan() function.

the formula for area of triangle is (Heron formula):

S = sqrt ( p.(p-a).(p-b).(p-c) )

where a,b,c are the lenght of each side and:

p = 0.5 (a+b+c)

http://mcraeclan.com/mathhelp/GeometryConicSectionCircleEquationGivenThreePoints.htm

we want the slope. not the angle.

>> find the signed area under curve for all three sides in either clockwise or anticlockwise direction

correction: only clockwise direction gives correct answer. use abs() [or may be fabs() is needed] to get actual area.

#include <fstream>

#include <stdlib.h>

#include <conio.h>

#include <stype.h>

#include <cmath>

struct Coords

{

int x;

int y;

};

struct Line

{

Coords A;

Coords B;

};

void DisplayCoords (Coords Point);

void SetCoords (Coords &Point, int x, int y);

void GetCoords (Coords &Point);

void SetLine (Line &AB, Coords A, Coords B);

void DisplayLine (Line AB);

float LineSlope (Line AB);

double LineLength (Line AB);

main ()

{

Coords A, B;

Line AB;

cout<<"A: "<<endl;

GetCoords(A);

cout <<"B: "<<endl;

GetCoords(B);

SetLine (AB, A, B);

DisplayLine (AB);

cout <<"The length of the line is: "<<LineLength(AB)<<endl;

cout <<"The slope of the line is: "<<LineSlope(AB)<<endl;

getch();

}

void GetCoords (Coords &Point)

{

int x, y;

cout <<">>";

cin>>x;

cout <<">>";

cin>>y;

SetCoords (Point, x, y);

}

void SetCoords (Cooords &Point, int x, int y)

{

Point.x = x;

Point.y = y;

}

void SetLine (Line &AB, Coords A, Coords B)

{

AB.A = A;

AB.B = B;

}

void DisplayLine (Line AB)

{

cout<<endl<<"{";

DisplayCoords(AB.A);

cout<<", ";

DisplayCoords(AB.B);

cout<<"}"<<endl;

}

void DisplayCoords (Coords Point)

{

cout<<"("<<Point.x<<", "<<Point.y<<")";

}

double LineLength(Line AB)

{

return sqrt( pow(AB.A.x-AB.B.x,2.0) + pow(AB.A.y-AB.B.y,2.0) );

}

float LineSlope (Line AB)

{

if (AB.B.x!=AB.A.x)

return ((AB.B.y-AB.A.y)/(AB.B.x-A

else

return 3.14/2;

}

This show me a lot of problem:

37 H:\LIne, Slope.cpp `cout' undeclared (first use this function)

52 H:\LIne, Slope.cpp `cin' undeclared (first use this function)

How should i fix this

using namespace std;

or alternatively,

using std::cin;

using std::cout;

using std::err; // ditto

using std::endl; // this is not required in your code but most often you would need it

or you could add 'std::' before all your cin, cout, endl and err. like, std::cin >> some_stuff;

{

if (AB.B.x!=AB.A.x)

return ((AB.B.y-AB.A.y)/(AB.B.x-A

else

return 3.14/2; <<----- this is wrong. it is supposed to be +/- INF

}

I would define a global const float.

const float INF = 1.#INF; // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/html/vcsampsamplemembersofthenumericlimitsclassstlsample.asp

and the new function would be float LineSlope (Line AB)

{

if (AB.B.x!=AB.A.x)

return ((AB.B.y-AB.A.y)/(AB.B.x-A

else

return INF;

}

or you could stick to returning angles. in that case, as jaime said you can use atan from <cmath>

if (AB.B.x!=AB.A.x)

return atan(((AB.B.y-AB.A.y)/(AB.

float INF;

int main(){

char * pINF = (char*)&INF;

pINF[0] = 0x3f; pINF[1] = 0x80; pINF[2] = pINF[3] = 0;

... rest of your code...

}

double Circumference(Triangle ABC)

{

return LineLength(ABC.AB)+LineLen

}

i dont know how to do with area

doulbe Area(Triangle ABC)

area use jaime's solution (Heron's formula)

float a,b,c,s, area;

a = LineLength(ABC.BC);

b = LineLength(ABC.CA);

c = LineLength(ABC.AB);

s = (a+b+c)/2;

area = pow(s*(s-a)*(s-b)*(s-c), 0.5);

note that jaime used S for area and I used s for semi-perimeter. do not confuse yourself with two s's. also, he uses p for semi-perimeter.

{

return pow((Circumference(ABC)/2.

*((Circumference(ABC)/2.0)

}

I do on this way, just copy the way jhshukla do it, area = pow(s*(s-a)*(s-b)*(s-c), 0.5); But it doesnt shoe the right answer. I can not you a, b, c,, s instead.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.