EECS 12 Summer 2006 Homework 6

General Instructions

Please place your programs in seperate files named as described in the problem. Improperly named programs will not count. Turn in your files by placing them in the dropbox. Please be mindful of the late policy.




Problem 0: 50 points

Modify your program from 5.0:

Problem 1: 50 points

Create a class for managing complex numbers. If you do not remember the mechanics of complex arithmatic, you can remind yourself by searching for complex on Your file should be called and your class should be called Complex. (There is already a python type called complex, but please do not make use of it. Imagine that you are programming the offical python complex class.)

Include the following methods:

Include the following test code:

print Complex(5.0,0)+Complex(7.0,0)
print Complex(0,5.0)+Complex(0,7.0)
print Complex(5.0,0)+Complex(0,7.0)
print Complex(5.0,0)-Complex(7.0,0)
print Complex(0,5.0)-Complex(0,7.0)
print Complex(5.0,0)-Complex(0,7.0)
print Complex(5.0,0)*Complex(7.0,0)
print Complex(0,5.0)*Complex(0,7.0)
print Complex(5.0,0)*Complex(0,7.0)
print Complex(5.0,0)/Complex(7.0,0)
print Complex(0,5.0)/Complex(0,7.0)
print Complex(5.0,0)/Complex(0,7.0)
print abs(Complex(5.0,0))
print abs(Complex(0,7.0))
print abs(Complex(5.0,7.0))
print -(Complex(5.0,0))
print -(Complex(0,7.0))
print -(Complex(5.0,7.0))
print Complex(5.0,0).conjugate()
print Complex(0,7.0).conjugate()
print Complex(5.0,7.0).conjugate()
print repr(Complex(5.0, 7.0))
print Complex(1.0)
print Complex(imag=1.0)

It should print out the following: