Prog 32 Write a Program for the addition of two integer value using returning object.
#include<iostream.h>
#include<conio.h>
class value
{
public:
int x,y;
void getdata(int a,int b)
{
x=a;
y=b;
}
void display()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
friend value sum(value,value);
};
value sum(value v1,value v2)
{
value v3;
v3.x=v1.x+v2.x;
v3.y=v1.y+v2.y;
return v3;
}
void main()
{
clrscr();
value A,B,C;
A.getdata(5,10);
B.getdata(10,15);
C=sum(A,B);
A.display();
B.display();
C.display();
getch();
}
Output:
x = 5
y = 10 x = 10 y = 15 x = 15 y = 25
No comments:
Post a Comment