#include <iostream>
#include <cmath>
usingnamespace std;
struct Point{
double x;
double y;
};
class Triangle
{
public:
Point point[3];
Triangle()
{
for(int i = 0; i < 3; i++){
point[i].x = 1.0;
point[i].y = 1.0;
}
}
Triangle(Point newPoint[])
{
for(int i = 0; i < 3; i++)
point[i] = newPoint[i];
}
double getPerimeter()
{
return getLength(point[1], point[2]) + getLength(point[1], point[3]) + getLength(point[3], point[2]);
}
double getLength(Point point1, Point point2)
{
return sqrt(pow((point1.x - point2.x), 2.0) + pow((point1.y - point2.y), 2.0));
}
};
int main()
{
Point point[3];
for(int i = 0; i < 3; i++)
{
cout << "Type x for point" << i + 1 << " : ";
cin >> point[i].x;
cout << "Type y for point" << i + 1 << " : ";
cin >> point[i].y;
}
Triangle triangle1;
Triangle triangle2(point);
cout << "The perimeter of the triangle1 is : " << triangle1.getPerimeter() << endl;
cout << "The perimeter of the triangle2 is : " << triangle2.getPerimeter() << endl;
system("pause");
return 0;
}
I expect to get 0 for triangle1, but I get some strange value...
can anybody tell me why this happens??
Here is the result
Type x for point1 : 1
Type y for point1 : 1
Type x for point2 : 3
Type y for point2 : 1
Type x for point3 : 1
Type y for point3 : 3
The perimeter of the triangle1 is : 2.82843
The perimeter of the triangle2 is : 6.82843
계속하려면 아무 키나 누르십시오 . . .