Print? /*
* Copyright and version Declaration of the program
* Copyright (c) 2012, a student from the computer College of Yantai University
* All rightsreserved.
* File name: x. cpp
* Author: Xu Benxi
* Completion date: January 1, March 24, 2013
* Version: v1.0
* Input description:
* Problem description:
* Program output:
*/
// My code:
# Include <iostream>
Using namespace std;
Class Complex
{Public:
Complex () {real = 0; imag = 0 ;}
Complex (double r, double I) {real = r; imag = I ;}
Complex operator + (Complex & c2 );
Complex operator-(Complex & c2 );
Complex operator * (Complex & c2 );
Complex operator/(Complex & c2 );
Void display ();
Private:
Double real;
Double imag;
};
Complex: operator + (Complex & c2)
{
Return Complex (this-> real + c2.real, this-> imag + c2.imag );
}
Complex: operator-(Complex & c2)
{
Return Complex (this-> real-c2.real, this-> imag-c2.imag );
}
Complex: operator * (Complex & c2)
{
Complex c;
C. real = real * c2.real-imag * c2.imag;
C. imag = imag * c2.real + imag * c2.imag;
Return c;
}
Complex: operator/(Complex & c2)
{
Complex c;
C. real = (real * c2.real + imag * c2.imag)/(c2.real * c2.real + c2.imag * c2.imag );
C. imag = (imag * c2.real-real * c2.imag)/(c2.real * c2.real + c2.imag * c2.imag );
Return c;
}
Void Complex: display ()
{
Cout <"(" <real <"," <imag <"I)" <endl;
}
Int main ()
{
Complex c1 (2, 3), c2 (3,-4), c3;
Cout <"c1 = ";
C1.display ();
Cout <"c2 = ";
C2.display ();
C3 = c1 + c2;
Cout <"c1 + c2 = ";
C3.display ();
C3 = c1-c2;
Cout <"c1-c2 = ";
C3.display ();
C3 = c1 * c2;
Cout <"c1 * c2 = ";
C3.display ();
C3 = c1/c2;
Cout <"c1/c2 = ";
C3.display ();
Return 0;
}
/*
* Copyright and version Declaration of the program
* Copyright (c) 2012, a student from the computer College of Yantai University
* All rightsreserved.
* File name: x. cpp
* Author: Xu Benxi
* Completion date: January 1, March 24, 2013
* Version: v1.0
* Input description:
* Problem description:
* Program output:
*/
// My code:
# Include <iostream>
Using namespace std;
Class Complex
{Public:
Complex () {real = 0; imag = 0 ;}
Complex (double r, double I) {real = r; imag = I ;}
Complex operator + (Complex & c2 );
Complex operator-(Complex & c2 );
Complex operator * (Complex & c2 );
Complex operator/(Complex & c2 );
Void display ();
Private:
Double real;
Double imag;
};
Complex: operator + (Complex & c2)
{
Return Complex (this-> real + c2.real, this-> imag + c2.imag );
}
Complex: operator-(Complex & c2)
{
Return Complex (this-> real-c2.real, this-> imag-c2.imag );
}
Complex: operator * (Complex & c2)
{
Complex c;
C. real = real * c2.real-imag * c2.imag;
C. imag = imag * c2.real + imag * c2.imag;
Return c;
}
Complex: operator/(Complex & c2)
{
Complex c;
C. real = (real * c2.real + imag * c2.imag)/(c2.real * c2.real + c2.imag * c2.imag );
C. imag = (imag * c2.real-real * c2.imag)/(c2.real * c2.real + c2.imag * c2.imag );
Return c;
}
Void Complex: display ()
{
Cout <"(" <real <"," <imag <"I)" <endl;
}
Int main ()
{
Complex c1 (2, 3), c2 (3,-4), c3;
Cout <"c1 = ";
C1.display ();
Cout <"c2 = ";
C2.display ();
C3 = c1 + c2;
Cout <"c1 + c2 = ";
C3.display ();
C3 = c1-c2;
Cout <"c1-c2 = ";
C3.display ();
C3 = c1 * c2;
Cout <"c1 * c2 = ";
C3.display ();
C3 = c1/c2;
Cout <"c1/c2 = ";
C3.display ();
Return 0;
}