1 / 3

Lab Exercise – Complex Numbers

Lab Exercise – Complex Numbers. Venkatesh Ramamoorthy (Venky). Problem statement. Write a Java class complex that implements complex numbers A complex number consists of a real part and an imaginary part. What are your instance variables?

zahur
Download Presentation

Lab Exercise – Complex Numbers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab Exercise – Complex Numbers Venkatesh Ramamoorthy (Venky)

  2. Problem statement • Write a Java class complex that implements complex numbers • A complex number consists of a real part and an imaginary part. What are your instance variables? • Implement the three constructors. What would they be? • Implement the Copy, Equals and Print methods for this class. Two complex numbers (a + ib) and (c + id) are equal if and only if a and b are equal, and also, c and d are equal. • Implement a method add that adds one complex number into another, using the following rule for addition: (a + ib) + (c + id) = (a + c) + i (b + d)

  3. Problem statement (cont’d) • Using a driver program – the main program – test your implementation. • Initialize two complex numbers c1 with 10+20i, and c2 with 30+40i. Add c1 into c2. What will c2 now contain? • Copy c1 into a third variable c3 and add a fourth complex number 15i (=0+15i) to it. What will c3 now contain? • Check if c2 is equal to 40+60i

More Related