Advertisement
AntonioVillanueva

Petits Ronds Exercice 46 -109

Dec 3rd, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. //Ex 46 petits ronds
  2. #include <iostream>
  3. #include <cmath> //M_PI
  4. using namespace std;
  5. class Cercle {
  6.     public:
  7.     Cercle (float rayon=1,float x=1,float y=1);
  8.     double surface ()const ;
  9.     void getCentre (double &x,double &y) const;
  10.     void setCentre (double x,double y) ;
  11.  
  12.     bool estInterieur(double x,double y)const;
  13.     bool estInterieur(Cercle c)const;
  14.    
  15.     void affiche();
  16.        
  17.     private:
  18.     double _rayon,_x,_y;
  19. };
  20. Cercle::Cercle (float rayon ,float x,float y):_rayon (rayon),_x(x),_y(y) {};
  21. double Cercle::surface ()const {return M_PI* pow(_rayon,2);}
  22.  
  23. void Cercle::getCentre (double &x,double &y) const{x=_x;y=_y;}
  24. void Cercle::setCentre (double x,double y) {_x=x;_y=y;}
  25. bool Cercle::estInterieur(double x,double y)const{
  26.    
  27.     double tmp=sqrt (pow((_x-x),2)+(pow((_y-y),2))) ;
  28.     if (tmp<=_rayon){return true;}
  29.    
  30.     return false;
  31. }
  32. bool Cercle::estInterieur(Cercle c)const{
  33.     return estInterieur(c._x,c._y);
  34. };
  35. void Cercle::affiche(){
  36.     cout << "rayon="<<_rayon<<",x="<<_x<<",y="<<_y<<endl;
  37. }
  38.  
  39. int main(){
  40.     Cercle c,a(1,0.5,0.5),d(1,1.1,1.1),e(1,2,2),f(2,2);
  41.     cout <<"surface="<<c.surface()<<endl;
  42.    
  43.     cout <<c.estInterieur(1.1,0.5)<<endl;
  44.     cout <<c.estInterieur(a)<<endl;
  45.     cout <<c.estInterieur(d)<<endl;
  46.     cout <<c.estInterieur(e)<<endl;
  47.     cout <<c.estInterieur(f)<<endl;
  48.    
  49.     Cercle x;
  50.     x.setCentre (2,4);
  51.     x.affiche ();
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement