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.

Grading

Correct80%
Commented10%
Attempted10%

Problems

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 mathworld.wolfram.com. Your file should be called complex.py 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:

(12.0+0j)
(0+12.0j)
(5.0+7.0j)
(-2.0+0j)
(0-2.0j)
(5.0-7.0j)
(35.0+0.0j)
(-35.0+0.0j)
(0.0+35.0j)
(0.714285714286+0.0j)
(0.714285714286+0.0j)
(0.0-0.714285714286j)
5.0
7.0
8.60232526704
(-5.0+0j)
(0-7.0j)
(-5.0-7.0j)
(5.0+0j)
(0-7.0j)
(5.0-7.0j)
(5.0+7.0j)
(1.0+0.0j)
(0.0+1.0j)