Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
25 views2 pages

Friendf

Uploaded by

smyyan.shah7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Friendf

Uploaded by

smyyan.shah7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream.

h>
#include<conio.h>
class calc
{
int a,b;
public:
calc(){
}
calc(int x, int y){
a = x;
b = y;
}
calc sum(calc p, calc q)
{
calc t;
t.a = p.a + q.a;
t.b = p.b + q.b;
return t;
}
void print(){
cout<<a<<"+"<<b<<"i"<<'\n';
}
friend calc diff(calc h, calc g){
calc e;
e.a = h.a - g.a;
e.b = h.b - g.b;
return e;
}
};
int main(){
clrscr();
calc c1(3,4),c2(5,6),c3,c4;
c1.print();
c2.print();
c3=c3.sum(c1,c2);
cout<<"the sum is ";
c3.print();
c4=diff(c2,c1);
cout<<"the difference is ";
c4.print();
getch();
return 0;
}

OUTPUT:
3+4i
5+6i
the sum is 8+10i
the difference is 2+2i

You might also like