#include <iostream>
#include <cstdlib>

using namespace std;

class conjunto {
    private:
        int c;

    public:
        conjunto(int co= 0);
        conjunto& operator += (int k);
        int bits(void) const;
        ostream&  print(ostream& os)  const;
        int Card(void) const;
};


conjunto::conjunto(int co)
{
    c= co;
}

conjunto& conjunto::operator += (int k)
{
    c|= 1 << k;
}

int conjunto::bits(void) const
{
   return c;
}


ostream& conjunto::print(ostream& os) const
{
    int s= 8*sizeof(c);
    os << "{";
    for (int k=0; k<s; k++) 
       if ( ((1 << k) & c) != 0)
          os << ' ' << k;
    os << " }";
    return os;
}

ostream& operator << (ostream& os, 
                      const conjunto& c)
{
   return c.print(os);
}

conjunto operator + (const conjunto& A,
                     const conjunto& B)
{
   return conjunto(A.bits() | B.bits()); 
}

conjunto operator * (const conjunto& A,
                     const conjunto& B)
{
   return conjunto(A.bits() & B.bits()); 
}

int conjunto::Card(void) const
{
    int s= 8*sizeof(c);
    int ca= 0;
    for (int k=0; k<s; k++) 
       if ( ((1 << k) & c) != 0)
          ca++;
    return ca;
}


int main()
{
    conjunto A, B;

    A+= 8;
    A+= 4;
    A+= 21;

    B+= 15;
    B+= 4;
    B+= 22;

    cout << "A= " << A << endl;
    cout << "B= " << B << endl;
    cout << "A union B= " << A+B << endl;
    cout << "A inter B= " << A*B << endl;

    return EXIT_SUCCESS;
}








