1

BINARY OPERATOR OVERLOADING #include #include class number { private: int a,b,c; public: void get(); void display(); number operator-(number); number operator+(number); number operator*(number); number operator/(number); }; void number::get() { cout<<"Enter a,b,c values:"; cin>>a>>b>>c; } void number::display() { cout<<"A:"<
2

r.c=c/q.c; return r; } number number::operator-(number t) { number d; d.a=a-t.a; d.b=b-t.b; d.c=c-t.c; return d; } main() { clrscr(); number x,y,z,h,b,k; x.get(); y.get(); clrscr(); cout<<"First Operand\n"; x.display(); cout<<"Second Operand\n"; y.display(); cout<<"Operator overloading\n"; cout<<"Subtract Two Object\n"; z=x-y; z.display(); cout<<"Add Two Object\n"; h=x+y; h.display(); cout<<"Multiply Two Object\n"; b=x*y; b.display(); cout<<"Divide Two Object\n"; k=x/y; k.display(); getch(); return 0; } OUTPUT:

Enter a,b,c values:10 20 30 Enter a,b,c values:2 4 6

3

First Operand A:10 B:20 C:30 Second Operand A:2 B:4 C:6 Operator overloading Subtract Two Object A:8 B:16 C:24 Add Two Object A:12 B:24 C:36 Multiply Two Object A:20 B:80 C:180 Divide Two Object A:5 B:5 C:5

BINARY OPERATOR OVERLOADING.pdf

Sign in. Loading… Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying.

115KB Sizes 1 Downloads 317 Views

Recommend Documents

No documents