Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

Problem 1

If u = x + i*y and w = a + i*b are complex numbers, then their product is given by:
u*w = (x*a - y*b) + i*(x*b + y*a)
In other words the real part of the product u*v is (x*a - y*b), and the imaginary part is (x*b + y*a).
Note: comnplex nbumber "x + i*y" can be thought of as a pair (x,y) where x is called the "real part" and y is called the "imaginary part".

Do one or the other of the versions of Problem 1 described below. You do not need to do both! The 90% solution is simpler to do (though more tedious and less interesting) and only worth at most 90 points. The 100% is a bit tougher (though less tedious and more interesting) and is worth 100 points. Most important to me is that I get a working program from you.
Remember: plan out the basic steps of your program before you start with the actual code. Also, look at the example problems at the end of the class notes. Seeing how they work will help you design your own solution.

A 90% Solution A 100% Solution
Write a program that reads in two complex numbers and prints out their product. A typical session with the program might look like this (user input is in red):
Enter the real part of u   : 3
Enter the complex part of w: 4
Enter the real part of w   : -0.5
Enter the complex part of w: .25
(3 + i*4) * (-0.5 + i*0.25) = -2.5 + i*-1.25
Write a program that reads in a complex number from the user and prints out its cube - i.e. it reads in a complex number w and prints out w^3. A typical session with the program might look like this (user input is in red):
Enter the real part of w   : -1.2
Enter the complex part of w: 1.3
(-1.2 + i*1.3)^3 = 4.356 + i*3.419
Note: I do not want you to derive a single mathematical expression for the cube of a complex number, which is a very ugly expression, and use that in your code. Cubing means multiplying twice. Use that!

Turn in a printout of the source code for your program, a screen capture of the window showing your program running with the above input, and a printout of this page with name, alpha, help-info filled in. These should be stapled together.

How to turn in Homework

Since this is your first time turning in code, here are some instructions for how we want this done. (Printing the screenshot is, hopefully, taken care of by the instructions from the previous class.) The whole point of the procdure described below is that it produces nice, colorized printouts that use as little paper as possible, even when there are many .cpp files of very long .cpp files.
  1. make sure you are in the same directory as the .cpp file(s) you want to print
  2. give the command codprint followed by the names of the .cpp (or .h) files you want to print. For example, if I have files foo.cpp and bar.cpp I would give the command
    codeprint foo.cpp bar.cpp
  3. The above command produces a file called out.pdf which you can then print out in whatever way works best for you.
Take the printout of the screen capture and the printout of your source code, and (1) make sure your name is on both of them, and make sure you write down from where or whom you received assistance. Remember: collaboration is fine, but you must always acknowledge any help you receive.