CS 368 p4

CS 368-1 Programming Assignment p4

DUE by 8:00 PM on Thursday, April 24th

p4 Announcements | Overview | Specifications | Submission

p4 Announcements

Corrections, clarifications, and other announcements regarding this programming assignment will be found below.

Overview

For this assignment, you are to implement the ComplexNumber class that corresponds to the interface (i.e., the header file) that we've provided. This requires overloading arithmetic, relational, assignment, and I/O operators. You are also to implement a separate main function (in the file main.cpp) that tests your ComplexNumber class.

Goals

The goals of this assignment are to gain experience:

Specifications

Complex Numbers

Complex numbers are abstract quantities having a real and an imaginary part and are expressed in the form a + bi where a and b are real numbers (i.e., doubles) and i is the imaginary unit that results from taking the square root of -1. Arithmetic operations are defined for complex numbers such as:

For a further review of complex numbers, take a look at this quick overview of complex numbers.

The ComplexNumber class

The ComplexNumber class is used to represent complex numbers and to define operations on complex numbers. The interface for the ComplexNumber class is given in the header file ComplexNumber.h. You can get a copy of this file using the linux cp command as shown below:

cp ~cs368-1/public/html/assignments/p4/ComplexNumber.h ./

Do not change ComplexNumber.h, and do not hand it in. We will use the original file to grade your work.

Complete the ComplexNumber class by writing all of the functions given in the header file. To do this you will be overloading several kinds of operators:

The main Function

Write a main function to test the overloaded operators of the ComplexNumber class. Your main function should read in two complex numbers (using the overloaded input operator) and use the overloaded operators to compute (and display the results of) the following (in this order):

An example of how your main function should run and the output it should produce is given below:


Enter a complex number C1:4.2    + 8.3i
Enter a complex number C2:3.1  - 9.2  i
For C1 = 4.2 + 8.3i and C2 = 3.1 - 9.2i :
C1 + C2 = 7.3 - 0.9i
C1 - C2 = 1.1 + 17.5i
C1 * C2 = 89.38 - 12.91i
C1 == C2 is false
C1 != C2 is true
After C1 += C2, C1 = 7.3 - 0.9i
After C1 -= C2, C1 = 1.1 + 17.5i
After C1 *= C2, C1 = 89.38 - 12.91i

You must allow for white spaces (space, \t, \n) before the '+' or '-' sign, as well as before the 'i'

You may assume that the user will always enter both the real and the imaginary parts of a complex number, e.g., the user will enter "5 + 0i" (and not "5") or "0 - 6.2i" (and not "-6.2i").

Submitting Your Work

Make sure your code follows the style and commenting standards used in CS 302 and CS 367. Note: the commenting standards use javadoc comments for class, method, and constructor headers. You do not need to use javadoc comments in your c++ programs for CS 368; however, your comments should include the same information as the javadoc comments. For example, your function header comments should include a description of what the function does, the name and a short description of each parameter, and a description of the return value.

Electronically submit the following file to your in "handin" directory by the due date and time (or refer to the late policy):

Please turn in only the files named above. Extra files clutter up the "handin" directories.

© 2012-2014 CS368 Instructors