Practical 18
#include<iostream>
using namespace std;
class Gajjar
{
float x,y;
public:
Gajjar()
{}
Gajjar(float a)
{
x=y=a;
}
Gajjar(float real,float imag)
{
x=real;
y=imag;
}
friend Gajjar sum(Gajjar,Gajjar);
friend Gajjar show(Gajjar);
};
using namespace std;
class Gajjar
{
float x,y;
public:
Gajjar()
{}
Gajjar(float a)
{
x=y=a;
}
Gajjar(float real,float imag)
{
x=real;
y=imag;
}
friend Gajjar sum(Gajjar,Gajjar);
friend Gajjar show(Gajjar);
};
Gajjar sum(Gajjar k1,Gajjar k2)
{
Gajjar k3;
k3.x = k1.x + k2.x;
k3.y = k1.y + k2.y;
return (k3);
}
void show(Gajjar k)
{
cout<<k.x<<" + j"<<k.y<<endl;
}
int main()
{
Gajjar A(2.7,3.5);
Gajjar B(1.6);
Gajjar C;
C = sum(A,B);
cout<<"A = ";
show(A);
cout<<"B = ";
show(B);
cout<<"C = ";
show(C);
return 0;
}
output:
A : 2.7 + j3.5
B : 1.6 + j1..6
C : 4.3 + j5.1
{
Gajjar k3;
k3.x = k1.x + k2.x;
k3.y = k1.y + k2.y;
return (k3);
}
void show(Gajjar k)
{
cout<<k.x<<" + j"<<k.y<<endl;
}
int main()
{
Gajjar A(2.7,3.5);
Gajjar B(1.6);
Gajjar C;
C = sum(A,B);
cout<<"A = ";
show(A);
cout<<"B = ";
show(B);
cout<<"C = ";
show(C);
return 0;
}
output:
A : 2.7 + j3.5
B : 1.6 + j1..6
C : 4.3 + j5.1
No comments:
Post a Comment