Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMPUTER 2430 Object Oriented Programming and Data Structures I

Similar presentations


Presentation on theme: "COMPUTER 2430 Object Oriented Programming and Data Structures I"— Presentation transcript:

1 COMPUTER 2430 Object Oriented Programming and Data Structures I

2 Complex Numbers Real numbers Imaginary numbers 5i i = i * i = -1
a + bi, where both a and b are real numbers -2 -1 1 2

3 Complex Numbers b a a + bi

4 Operations on Complex Numbers
(a1 + b1i) + (a2 + b2i) = (a1 + a2) + (b1 + b2)i (a1 + b1i) - (a2 + b2i) = (a1 - a2) + (b1 - b2)i (a1 + b1i) * (a2 + b2i) = (a1 * a2 - b1 * b2) + (a1 * b2 + a2 * b1)i (a1 + b1i) / (a2 + b2i) = ((a1 + b1i) * (a2 - b2i)) / ((a2 + b2i) * (a2 - b2i)) (a2 + b2i) * (a2 - b2i) = (a2 * a2 + b2 * b2) Conjugate of a + bi is a – bi Magnitude of a + bi is

5 Complex Numbers b a a + bi

6 ADT: Complex Number Data Two double (float): real and imag
String representation (real, imag) Could be a + bi Or other formats

7 Complex Class public class Complex { private double real, imag;
public Complex() // Default constructor real = imag = 0.0; } public Complex( Complex z ) // Copy constructor real = z.real; // this.real = z.real; imag = z.imag; // this.imag = z.imag; ...

8 More Constructors public class Complex { private double real, imag;
... public Complex( double realPart, double imagPart ) real = realPart; imag = imagPart; } public Complex( double realPart ) imag = 0.0;

9 public class Complex { private double real, imag; public Complex( double realPart, double imagPart ) real = realPart; imag = imagPart; } /** Does not change either instance, this or parameter z. Usage: z3 = z1.plus(z2); */ public Complex plus ( Complex z ) return new Complex( real + z.real, imag + z.imag );

10 public class Complex { private double real, imag; public Complex( double realPart, double imagPart ) . . . } /** Does not change either instance, this or parameter z. */ public Complex plus ( Complex z ) return new Complex( this.real + z.real, this.imag + z.imag );

11 Override Method toString
public class Complex { private double real, imag; ... /** Example: (3.4, 12.8) */ @Override public String toString() return "(" + real + ", " + imag + ")"; }

12 Override Method equals
public class Complex { private double real, imag; @Override public boolean equals ( ? ) }

13 Override Method equals
public class Complex { private double real, imag; @Override public boolean equals ( Object obj ) if ( obj instanceof Complex ) Complex temp = (Complex) obj; return (real == temp.real && imag == temp.imag); } return false;

14 public class Complex { private double real, imag; . . . public Complex divides ( Complex z ) public Complex conjugate() public double magnitude() public boolean lessThan( Complex z ) public boolean hasSameMagnitude( Complex z ) }

15 Test 1 Wednesday, October 10 Note01 - Note14 50 points

16 Program 2 Due 10 pm, October 5 Follow instructions
-1 by 10 pm, October 6 -5 by 10 pm, October 8 Follow instructions Individual Assignment Do it yourself!

17 Program 3 Due Wednesday, October 24 Lab 4 Lab 5 Part of Prog3
Due 10 pm, Monday, October 15 Lab 5 Due 10 pm, Wednesday, October 17


Download ppt "COMPUTER 2430 Object Oriented Programming and Data Structures I"

Similar presentations


Ads by Google