/** A class for complex numbers. C.A. Bertulani 06/12/2000 */ #include #include #include "complex_exceptions.h" #include "Complex3.h" void main() { try { cout << "Complex()" << endl; Complex c1; cout << c1 << endl; cout << endl; cout << "Complex( 2.0, 3.0)" << endl; Complex c2( 2.0, 3.0); cout << c2 << endl; cout << endl; cout << "2,3 + 3,4 = 5,7" << endl; Complex c3( 3.0, 4.0); c1 = c2 + c3; cout << c1 << endl; cout << endl; cout << "2,3 - 3,4 = -1,-1" << endl; c1 = c2 - c3; cout << c1 << endl; cout << endl; cout << "2,3 * 3,4 = -6,17" << endl; c1 = c2 * c3; cout << c1 << endl; cout << endl; cout << "2,3 * 3 = 6,9" << endl; c1 = c2 * 3.0; cout << c1 << endl; cout << endl; cout << "2,3 / 3 = 0.67,1" << endl; c1 = c2 / 3.0; cout << c1 << endl; cout << endl; cout << "testing operator ==" << endl; c1 = c3; if (c1 == c3 && !(c2 == c3)) cout << "passed == test" << endl; else cout << "did not pass == test" << endl; cout << endl; cout << "testing operator !=" << endl; c1 = c3; if (!(c1 != c3) && c2 != c3) cout << "passed != test" << endl; else cout << "did not pass != test" << endl; cout << endl; cout << "testing get methods" << endl; cout << "for " << c1 << endl; cout << "\tthe real part is " << c1.getReal() << endl; cout << "\tthe imaginary part is " << c1.getImaginary() << endl; cout << endl; cout << "testing set methods" << endl; cout << "before sets the values is " << c1 << endl; cout << "setting to 5.0 + 7.0i" << endl; c1.setReal( 5.0); c1.setImaginary( 7.0); cout << c1 << endl; cout << "setting another to 1.5 + 2.3i" << endl; c2.set( 1.5, 2.3); cout << c2 << endl; cout << endl; cout << "testing operator>>" << endl; ifstream inFile("complexInput.data"); if (!inFile) throw Exception("input test file not found"); inFile >> c1; cout << "file contains " << c1 << endl; cout << endl; } catch( Exception& e) { cout << e << endl; } catch(...) { cout << "caught unknown exception type" << endl; } }