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 u: 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 (which should have your name and alpha in a comment at the top), 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.

A note about using the Internet to complete this homework: You may be tempted to google how to do complex numbers with c++ and come across the complex library. You should not be using this library because the point of the assignment is to complete it using the skills you currently have based on the lessons so far. The purpose of this homework is for you exercise those skills and not the skill of googling for solutions that have not been covered in class.

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 covered by the note from Midn McKelvey on the right-hand side of the notes.) 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. "I don't remember anything being to tricky about codeprint. But taking a picture of the terminal [...] cropping the desired area so you didn't need a full screen shot of the terminal. Shift+PrintScreen allows you to capture a selection of the screen by clicking-and-dragging a box of what you want to capture." - 2/C Keven McKelvey

    Note: Shift+PrintScreen does the screencapture within the VM. This means that the resulting .png file (which you name yourself) should be dragged outof the VM desktop and onto the Windows desktop to print.

    The above command produces a file called out.pdf which you can then print out in whatever way works best for you. I recommend you click on the folder icon along the right-hand side of your VM's desktop, navigate to the right directory, and drag out.pdf of the VM desktop and onto your Windows desktop.
Take the printout of the screen capture and the printout of your source code, and staple them to a printout of this page. Make sure your name is on the printout of this page, 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.