You are on page 1of 2

My Int Class

============================================
#include <iostream.h>
class MyInt{
public:

MyInt()
{
data=0;
}

MyInt(int d)
{
data=d;
}

void setData(int d)
{
data=d;
}

int getData()
{
return data;
}

MyInt Plus(MyInt p)
{
p.setData(data+p.getData());
return p;
}

int Plus(int p)
{
p=p+data;
return p;
}

private:
int data;
};

void main()
{
MyInt a(2),b(3),c;
c=a.Plus(b);
cout<<"Sum = "<<c.getData()<<endl; // Output Sum= 5
c=a.Plus(10);
cout<<"Sum = "<<c.getData()<<endl; // Output Sum= 12
}

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