Advertisement
Guest User

aa

a guest
Jan 22nd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Ensemble
  4. {
  5. private:
  6.     int *tab;
  7.     int taille;
  8.     int nbEffe;
  9. public:
  10.     Ensemble(int taille=0)
  11.     {
  12.         this->taille = taille;
  13.         if(taille)
  14.             tab = new int[taille];
  15.         nbEffe = 0;
  16.     }
  17.  
  18.     Ensemble(const Ensemble &E)
  19.     {
  20.         taille = E.taille;
  21.         nbEffe = E.nbEffe;
  22.         tab = new int[taille];
  23.         for (int i = 0; i < taille; i++)
  24.             tab[i] = E.tab[i];
  25.     }
  26.  
  27.     bool estvidde() const
  28.     {
  29.         return nbEffe == 0;
  30.     }
  31.  
  32.     int cardinal() const
  33.     {
  34.         return nbEffe;
  35.     }
  36.  
  37.     friend ostream &operator<<(ostream &flux, const Ensemble &E);
  38.     friend istream &operator>>(istream &flux, Ensemble &E);
  39.  
  40.     virtual void operator+(int a)
  41.     {
  42.         int i;
  43.         for (i = 0; i < nbEffe && tab[i] != a; i++);
  44.         if (i == nbEffe)
  45.             tab[nbEffe++] = a;
  46.     }
  47.  
  48.     bool operator>(int a)
  49.     {
  50.         if(!this->estvidde())
  51.         {
  52.         int i;
  53.         for (i = 0; i < nbEffe && tab[i] != a; i++);
  54.         return !(i == nbEffe);
  55.         }
  56.         else
  57.             return false;
  58.        
  59.     }
  60.  
  61.     bool operator>(const Ensemble& E)
  62.     {
  63.         if(!this->estvidde() || !E.estvidde() )
  64.         {
  65.         int cpt = 0;
  66.         for (int i = 0; i < E.nbEffe; i++)
  67.         {
  68.             if (*this > E.tab[i])
  69.                 cpt++;
  70.         }
  71.         return cpt == E.nbEffe;
  72.         }else
  73.             return false;
  74.     }
  75.  
  76.     void triCroissant()
  77.     {
  78.         int cpt, tmp;
  79.         do{
  80.             cpt = 0;
  81.             for (int i = 0; i < taille; i++)
  82.             {
  83.                 if (tab[i] > tab[i + 1])
  84.                 {
  85.                     tmp = tab[i];
  86.                     tab[i] = tab[i + 1];
  87.                     tab[i + 1] = tmp;
  88.                     cpt++;
  89.                 }
  90.             }
  91.         } while (cpt > 0);
  92.     }
  93.  
  94.     void triDeCroissant()
  95.     {
  96.         int cpt, tmp;
  97.         do{
  98.             cpt = 0;
  99.             for (int i = 0; i < taille; i++)
  100.             {
  101.                 if (tab[i] < tab[i + 1])
  102.                 {
  103.                     tmp = tab[i];
  104.                     tab[i] = tab[i + 1];
  105.                     tab[i + 1] = tmp;
  106.                     cpt++;
  107.                 }
  108.             }
  109.         } while (cpt > 0);
  110.     }
  111.  
  112.     virtual Ensemble operator+(const Ensemble &E)
  113.     {
  114.         if(this->estvidde())
  115.             return E;
  116.         else if(E.estvidde())
  117.             return *this;
  118.         else
  119.         {
  120.         int a = this->cardinal();
  121.         int b = E.cardinal();
  122.         Ensemble *newE = new Ensemble(a + b);
  123.         newE->nbEffe = a;
  124.         for (int i = 0; i < a; i++)
  125.             newE->tab[i] = this->tab[i];
  126.         for (int i = 0; i < b; i++)
  127.         {
  128.             if (!(*newE > E.tab[i]))
  129.                 newE->tab[newE->nbEffe++] = E.tab[i];
  130.         }
  131.         return *newE;
  132.         }
  133.     }
  134. };
  135.  
  136. istream& operator>>(istream &flux, Ensemble &E)
  137. {
  138.    
  139. }
  140.  
  141. ostream& operator<<(ostream &flux, const Ensemble &E)
  142. {
  143.     if(!E.estvidde())
  144.     {
  145.     for (int i = 0; i < E.nbEffe; i++)
  146.     {
  147.         flux << E.tab[i] << " ";
  148.     }
  149.     return flux;
  150.     }
  151. }
  152.  
  153. class derive : class Ensemble
  154. {
  155.     private:
  156.         int indice;
  157.     public:
  158.         derive(int taille=0, int indice=-1) : Ensemble(taille), this->indice(indice) //indice = 1 -> croissant
  159.         {
  160.             if(indice==1)
  161.                 Ensemble::triCroissant();
  162.             else
  163.                 Ensemble::triDeCroissant();
  164.            
  165.         }
  166.  
  167.         derive(const derive& e) : Ensemble(e), indice(e.indice)
  168.         {
  169.             if(indice==1)
  170.                 Ensemble::triCroissant();
  171.             else
  172.                 Ensemble::triDeCroissant();
  173.         }
  174.  
  175.         void operator+(int a)
  176.         {
  177.             Ensemble::operator+(a);
  178.             if(indice==1)
  179.                 Ensemble::triCroissant();
  180.             else
  181.                 Ensemble::triDeCroissant();
  182.         }
  183.  
  184.         derive operator+(const derive& d)
  185.         {
  186.             //Ensemble d=d;
  187.             Ensemble::operator+(d);
  188.             if(indice==1)
  189.                 Ensemble::triCroissant();
  190.             else
  191.                 Ensemble::triDeCroissant();
  192.             return *this;
  193.         }
  194.  
  195. };
  196.  
  197. int main()
  198. {
  199.  
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement