Вы находитесь на странице: 1из 3

OPERADORES DE INPUT OUTPUT:

friend ostream &operator<<(ostream &out, Complex c)


{
out<<"real part: "<<c.real<<"\n";
out<<"imag part: "<<c.imag<<"\n";
return out;
}
friend istream &operator>>(istream &in, Complex &c)
{
cout<<"enter real part:\n";
in>>c.real;
cout<<"enter imag part: \n";
in>>c.imag;
return in;
}

//output

//input

OPERADORES BINARIOS (ARITMETICOS)


Box operator+(const Box& b)
{
Box box;
box.length = this->length + b.length;
box.breadth = this->breadth + b.breadth;
box.height = this->height + b.height;
return box;
};
OPERADORES UNARIOS
Distance operator- ()
{
feet = -feet;
inches = -inches;
return Distance(feet, inches);
}
/*TROCA OS SINAIS DAS VARIAVEIS*/
/*LISTA DE OPERADORES UNARIOS
Incremento ++
Decremento -Menos unrio Not logico !
CASO ESPECIAL DOS INCREMENTOS (POUCO IMPORTANTE PARA TESTE)
// overloaded prefix ++ operator
Time operator++ ()
{
++minutes;
// increment this object
if(minutes >= 60)
{
++hours;
minutes -= 60;
}
return Time(hours, minutes);
}
// overloaded postfix ++ operator
Time operator++( int )

{
// save the orignal value
Time T(hours, minutes);
// increment this object
++minutes;
if(minutes >= 60)
{
++hours;
minutes -= 60;
}
// return old original value
return T;
}
OPERADORES RELACIONAIS (<, >, <=, >=, ==, etc.)
bool operator <(const Distance& d)
{
if(feet < d.feet)
{
return true;
}
if(feet == d.feet && inches < d.inches)
{
return true;
}
return false;
}
OPERADOR DE ATRIBUIO (=)
void operator=(const Distance &D )
{
feet = D.feet;
inches = D.inches;
}
OPERADOR DE CHAMADA DE FUNO ()

//POUCO IMPORTANTE PARA TESTE

Distance operator()(int a, int b, int c)


{
Distance D;
// just put random calculation
D.feet = a + c + 10;
D.inches = b + c + 100 ;
return D;
}
OPERADOR SUBSCRIPT []

//POUCO IMPORTANTE

int &operator[](int i)
{
if( i > SIZE )
{
cout << "Index out of bounds" <<endl;
// return first element.
return arr[0];
}
return arr[i];

Вам также может понравиться