Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 21.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <cstring>
  5. #include <iterator>
  6. #include <initializer_list>
  7. #include <cmath>
  8. #include <cassert>
  9.  
  10. #define PI 3.14159265
  11. //Je me suis arrêté après avoir terminé la partie 2.
  12. //Faire différents module serait plus propre.
  13. //Je n'ai pas testé ce code sous visual studio. Je compile avec g++ option -std=c++11
  14. using namespace std;
  15.  
  16. //~ class Point{
  17.     //~ private:
  18.     //~ int x,y;
  19.     //~
  20.     //~ public:
  21.         //~ inline Point():x(0),y(0){}
  22.         //~ inline Point(int a, int b):x(a),y(b){}
  23.         //~ inline Point(const Point &P):x(P.x),y(P.y){}
  24.         //~ inline int getPoint_x()const{ return x;}
  25.         //~ inline int getPoint_y()const{ return y;}
  26.         //~ inline void setPoint_x(int a){this->x=a;}
  27.         //~ inline void setPoint_y(int a){this->y=a;}
  28. //~ };
  29. //!DEBUT POINT.H
  30.     class Point{
  31.     private:
  32.     float x,y;
  33.    
  34.     public:
  35.         inline Point();
  36.         inline Point(float a, float b);
  37.         inline Point(const Point &P);
  38.         inline float getPoint_x()const;
  39.         inline float getPoint_y()const;
  40.         inline void setPoint_x(float flo);
  41.         inline void setPoint_y(float flo);
  42.        
  43.         Point& operator =(const Point &P); 
  44. };
  45. //!FIN POIN.h
  46. //!DEBUT POINT.cpp 
  47.     inline Point::Point():x(0),y(0){}
  48.     inline Point::Point(float a, float b):x(a),y(b){}
  49.     inline Point::Point(const Point &P):x(P.x),y(P.y){}
  50.     inline float Point::getPoint_x()const{ return x;}
  51.     inline float Point::getPoint_y()const{ return y;}
  52.     inline void Point::setPoint_x(float flo){this->x=flo;}
  53.     inline void Point::setPoint_y(float flo){this->y=flo;}
  54.    
  55.     Point& Point::operator =(const Point &P){
  56.         cout << "Point: operator = " << endl;
  57.         if(this!=&P){
  58.             this->x=P.x;
  59.             this->y=P.y;
  60.         }
  61.         return *this;
  62.     }
  63.    
  64.     ostream& operator<<(ostream &os ,const Point p){
  65.         os << "( " << p.getPoint_x() <<" , " << p.getPoint_y() <<" )"<< endl;
  66.         return os;
  67.     }
  68.    
  69. //!FIN DE POINT .cpp
  70. //!DEBUT COLOR.H
  71. class Color{
  72.     public:
  73.     enum color { white, yellow, orange, turquoise, violet, pink, red, green, grey, cyan, blue, brown};//Chap 1 p12
  74.    
  75.     // tester avec enum color:const char* {black = "black ", ... } // dans main Color c(Color::red);
  76.     private :
  77.     color couleur;
  78.     static const char* name[];
  79.    
  80.     public:
  81.     inline Color();
  82.     inline Color(color c );
  83.     inline Color(const Color &C );//Ajout non demandé
  84.     void view();
  85.     const char* getColor()const;
  86.  
  87.    
  88. };
  89. //!FIN COLOR.H
  90. //!DEBUT COLOR.CPP
  91.     inline Color::Color():couleur(red){};
  92.     inline Color::Color(color c ):couleur(c){cout << "Ccopie" << endl; };
  93.     inline Color::Color(const Color &C ):couleur(C.couleur){cout << "Ccopie" << endl; };//Ajout non demandé
  94.     void Color::view(){ cout << couleur << endl; }
  95.     const char* Color::getColor()const{ return name[couleur];}
  96.  
  97. const char* Color::name[]={ "white", "yellow", "orange", "turquoise", "violet", "pink", "red", "green", "grey", "cyan", "blue", "brown"};//Chap 1 p12
  98. //!FIN COLOR.CPP
  99. //!DEBUT TRANSFORM.H
  100. class Transform{//Interface ne contient que des méthodes virtuels pures (méthodes implémentés dans les classes qui héritent de cette interface/classe abstraite pure ) n'implémentez JAMAIS une fonction virtuelle pure dans cette même classe
  101.     public:
  102.     virtual void Rotate(float)=0;
  103.     virtual void Translate(float,float)=0;
  104.     virtual void Scale(float)=0;
  105. };
  106. //!FIN TRANSFORM.H
  107. //!DEBUT GEOM2D.H
  108. class Geom2D: public Transform{
  109.     protected:
  110.         Point p;
  111.     public:
  112.    
  113.     //Constructeurs
  114.     inline Geom2D();//on utilise le constructeur par défaut de Point
  115.     inline Geom2D(float x,float y);//on utilise le constructeur qui prend deux entier de Point
  116.     inline void info();
  117.  
  118.        
  119.     inline Point getPoint()const;//modification ici avec erreur dans setter
  120.     inline void setX(float x);
  121.     inline void setY(float y);
  122.     virtual void Translate(float a, float b){p.setPoint_x(p.getPoint_x()+a);p.setPoint_y(p.getPoint_y()+b);}
  123. };
  124. //!FIN GEOM2D.H
  125. //!DEBUT GEOM2D.CPP
  126.     //Constructeurs
  127.     inline Geom2D::Geom2D():p(){}//on utilise le constructeur par défaut de Point
  128.     inline Geom2D::Geom2D(float x,float y):p(x,y){}//on utilise le constructeur qui prend deux entier de Point
  129.     inline void Geom2D::info(){
  130.         cout << "Coordonnées : " << p.getPoint_x() << ", " << p.getPoint_y() << endl;
  131.     }
  132.  
  133.        
  134.     inline Point Geom2D::getPoint()const{return p;}//modification ici avec erreur dans setter
  135.     inline void Geom2D::setX(float x){p.setPoint_x(x);}
  136.     inline void Geom2D::setY(float y){p.setPoint_y(y);}
  137.        
  138. //!FIN GEOM2D.CPP
  139. //!DEBUT FILLPROPERTY.H
  140. class FillProperty{
  141.     protected:
  142.         Color C;
  143.     public:
  144.     //Constructeurs
  145.         inline FillProperty();
  146.         inline FillProperty(const Color &Couleur);
  147.        
  148.         inline void info();// à suppr juste pour tests
  149.         inline const char* getColor()const;
  150. };
  151. //!FIN FILLPROPERTY.H
  152. //!DEBUT FILLPROPERTY.cpp
  153.     inline FillProperty::FillProperty():C(){}
  154.     inline FillProperty::FillProperty(const Color &Couleur):C(Couleur){}
  155.    
  156.     inline void FillProperty::info(){cout << C.getColor() << endl;}// à suppr juste pour tests
  157.     inline const char* FillProperty::getColor()const{return C.getColor();}
  158. //!FIN FILLPROPERTY.cpp
  159. //!DEBUT SURFACE.H
  160. class Surface : public Geom2D, public FillProperty{//classe virtuelle à cause de aire et info qui seront réimplémenté dans les objets qui héritent de Surface, ceci dit n'étant pas des fonctions virtuelles pure on doit implémenté info() et aire() aussi dans Surface
  161.     protected:
  162.         float S_rotate;//Utile pour transform()
  163.     public:
  164.     //Constructeurs
  165.         inline Surface();
  166.         inline Surface(float x, float y, const Color& Couleur);    
  167.         inline void info();
  168.         virtual double aire(){return 0;}//pas d'air pour l'instant on ne dispose que d'un point et d'une couleur
  169.         virtual void Rotate( float rotation){S_rotate = rotation;}
  170.         inline float getRotate()const;
  171. };
  172. //!FIN SURFACE.H
  173. //!DEBUT SURFACE.cpp
  174.     inline Surface::Surface():Geom2D(),FillProperty(),S_rotate(0){cout << "Surface defaut " << endl;}
  175.     inline Surface::Surface(float x, float y, const Color& Couleur):Geom2D(x,y),FillProperty(Couleur),S_rotate(0){cout << "S_tout spécifier\n" << endl;};     
  176.     inline void Surface::info(){
  177.         cout << "Surface : \nCouleur " << C.getColor() << "\nGeom2D (x,y) : ( " << p.getPoint_x() << " , "  << p.getPoint_y() << " )\n" << endl;
  178.     }
  179.     inline float Surface::getRotate()const{return S_rotate;}
  180. //!FIN SURFACE.cpp
  181. //!DEBUT DISC.H
  182. class Disc : public Surface{
  183.     private:
  184.         float rayon;
  185.     public:
  186.     //Constructeurs
  187.         inline Disc();
  188.         inline Disc(float x, float y ,const Color& Couleur, float r);
  189.         inline void info();
  190.         inline float getRayon()const;
  191.         virtual double aire(){return 3.14*rayon*rayon;}//pi*r*r peut mieux faire pour pi
  192.         virtual void Scale(float s){ rayon*=s;};
  193.     };
  194. //!FIN DISC.H
  195. //!DEBUT DISC.cpp
  196.     inline Disc::Disc():Surface(),rayon(100){}
  197.     inline Disc::Disc(float x, float y ,const Color& Couleur, float r):Surface(x,y,Couleur),rayon(r){}
  198.     inline void Disc::info(){
  199.         cout << "Disc : \nCouleur " << C.getColor() << "\nGeom2D (x,y) : ( " << p.getPoint_x() << " , "  << p.getPoint_y() << " )\n" << "Rayon : " << rayon << "\n" << endl;
  200.     }
  201.     inline float Disc::getRayon()const{return rayon;}
  202.    
  203. //!FIN DISC.cpp
  204.  
  205. //!DEBUT RECTANGLE.H
  206. class Rectangle : public Surface{
  207.     protected:
  208.         float hauteur;
  209.         float largeur;
  210.     public:
  211.     //Constructeurs
  212.         inline Rectangle();
  213.         inline Rectangle(float x, float y , float h , float l ,const Color& Couleur);
  214.         inline void info();
  215.         inline float getHauteur()const;
  216.         inline float getLargeur()const;
  217.         inline void setHauteur( float h);
  218.         inline void setLargeur( float l);
  219.        
  220.         virtual double aire(){return hauteur*largeur;}
  221.         virtual void Scale(float s ){hauteur*=s;largeur*=s;}
  222.    
  223. };
  224. //!FIN RECTANGLE.H
  225.  
  226. //!DEBUT RECTANGLE.cpp
  227.     inline Rectangle::Rectangle():Surface(),hauteur(100),largeur(200){}
  228.     inline Rectangle::Rectangle(float x, float y , float h , float l ,const Color& Couleur):Surface(x,y,Couleur),hauteur(h),largeur(l){}
  229.     inline void Rectangle::info(){
  230.         cout << "Rectangle : \nCouleur " << C.getColor() << "\nGeom2D (x,y) : ( " << p.getPoint_x() << " , "  << p.getPoint_y() << " )" << "\nHauteur: " << hauteur << "\nLargeur: " << largeur << "\n" << endl;
  231.     }
  232.     inline float Rectangle::getHauteur()const{return hauteur;}
  233.     inline float Rectangle::getLargeur()const{return largeur;}
  234.     inline void Rectangle::setHauteur( float h){this->hauteur = h;}
  235.     inline void Rectangle::setLargeur( float l){this->largeur = l;}
  236.  
  237. //!FIN RECTANGLE.cpp
  238. //!DEBUT RECTANGLE.H
  239.  
  240. class Square : public Rectangle{// On utilise uniquement la hauteur pour le carré
  241.     public:
  242.         inline Square();
  243.         inline Square(float x, float y ,float h,const Color& Couleur);
  244.         inline void info();
  245.         virtual double aire(){return hauteur*hauteur;}
  246.         virtual void Scale(float s){hauteur*=s;}
  247. };
  248. //!FIN RECTANGLE.H
  249. //!DEBUT RECTANGLE.CPP
  250.         inline Square::Square():Rectangle(){}
  251.         inline Square::Square(float x, float y ,float h,const Color& Couleur):Rectangle(x,y,h,h,Couleur){}
  252.         inline void Square::info(){
  253.             cout << "Square : \nCouleur " << C.getColor() << "\nGeom2D (x,y) : ( " << p.getPoint_x() << " , "  << p.getPoint_y() << " )\n" << hauteur << "\n" << endl;
  254.         }
  255.        
  256. //!FIN RECTANGLE.CPP
  257.  
  258. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PAS IMPLEMENTER
  259. class LineProperty:public FillProperty{
  260.     //Uniquement des méthodes virtuel=0 PURES
  261.    
  262. };
  263. class Curve:public LineProperty{   
  264.     private:
  265.         Point A,B;
  266.         int largeur;
  267.     public:
  268.         //Constructeurs
  269.         //getters
  270.         inline Point getPointA()const{return A;}
  271.         inline Point getPointB()const{return B;}
  272.         inline int getLargeur()const{return largeur;}
  273. };
  274. class Segment{
  275.    
  276. };
  277. //!!!!!!!!!!!!!!!!!!!!! Fin des trucs pas implémenté
  278. //!DEBUT SVGSTREAM.H
  279. class SVGstream{
  280.     private:
  281.         string nom;
  282.         ofstream fichier;
  283.     public:
  284.         inline SVGstream(string nom,bool PureSvg);
  285.         ~SVGstream(){
  286.             if(fichier){
  287.                 fichier << "</svg>" << endl;
  288.                 fichier.close();
  289.             }
  290.         }
  291.        
  292.     ostream& operator<<(const string s){//operator définie dans la classe, on a directement acces aux champs
  293.             fichier << s << endl;
  294.             return fichier;
  295.         }
  296.     ostream& operator<<(const Disc D){ // Amélioration de l'appel des Getteur ici ( D.getPoint().getPoint_x() est beaucoup mieux )
  297.         fichier << "<circle cx=\""<< D.getPoint().getPoint_x()  <<"\" cy= \""<< D.getPoint().getPoint_y() <<"\" r= \""<< D.getRayon() <<"\" fill= \""<< D.getColor() << "\"/>" << endl;
  298.         return fichier;
  299.     }
  300.     ostream& operator <<(const Rectangle R){
  301.         if(R.getRotate()!=0){
  302.             fichier << "<rect x=\"" <<  R.getPoint().getPoint_x() <<"\" y=\"" << R.getPoint().getPoint_y() <<"\" width=\"" << R.getHauteur() <<"\" height=\"" << R.getLargeur() <<"\" fill=\"" << R.getColor() << "\" transform=\"rotate("<< R.getRotate() <<","<< R.getPoint().getPoint_x()+ R.getHauteur()/2 << "," << R.getPoint().getPoint_y()+ R.getLargeur()/2 << ")\"/>" << endl;
  303.         }else{
  304.             fichier << "<rect x=\"" << R.getPoint().getPoint_x() <<"\" y=\"" << R.getPoint().getPoint_y() <<"\" width=\"" << R.getHauteur() <<"\" height=\"" << R.getLargeur() <<"\" fill=\"" << R.getColor() <<"\" />" << endl;
  305.         }
  306.         return fichier;
  307.     }
  308.     /*ostream& operator <<(const LineProperty L){//<line x1="20" y1="100" x2="100" y2="20"stroke-width="2" stroke="black"/>
  309.         fichier << "<line x1=\""<< L.getPointA().getPoint_x() <<"\" y1=\""<< L.getPointA().getPoint_y() <<"\" x2=\""<< L.getPointB().getPoint_x() <<"\" y2=\""<< L.getPointB().getPoint_x() <<"\" stroke-width=\""<< L.getLargeur() <<"\" stroke=\""<<L.getColor()<<"\"/>" << endl;
  310.         return fichier;
  311.     }*/
  312. };
  313. //!FIN SVGSTREAM.H
  314. //!DEBUT SVGSTREAM.CPP
  315.     inline SVGstream::SVGstream(string nom,bool PureSvg=true):fichier(nom+".html",ios::out | ios::trunc){
  316.         //~ string s = nom + ".html";
  317.         //~ ofstream fichier(s, ios::out | ios::trunc); // ouverture en écriture avec effacement du fichier ouvert / OU LE CREER SI EXISTE // possible de placer dans chaine d'initialisation
  318.         if(fichier){
  319.             if(!PureSvg){fichier << "<!doctype html>" << endl; }
  320.             fichier << "<svg width=\"1000\" height=\"1000\">" << endl ;
  321.         }
  322.     }
  323. //!FIN SVGSTREAM.CPP
  324. //!FIN TP3
  325. //!DEBUT TP4
  326.  
  327. //!DEBUT POINTARRAY.H
  328. class PointArray{//avec pointeur
  329.     protected:
  330.         size_t taille;
  331.         static const size_t def = 3;
  332.         Point* array;
  333.        
  334.     public:
  335.  
  336.     inline PointArray(size_t t);
  337.     inline PointArray();
  338.     inline PointArray(const PointArray &P);
  339.     inline PointArray(const std::initializer_list<float> &list);
  340.     inline PointArray(unsigned int nb_point, Point centre,float rayon, float s);
  341.  
  342.     ~PointArray(){cout << "PointArray: Destructeur" << endl;delete [] array;}
  343.     Point& operator[](const unsigned int &a){
  344.         assert(taille < a);//attention il faut arreter l'execution
  345.         return array[a];
  346.     }
  347.     inline void view();
  348.     inline void translation(float a, float b);
  349.     inline void rotate(float rotation);
  350.     inline void scale(float s);
  351. };
  352. //!FIN POINTARRAY.H
  353.  
  354. //!DEBUT POINTARRAY.Cpp
  355.  
  356.     inline PointArray::PointArray(size_t t):taille(t),array(new Point[t]){cout<<"PtArray Ctaille "<<endl;}
  357.     inline PointArray::PointArray():PointArray(def){}
  358.     //J'avais oublié le constructeur par défaut, par conséquent l'allocation mémoire des 10 éléments du tableau ne s'est pas faite, d'ou le segmentation fault
  359.     inline PointArray:: PointArray(const PointArray &P):PointArray(P.taille){
  360.         //memcpy(array,P.array,def*sizeof(Point));On utilise pas memcpy ici c'est uniquement dans le cas d'un BITs (build in type)
  361.         cout << "PointArray Cc" << endl;
  362.         for(size_t i = 0 ; i< P.def ; i++){
  363.             this->array[i] = P.array[i];
  364.         }
  365.     }
  366.     //*******************monvecteur ?
  367.    
  368.     //*******************CONSTRUCTEUR A PARTIR DUNE LISTE DE POINT
  369.     inline PointArray::PointArray(const std::initializer_list<float> &list):PointArray(list.size()/2){// Stratégie : On passe un nombre pair d'int et on les met dans un point qu'on va ranger au fur et a mesure dans le tableau
  370.         //si le nombre passé est impair on fait quoi ?
  371.         //~ cout << " PointArray : Cinittializer_list"<< endl ;
  372.         //~ cout << "taille de tableau "<< list.size() << endl ;
  373.         float* tableau_entier = new float[list.size()];//ou list list.size()
  374.         Point P;
  375.         size_t j=0;
  376.         for(auto &i : list){// le prof veut faire comme ça mais j'ai pas compris, il veut qu'on fasse un tableau dynamique d'int en plus ?
  377.             tableau_entier[j]=i;
  378.             j++;
  379.         }
  380.         for(size_t k=0,j=0;j<list.size(); j=j+2,k++){
  381.             P.setPoint_x(tableau_entier[j]);
  382.             P.setPoint_y(tableau_entier[j+1]);
  383.             this->array[k]=P;
  384.             //cout << array[k] << endl;
  385.         }
  386.        
  387.         //cout << array[i] << endl;//**********
  388.         delete [] tableau_entier;
  389.     }
  390.     //*******************CONSTRUCTEUR A PARTIR  et à partir de: un nombre de points n, un centre c et une taille s qui
  391.     //initialise une liste de n points régulièrement répartis sur un cercle de centre c et de rayon r (à savoir
  392.     //les points Pi du PointsArray sont Pi(x,y) = c + r * ( cos[theta(i)], sin[theta(i)] ) où theta(i) =2.pi/n*i et i est dans {0,1,...,n-1}).
  393.     inline PointArray::PointArray(unsigned int nb_point, Point centre,float rayon, float s):PointArray(nb_point){//********************CONVERSION*********************************************
  394.         Point P;
  395.         float teta;
  396.         for(unsigned int i = 0 ; i < nb_point ; i++ ){
  397.             teta = static_cast<float>(2.f*PI*i)/static_cast<float>(nb_point);
  398.             P.setPoint_x( ( centre.getPoint_x()+rayon ) *cos(teta));//Comment regler le problème ?
  399.             P.setPoint_y( ( centre.getPoint_y()+rayon ) *sin(teta));
  400.             this->array[i] = P;
  401.         }
  402.     }
  403.     inline void PointArray::view(){
  404.         for(size_t i = 0 ; i < taille ; i++){
  405.             cout << array[i] << endl;
  406.         }
  407.     }
  408.     inline void PointArray::translation(float a, float b){
  409.         float x,y;
  410.         for(size_t i = 0; i < taille; i++){
  411.             x=array[i].getPoint_x();
  412.             y=array[i].getPoint_y();
  413.             array[i].setPoint_x(x+a);
  414.             array[i].setPoint_y(y+b);
  415.         }
  416.     }
  417.     inline void PointArray::rotate(float rotation){
  418.         float cx=0,
  419.             cy=0;
  420.         //CALCUL DU CENTRE :(Pour le barycentre ou centre de gravité on fait la moyenne des X et la moyenne des Y)
  421.         for(size_t i = 0; i < taille; i++){
  422.             cx=array[i].getPoint_x()+cx;
  423.             cy=array[i].getPoint_y()+cy;
  424.         }
  425.         cx = cx/static_cast<float>(taille);
  426.         cy = cy/static_cast<float>(taille);
  427.         //CALCUL AVEC CENTRE (0,0)
  428.         Point *tableau= new Point[taille];
  429.         float x,y;
  430.         for(size_t i = 0; i < taille; i++){
  431.             x=array[i].getPoint_x();
  432.             y=array[i].getPoint_y();
  433.             tableau[i].setPoint_x(x*cosf(rotation)-y*cosf(rotation));//cosf() renvoit un float ça évite un static_cast en plus
  434.             tableau[i].setPoint_y(x*cosf(rotation)+y*cosf(rotation));
  435.        
  436.         }
  437.         //On met dans le tableau
  438.         for(size_t i = 0; i < taille ; i++){
  439.             array[i].setPoint_x(cx+tableau[i].getPoint_x()-cx);
  440.             array[i].setPoint_y(cy+tableau[i].getPoint_y()-cx);
  441.         }
  442.         delete [] tableau;
  443.     }
  444.     inline void PointArray::scale(float s){// Scale avec un double serait préférable
  445.         //Calcul du centre
  446.         float cx = 0.f,
  447.             cy = 0.f;
  448.         for(size_t i = 0; i < taille; i++){
  449.             cx=array[i].getPoint_x()+cx;
  450.             cy=array[i].getPoint_y()+cy;
  451.         }
  452.         cx = cx/static_cast<float>(taille);
  453.         cy = cy/static_cast<float>(taille);
  454.         float x,y;
  455.         for(size_t i = 0; i < taille; i++){
  456.             x=array[i].getPoint_x();
  457.             y=array[i].getPoint_y();
  458.             array[i].setPoint_x(cx+s*(x-cx));
  459.             array[i].setPoint_y(cy+s*(y-cy));
  460.         }
  461.        
  462.     }
  463. //!FIN POINTARRAY.CPP
  464.  
  465. //!DEBUT ReallocablePointsArray.h
  466. class ReallocatablePointsArray : public PointArray{
  467.     //Le prof m'a dit que ajouter un champ nombre d'element serait mieux. Pour l'assignation, un exemple R1.taille = 10 R2.taille = 3 si on fait R1 = R2 il va falloir delete un tableau de 10 pour en refaire un de trois alors qu'il y a assez de place pour lui mettre 3 element ! Allocation inutile (Pour un )!
  468.     public:
  469.         inline ReallocatablePointsArray();
  470.         inline ReallocatablePointsArray(size_t taille);
  471.         inline ReallocatablePointsArray(const ReallocatablePointsArray &R);    
  472.         inline ReallocatablePointsArray(unsigned int nb_point, Point centre,float rayon, float s);
  473.         inline ReallocatablePointsArray(const std::initializer_list<float> &list);
  474.         ReallocatablePointsArray& operator =(const ReallocatablePointsArray R){//Ici   
  475.             if(this!=&R){
  476.                 delete [] array;
  477.                 this->taille = R.taille;
  478.                 array = new Point[this->taille];
  479.                 memcpy(array,R.array,R.taille*sizeof(int));
  480.                 //~ for(size_t i = 0 ; i< R.taille ; i++){
  481.                     //~ this->array[i] = R.array[i];
  482.                 //~ }
  483.             }
  484.             return *this;
  485.         }
  486. };
  487. //!FIN ReallocablePointsArray.h
  488. //!DEBUT ReallocablePointsArray.cpp
  489.    
  490.     inline ReallocatablePointsArray::ReallocatablePointsArray():PointArray(){}
  491.     inline ReallocatablePointsArray::ReallocatablePointsArray(size_t taille):PointArray(taille){}//constructeur délégué
  492.     inline ReallocatablePointsArray::ReallocatablePointsArray(const ReallocatablePointsArray &R):PointArray(R.taille){cout << "ReallocablePointArray Cc" << endl;}
  493.     inline ReallocatablePointsArray::ReallocatablePointsArray(unsigned int nb_point, Point centre,float rayon, float s):PointArray(nb_point,centre,rayon,s){}
  494.     inline ReallocatablePointsArray::ReallocatablePointsArray(const std::initializer_list<float> &list):PointArray(list){}
  495.    
  496. //!FIN ReallocablePointsArray.h
  497. //FIN TP4
  498. int main(){
  499.     Color a;
  500.     Color c = Color::red;
  501.     c.view();
  502.     a.view();
  503.     cout << a.getColor() << endl;
  504.     SVGstream S("fichier",0);
  505.     string chaine = "<circle cx=\"100\" cy=\"100\" r=\"75\" fill=\"red\"/>";
  506.     S << chaine << endl;
  507.    
  508.    
  509.     //Geom2D Classe abstraites
  510.     /*Geom2D G;                                     G.info();
  511.     Geom2D G1(1,2);                                 G1.info();
  512.     */
  513.     //FillProperty
  514.     FillProperty F;                                 F.info();
  515.     FillProperty F1(c);                             F1.info();
  516.     FillProperty F2(Color::blue);                   F2.info();
  517.     /*Classe abstraire  
  518.     Surface S1;                                     S1.info();
  519.     Surface S2(500,200,Color::blue);                S2.info();
  520.     */
  521.     //TEST sur objets concrets
  522.     Disc D(600.6f,100,Color::blue,100);             D.info();
  523.     Disc D2(900,100,Color::turquoise,200);          D2.info();
  524.     D.info();
  525.     S << D << endl;
  526.     S << D2 << endl;
  527.     Rectangle R(500,500,400,100,Color::brown);//Rectangle(int x, int y , int h , int l ,const Color& Couleur):Surface(x,y,Couleur),hauteur(h),largeur(l)
  528.     S << R << endl;
  529.     Square carr;
  530.     Square carr2(100,200,50,Color::grey);
  531.     carr2.Rotate(45);
  532.     S << carr << endl;
  533.    
  534.     R.Translate(-100,-100);
  535.     R.info();
  536.     carr2.Translate(50,50);
  537.     R.Scale(2);
  538.     R.Rotate(45);
  539.     S << R << endl;
  540.     S << carr2 << endl;
  541.     //*************************Ouverture écriture sur un fichier les test
  542.     //~ string s = "test2.html";
  543.     //~ ofstream fichier(s, ios::out | ios::trunc); // ouverture en écriture avec effacement du fichier ouvert / OU LE CREER SI EXISTE
  544.     //~
  545.     //~ if(fichier)
  546.     //~ {
  547.         //~ string nom = "Xav57";
  548.         //~ int age = 19;
  549.         //~ fichier << "Date de naissance : " << 24 << '/' << 3 << '/' << 1988 << endl;
  550.         //~ fichier << "Bonjour, " << nom << ". Vous avez " << age << " ans.";
  551.         //~ fichier.close();
  552.     //~ }
  553.     //~ else
  554.         //~ cerr << "Impossible d'ouvrir le fichier !" << endl;
  555.        
  556.     //! TP4
  557.         PointArray A;
  558.     Point P(3,3);
  559.     A[9]= P;
  560.     A[0]=A[9];
  561.  
  562.     PointArray B(A);
  563.     //Affiche A
  564.     cout << "A :" << endl;
  565.     A.view();
  566.     //Affiche B
  567.     cout << "B :" << endl;
  568.     B.view();
  569.  
  570.     ReallocatablePointsArray Rarray(2);
  571.     Rarray[1]=P;
  572.     ReallocatablePointsArray Rarray2(Rarray);
  573.     cout << "Reallocable" << endl;
  574.     cout << "Rarray1" << endl;
  575.     Rarray.view();
  576.     cout << "Rarray2" << endl;
  577.     Rarray2.view();
  578.     cout << "Rarray3" << endl;
  579.     ReallocatablePointsArray Rarray3;Rarray3.view();//taille = 10
  580.  
  581.    
  582.     //test initializer_list
  583.     auto lise = {1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f};
  584.     PointArray Parray(lise);
  585.     cout << "Parray" << endl;
  586.     Parray.view();
  587.     Point point(0,0);
  588.     PointArray Parray2(2,point,10,0);//*******************************//PointArray(size_t nb_point, Point centre,size_t rayon, int s):PointArray(nb_point){
  589.     cout << "Parray2" << endl;
  590.     Parray2.view();
  591.     ReallocatablePointsArray Rarray4(lise);//taille = 4
  592.     cout << "Rarray4" << endl;
  593.     Rarray4.view();
  594.     cout << "Rarray4 avant" << endl;
  595.     Rarray4.view();
  596.     Rarray4=Rarray3;
  597.     cout << "Rarray4 après" << endl;
  598.     Rarray4.view();
  599.    
  600.     return 0;
  601.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement