Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Ensemble
- {
- private:
- int *tab;
- int taille;
- int nbEffe;
- public:
- Ensemble(int taille=0)
- {
- this->taille = taille;
- if(taille)
- tab = new int[taille];
- nbEffe = 0;
- }
- Ensemble(const Ensemble &E)
- {
- taille = E.taille;
- nbEffe = E.nbEffe;
- tab = new int[taille];
- for (int i = 0; i < taille; i++)
- tab[i] = E.tab[i];
- }
- bool estvidde() const
- {
- return nbEffe == 0;
- }
- int cardinal() const
- {
- return nbEffe;
- }
- friend ostream &operator<<(ostream &flux, const Ensemble &E);
- friend istream &operator>>(istream &flux, Ensemble &E);
- virtual void operator+(int a)
- {
- int i;
- for (i = 0; i < nbEffe && tab[i] != a; i++);
- if (i == nbEffe)
- tab[nbEffe++] = a;
- }
- bool operator>(int a)
- {
- if(!this->estvidde())
- {
- int i;
- for (i = 0; i < nbEffe && tab[i] != a; i++);
- return !(i == nbEffe);
- }
- else
- return false;
- }
- bool operator>(const Ensemble& E)
- {
- if(!this->estvidde() || !E.estvidde() )
- {
- int cpt = 0;
- for (int i = 0; i < E.nbEffe; i++)
- {
- if (*this > E.tab[i])
- cpt++;
- }
- return cpt == E.nbEffe;
- }else
- return false;
- }
- void triCroissant()
- {
- int cpt, tmp;
- do{
- cpt = 0;
- for (int i = 0; i < taille; i++)
- {
- if (tab[i] > tab[i + 1])
- {
- tmp = tab[i];
- tab[i] = tab[i + 1];
- tab[i + 1] = tmp;
- cpt++;
- }
- }
- } while (cpt > 0);
- }
- void triDeCroissant()
- {
- int cpt, tmp;
- do{
- cpt = 0;
- for (int i = 0; i < taille; i++)
- {
- if (tab[i] < tab[i + 1])
- {
- tmp = tab[i];
- tab[i] = tab[i + 1];
- tab[i + 1] = tmp;
- cpt++;
- }
- }
- } while (cpt > 0);
- }
- virtual Ensemble operator+(const Ensemble &E)
- {
- if(this->estvidde())
- return E;
- else if(E.estvidde())
- return *this;
- else
- {
- int a = this->cardinal();
- int b = E.cardinal();
- Ensemble *newE = new Ensemble(a + b);
- newE->nbEffe = a;
- for (int i = 0; i < a; i++)
- newE->tab[i] = this->tab[i];
- for (int i = 0; i < b; i++)
- {
- if (!(*newE > E.tab[i]))
- newE->tab[newE->nbEffe++] = E.tab[i];
- }
- return *newE;
- }
- }
- };
- istream& operator>>(istream &flux, Ensemble &E)
- {
- }
- ostream& operator<<(ostream &flux, const Ensemble &E)
- {
- if(!E.estvidde())
- {
- for (int i = 0; i < E.nbEffe; i++)
- {
- flux << E.tab[i] << " ";
- }
- return flux;
- }
- }
- class derive : class Ensemble
- {
- private:
- int indice;
- public:
- derive(int taille=0, int indice=-1) : Ensemble(taille), this->indice(indice) //indice = 1 -> croissant
- {
- if(indice==1)
- Ensemble::triCroissant();
- else
- Ensemble::triDeCroissant();
- }
- derive(const derive& e) : Ensemble(e), indice(e.indice)
- {
- if(indice==1)
- Ensemble::triCroissant();
- else
- Ensemble::triDeCroissant();
- }
- void operator+(int a)
- {
- Ensemble::operator+(a);
- if(indice==1)
- Ensemble::triCroissant();
- else
- Ensemble::triDeCroissant();
- }
- derive operator+(const derive& d)
- {
- //Ensemble d=d;
- Ensemble::operator+(d);
- if(indice==1)
- Ensemble::triCroissant();
- else
- Ensemble::triDeCroissant();
- return *this;
- }
- };
- int main()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement