ComplexDemo - cout << c1.show() << " +...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Sample Complex number class demonstration. Author: Eric Van Wyk Date: March 30, 2010 */ #include <iostream> #include "Complex.h" using namespace std ; int main() { cout << "Complex numbers" << endl ; Complex c1(4.0, 2.11) ; cout << "c1 = " << c1.show() << endl ; Complex c2(5.0, 3.44); cout << "c2 = " << c2.show() << endl ; // adding and multiplying with destructive methods. cout << "Adding " << c1.show() << " to " << c2.show() << " (using addTo)" << endl ; c1.addTo(c2) ; cout << "This yields " << c1.show() << endl ; cout << "Mutiplying " << c1.show() << " by " << c2.show() << " (using multiplyBy)" << endl ; c1.multiplyBy(c2) ; cout << "This yields " << c1.show() << endl ; cout << "Testing equality. " << endl ; Complex c3(c1) ; if (c1.equals(c2)) cout << c1.show() << " == " << c2.show() << endl ; else cout << c1.show() << " != " << c2.show() << endl ; if (c1.equals(c3)) cout << c1.show() << " == " << c3.show() << endl ; else cout << c1.show() << " != " << c3.show() << endl ; // adding and multiplying with constructive methods.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout << c1.show() << " + " << c2.show() << " is " << c1.add(c2).show() << " (using add)" << endl ; cout << c1.show() << " * " << c2.show() << " is " << c1.multiply(c2).show() << " (using multiply)" << endl ; cout << c1.show() << " + " << c2.show() << " is " << (c1 + c2 ).show() << " (using operator +)" << endl ; cout << c1.show() << " * " << c2.show() << " is " << (c1 * c2).show() << " (using operator *)" << endl ; Complex c4(c1) ; if (c1 == c2 + c3 * c4) cout << c1.show() << " == " << (c2+c3*c4).show() << endl ; else cout << c1.show() << " != " << (c2+c3*c4).show() << endl ; if (c1 == c4) cout << c1.show() << " == " << c4.show() << endl ; else cout << c1.show() << " != " << c4.show() << endl ; cout << "c5 - for type conversion)" << endl; Complex c5(3.14) ; cout << c5.show() << endl ; c5 = c5 + 4.3 ; // c5 = 1.3 + c5 ; cout << c5.show() << endl ; cout << c5 << endl ; cout << "End of the program. .." << endl ; }...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Page1 / 2

ComplexDemo - cout << c1.show() << " +...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online