How To Return Object
PROGRAM:
- #include<iostream>
-
- using namespace std;
-
- class Complex{
- int x,y;
-
- public:
- void setdata(int a,int b){
- x=a; y=b;
- }
- void showdata(){
- cout<<"\nx = "<<x<<" y = "<<y;
- }
- friend Complex addition(Complex,Complex);
- };
-
- Complex addition(Complex a,Complex b){
- Complex temp;
- temp.x=a.x+b.x;
- temp.y=a.y+b.y;
- return temp;
- }
-
- int main(){
- Complex c1,c2,c3;
- c1.setdata(3,2);
- c2.setdata(2,3);
- cout<<"\n c1:";
- c1.showdata();
- cout<<"\n c2:";
- c2.showdata();
- c3=addition(c1,c2);
- cout<<"\n c3:";
- c3.showdata();
- return 0;
- }
-
-
-
Comments
Post a Comment