class prog9
{
int real, imag;
prog9(int r, int i)
{
real=r;
imag=i;
}
public static prog9 add(prog9 c1, prog9 c2)
{
prog9 temp = new prog9(0,0);
temp.real=c1.real+c2.real;
temp.imag=c1.imag+c2.imag;
return(temp);
}
public static prog9 mul(prog9 c1, prog9 c2)
{
prog9 temp = new prog9(0,0);
temp.real=c1.real*c2.real;
temp.imag=c1.imag*c2.imag;
return(temp);
}
public static prog9 sub(prog9 c1, prog9 c2)
{
prog9 temp = new prog9(0,0);
temp.real=c1.real-c2.real;
temp.imag=c1.imag-c2.imag;
return(temp);
}
public static void main(String args[])
{
prog9 obj1 = new prog9(1,2),
obj2 = new prog9(1,2),
temp;
temp = add(obj1,obj2);
System.out.println(temp.real+"."+temp.imag);
temp = mul(obj1,obj2);
System.out.println(temp.real+"."+temp.imag);
temp = sub(obj1,obj2);
System.out.println(temp.real+"."+temp.imag);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.