Advertisement
AntonioVillanueva

Exercice 47 coordonnées tridimensionnelles 110

Dec 4th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. //Exercice 47 coordonnées tridimensionnelles 110
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. //----------------------------------------------------------------------
  6. class Point3D{
  7.     public:
  8.     Point3D(float x=1,float y=1,float z=1);
  9.     ostream& affiche (ostream& stream);
  10.     bool compare(Point3D const &p);
  11.    
  12.     private :
  13.     float x,y,z;
  14. };
  15. //----------------------------------------------------------------------
  16. //----------------------------------------------------------------------
  17.     Point3D::Point3D(float x,float y,float z):x(x),y(y),z(x){}
  18.    
  19.     ostream&  Point3D::affiche (ostream& stream){
  20.          stream <<"( "<<x<<" , "<<y<<" , "<<z<<" )"<<endl;
  21.          return stream;
  22.     }
  23.          
  24.     bool Point3D::compare(Point3D const &p){
  25.         if (p.x==x && p.y==y && p.z==z){return true;}
  26.         return false;
  27.     }
  28.        
  29.     ostream& operator <<(ostream& os ,Point3D p){  
  30.         return p.affiche(os);
  31.     }      
  32. //----------------------------------------------------------------------
  33. int main(){
  34.     Point3D A, B(2,1,1), C(1,1,1); //Trois points
  35.  
  36.     cout<<A<<B<<C<<endl;//Affiche les trois points
  37.     cout<<A.compare(B)<<endl;//Compare A avec B
  38.     cout<<A.compare(C)<<endl;//et A avec C
  39.        
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement