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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #include <iostream>
using namespace std ;
class Point
{
int x;
int y;
public :
Point();
Point(int, int);
~Point();
void Init(int a, int b);
void Init(int a=0);
void Deplace(int a, int b);
void Deplace(int a=0);
void Affiche(char* strMesg="");
int Coincide(Point &);
};
Point::Point()
{
cout << "--Constructeur par defaut--" << endl;
}
Point::Point(int a, int b)
{
cout << "--Constructeur (a,b)--" << endl;
Init(a,b);
}
Point::~Point()
{
cout << "--Destructeur--" << endl;
}
void Point::Init(int a, int b)
{
x = a;
y = b;
}
void Point::Init(int a)
{
Init(a,a);
}
void Point::Deplace(int a, int b)
{
x += a;
y += b;
}
void Point::Deplace(int a)
{
Deplace(a,a);
}
void Point::Affiche(char *strMesg)
{ // On ne rajoute pas le paramètre par
// défaut dans limplémentation !
cout << strMesg << x << ", " << y << endl;
}
int Point::Coincide(Point & p)
{
if( (p.x==x) && (p.y==y) )
return 1;
else
return 0;
}
void main()
{
Point p(1,2);
p.Deplace(4);
p.Affiche("Le point vaut ");
p.Init(10);
p.Affiche("Le point vaut desormais : ");
Point pp;
pp = p;
p.Deplace(12,13);
pp.Deplace(5);
p.Affiche("Le point p vaut ");
pp.Affiche("Le point pp vaut ");
Point ppp(2,0);
Point pppp(2);
if( ppp.Coincide(pppp) )
cout << "p et pp coincident !" << endl;
if( pppp.Coincide(ppp) )
cout << "pp et p coincident !" << endl; |
Partager