You are on page 1of 3

My Bool Operator

============================================

#include <iostream.h>
enum Status{False,True};
class MyBool{
public:

MyBool(){}

Status getStatus();

void operator=(Status s);


Status operator&&(MyBool s);
Status operator||(MyBool s);
Status operator==(MyBool s);
Status operator!=(MyBool s);
Status operator! ();

private:
Status data;
};

Status MyBool::getStatus()
{
return data;
}
void MyBool::operator=(Status s)
{
data=s;
}
Status MyBool::operator&&(MyBool s)
{
if(data && s.data)
return True;
else
return False;
}
Status MyBool::operator||(MyBool s)
{
if(data || s.data)
return True;
else
return False;
}
Status MyBool::operator==(MyBool s)
{
if(data == s.data)
return True;
else
return False;
}
Status MyBool::operator!=(MyBool s)
{
if(data != s.data)
return True;
else
return False;
}
Status MyBool::operator!()
{
if(!data)
return True;
else
return False;
}
void main(){
MyBool a,b;
a=True;
b=False;
cout<<"\n\n======== Result of && operator
========\n";
if(a&&b)
cout<<"\n\t\tTrue";
else
cout<<"\n\t\tFalse";
cout<<"\n\n======== Result of || operator
========\n";
if(a||b)
cout<<"\n\t\tTrue";
else
cout<<"\n\t\tFalse";
cout<<"\n\n======== Result of == operator
========\n";
if(a==b)
cout<<"\n\t\tTrue";
else
cout<<"\n\t\tFalse";
cout<<"\n\n======== Result of != operator
========\n";
if(a!=b)
cout<<"\n\t\tTrue";
else
cout<<"\n\t\tFalse";
cout<<"\n\n======== Result of ! operator ========\n";
if(!b)
cout<<"\n\t\tTrue";
else
cout<<"\n\t\tFalse";
cout<<endl<<endl;
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006