COMPUTER 2430 Object Oriented Programming and Data Structures I

Slides:



Advertisements
Similar presentations
Complex Numbers.
Advertisements

Engineering Problem Solving With C++ An Object Based Approach Additional Topics Chapter 10 Programming with Classes.
1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
Introduction to Programming Lecture 31. Operator Overloading.
Classes we can write our own classes – to represent and define our objects e.g. class for Complex objects represents a complex number defines its properties.
Java Syntax Primitive data types Operators Control statements.
ADT Specification Example
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Warm-upAnswers Compute (in terms of i) _i, -1, -i, 1.
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
CS1101: Programming Methodology Aaron Tan.
Non-static classes Part 2 1. Methods  like constructors, all non-static methods have an implicit parameter named this  for methods, this refers to the.
1 Object Oriented Programming Lecture II Classes, Objects, Abstract Data Types, Representation Invariants, Mutables and Immutables.
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
Review – Final Test Chapters 8,10,11. Locate error in following statement try i = Integer.pareseInt(str); catch(NumberFormatException e) System.out.println(“Input.
CLASSES Python Workshop. Introduction  Compared with other programming languages, Python’s class mechanism adds classes with a minimum of new syntax.
Overriding toString()
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Chapter 11 Friends and Overloaded Operators. Introduction to function equal // Date.h #ifndef _DATE_H_ #define _DATE_H_ class CDate { public: CDate();
Non-static classes 1.  a utility class has features (fields and methods) that are all static  all features belong to the class  therefore, you do not.
CS1020 Data Structures and Algorithms I Lecture Note #9 Abstract Data Type (The Walls)
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
 Write the expression as a complex number in standard form.  1.) (9 + 8i) + (8 – 9i)  2.) (-1 + i) – (7 – 5i)  3.) (8 – 5i) – ( i) Warm Up.
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
2.1 Complex Numbers. The Imaginary Unit Complex Numbers the set of all numbers in the form with real numbers a and b; and i, (the imaginary unit), is.
Precalculus Section 1.5 Perform basic operations with complex numbers The basic imaginary unit is i. i = i 2 = -1 A complex number is any number that can.
6.6 – Complex Numbers Complex Number System: This system of numbers consists of the set of real numbers and the set of imaginary numbers. Imaginary Unit:
The imaginary unit i is defined as Furthermore.
More constructors 1. Constructors  recall that a public constructor is what a client uses to create an object  the purpose of a constructor is to initialize.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
Operator Overloading What is operator overloading? Most predefined operators (arithmetic, logic, etc.) in C++ can be overloaded when applied to objects.
Algebra Operations with Complex Numbers. Vocabulary Imaginary Number i -
COMPUTER 2430 Object Oriented Programming and Data Structures I
Chapter 12 Classes and Abstraction
COMPUTER 2430 Object Oriented Programming and Data Structures I
Haidong Xue Summer 2011, at GSU
CSC 205 Java Programming II
COMPUTER 2430 Object Oriented Programming and Data Structures I
Complex Numbers.
Data Types & Operations
5.6 Complex Numbers.
Operations with Complex Numbers
COMPUTER 2430 Object Oriented Programming and Data Structures I
Section 5.9.B Complex Numbers.
COMPUTER 2430 Object Oriented Programming and Data Structures I
CS 302 Week 11 Jim Williams, PhD.
Classes and Data Abstraction
CSC 113: Computer programming II
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
ITunes Lab Copyright © 2012 Pearson Education, Inc.
COMPUTER 2430 Object Oriented Programming and Data Structures I
© A+ Computer Science - OOP © A+ Computer Science -
Chapter 11 Inheritance and Polymorphism
Section 4.6 Complex Numbers
CS139 October 11, 2004.
College Algebra Chapter 1 Equations and Inequalities
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
1.2 Adding And Subtracting Complex Numbers
1.2 Adding And Subtracting Complex Numbers
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
Methods, Data and Data Types
COMPUTER 2430 Object Oriented Programming and Data Structures I
Presentation transcript:

COMPUTER 2430 Object Oriented Programming and Data Structures I

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

Complex Numbers b a a + bi

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

Complex Numbers b a a + bi

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

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; ...

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;

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 );

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 );

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

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

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;

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 ) }

Test 1 Wednesday, October 10 Note01 - Note14 50 points

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!

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