Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Ex 46 petits ronds
- #include <iostream>
- #include <cmath> //M_PI
- using namespace std;
- class Cercle {
- public:
- Cercle (float rayon=1,float x=1,float y=1);
- double surface ()const ;
- void getCentre (double &x,double &y) const;
- void setCentre (double x,double y) ;
- bool estInterieur(double x,double y)const;
- bool estInterieur(Cercle c)const;
- void affiche();
- private:
- double _rayon,_x,_y;
- };
- Cercle::Cercle (float rayon ,float x,float y):_rayon (rayon),_x(x),_y(y) {};
- double Cercle::surface ()const {return M_PI* pow(_rayon,2);}
- void Cercle::getCentre (double &x,double &y) const{x=_x;y=_y;}
- void Cercle::setCentre (double x,double y) {_x=x;_y=y;}
- bool Cercle::estInterieur(double x,double y)const{
- double tmp=sqrt (pow((_x-x),2)+(pow((_y-y),2))) ;
- if (tmp<=_rayon){return true;}
- return false;
- }
- bool Cercle::estInterieur(Cercle c)const{
- return estInterieur(c._x,c._y);
- };
- void Cercle::affiche(){
- cout << "rayon="<<_rayon<<",x="<<_x<<",y="<<_y<<endl;
- }
- int main(){
- Cercle c,a(1,0.5,0.5),d(1,1.1,1.1),e(1,2,2),f(2,2);
- cout <<"surface="<<c.surface()<<endl;
- cout <<c.estInterieur(1.1,0.5)<<endl;
- cout <<c.estInterieur(a)<<endl;
- cout <<c.estInterieur(d)<<endl;
- cout <<c.estInterieur(e)<<endl;
- cout <<c.estInterieur(f)<<endl;
- Cercle x;
- x.setCentre (2,4);
- x.affiche ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement