Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std ;
- class Point {
- private:
- float abs;
- float ord;
- char pnt;
- public:
- Point(char, float,float);
- Point();
- Point(const Point &p);
- void deplace(float dx,float dy);
- void affiche();
- float GetAbs() {return abs;};
- float GetOrd();
- char GetPnt();
- ~Point();
- };
- Point::Point(char a,float x,float y)
- {
- pnt= a;
- abs= x;
- ord= y;
- cout<<"construction point "<<a<<" d'abscisse "<<x<<" et d'ordonnee "<<y<<" avec le constructeur parametre"<<endl;
- }
- Point::Point()
- {
- pnt= 'o';
- abs= 0;
- ord= 0;
- }
- Point::Point(const Point &p)
- {
- pnt= p.pnt;
- abs= p.abs;;
- ord= p.ord;
- }
- Point::~Point()
- {
- cout<<"destruction du point "<<pnt<<endl;
- }
- void Point::deplace(float dx, float dy)
- {
- abs=abs+dx;
- ord=ord+dy;
- }
- void Point::affiche()
- {
- cout<<"le point "<<pnt<<" a pour coordonnées:("<<abs<<","<<ord<<")"<<endl;
- }
- inline float Point::GetOrd() {
- return ord;
- }
- char Point::GetPnt(){
- return pnt;
- }
- float distant(Point t1, Point t2)
- {
- float d,x1,x2,y1,y2;
- x1=t1.GetAbs();
- x2=t2.GetAbs();
- y1=t1.GetAbs();
- y2=t2.GetAbs();
- d = sqrt(pow((x1-x2),2)+pow((y1-y2),2));
- return d;
- }
- int main ()
- {
- Point p1('p',1,2);
- Point p2('r',2,4);
- Point p5(p2);
- p1.affiche();
- p2.affiche();
- p5.affiche();
- cout<<"distance entre "<<p1.GetPnt()<<" et "<<p2.GetPnt()<<" est "<<distant(p1,p2)<<endl;
- p1.deplace(3,4);
- p2.deplace(0,5);
- p1.affiche();
- p2.affiche();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement