Classes: Point2D et Triangle
Bonjour,
J'ai crée une classe Point2D que voici :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #ifndef _POINT_H_
#define _POINT_H_
class Point2D {
private :
float x; // abscisse
float y; // ordonnee
public :
Point2D();
Point2D(float, float);
void afficherPoint();
float distance(Point2D);
float getX();
float getY();
void setX(float);
void setY(float);
};
#endif |
Ainsi qu'une classe Triangle :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #ifndef _TRIANGLE_H_
#define _TRIANGLE_H_
#include "Point2D.h"
class Triangle {
private :
Point2D A;
Point2D B;
Point2D C;
public :
Triangle(Point2D, Point2D, Point2D);
bool isocele();
bool equilateral();
bool rectangle();
float perimetre();
};
#endif |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include "Triangle.h"
Triangle::Triangle(Point2D A, Point2D B, Point2D C):A(A),B(B),C(C) {}
bool Triangle::isocele() {
if ((A.distance(B) == B.distance(C)) ||
(A.distance(B) == A.distance(C)) ||
(A.distance(C) == B.distance(C))) {
return true;
}
else return false;
}
bool Triangle::equilateral() {
if ((A.distance(B) == B.distance(C)) && (A.distance(B) == A.distance(C))) {
return true;
}
else return false;
}
// NE FONCTIONNE PAS
bool Triangle::rectangle() {
if (A.distance(B)*A.distance(B) == A.distance(C)*A.distance(C) + B.distance(C)*B.distance(C)) {
return true;
}
else if (A.distance(C)*A.distance(C) == A.distance(B)*A.distance(B) + B.distance(C)*B.distance(C)) {
return true;
}
else if (B.distance(C)*B.distance(C) == A.distance(C)*A.distance(C) + A.distance(B)*A.distance(B)) {
return true;
}
else return false;
}
float Triangle::perimetre() {
float resultat = 0;
resultat += A.distance(C) + A.distance(B) + B.distance(C);
return resultat;
} |
Problème, ma méthode rectangle() semble ne pas fonctionner (ce qui n'est pas le cas des autres)
En effet, quand je teste ceci :
Code:
1 2 3 4 5
| Point2D A(2,3);
Point2D B(1,-1);
Point2D C(6,2);
Triangle T(A,B,C);
cout << T.rectangle() << endl; |
Il m'affiche 0 alors que pourtant le triangle est rectangle...
Je n'arrive pas a voir d’où vient le problème, pouvez vous m'aider ?
Merci d'avance.