Name: ____________________________________________________ Alpha: ________________________

Describe help received: _____________________________________________________________________

Print this homework sheet, bring it to the class, and turn it in right before the next lecture starts.

  1. (20 pts) Read the C++ programming guide and tips. Honestly declare how your read the guide. You will get the full credit only if you read it carefully.
    a. (20 pts) I read it very carefully.     b. (15 pts) I read it.
    c. (10 pts) I just skimmed it.             d. (0 pts) I didn't read it.
  2. (80 pts) If $u = x + yi$ and $w = a + bi$ are complex numbers, then their product is given by: $$ u \cdot w = (xa - yb) + (xb + ya)i$$ In other words the real part of the product $u \cdot v$ is $xa-yb$, and the imaginary part is $xb+ya$. Note: complex number $x+yi$ 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 63 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 the following: 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; which means variable assignments and arithmetic expressions and nothing else. 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

"I don't remember anything too 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.

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 procedure 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 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. 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.