// --------- // proj2.cpp // --------- // Project 2 of Com S 229 // Due at 11:59pm on Tuesday, Feb 17, 2009 // // Test file #include #include "complexx_soln.h" int main() { // complex number i = 0 + 1i complex i(0, 1), z1, z2; // input values cout << "Enter two complex numbers: "; cin >> z1 >> z2; cout << "Test the binary arithmetic operators:" << endl; cout << " z1 + z2 = " << z1 + z2 << endl; cout << " z1 - z2 = " << z1 - z2 << endl; cout << " z1 * z2 = " << z1 * z2 << endl; cout << " z1 / z2 = " << z1 / z2 << endl << endl; // test relational equality if (z1 == z2) cout << z1 << " = " << z2 << endl; else cout << z1 << " != " << z2 << endl << endl; // evaluate phase and magnitude cout << z1 << "=" << z1.magnitude() << "* (cos (" << z1.phase() << ") + i * sin(" << z1.phase() << "))" << endl; cout << z2 << "=" << z2.magnitude() << "* (cos (" << z2.phase() << ") + i * sin(" << z2.phase() << "))" << endl << endl; // verify that i*i = -1 and that -i * i = 1 cout << "i*i = " << i * i << endl; cout << "-i*i = " << -i * i << endl << endl; // verify powers cout << "10th power of z1 = " << z1.power(10) << endl; cout << "7th power of z2 = " << z2.power(7) << endl << endl; // verify square roots cout << "sqrt(i) = " << i.sqrt() << endl; cout << "sqrt(z1) = " << z1.sqrt() << endl; cout << "sqrt(z2) = " << z2.sqrt() << endl << endl; // test the evaluation function complex z3(2, 3), z4(-1, 1), z5(1, 1), z6(1, -1), z7(1, 0); cout << "f(" << z3 << ") = " << f(z3) << endl; cout << "f(" << z4 << ") = " << f(z4) << endl; cout << "f(" << z5 << ") = " << f(z5) << endl; cout << "f(" << z6 << ") = " << f(z6) << endl; cout << "f(" << z7 << ") = " << f(z7) << endl; return 0; }