Docsity

Complex Number Class - Programming Project 1 | CSC 1254, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
Complex Number ADT CSc 1254: Programming Project # 1
Complex Number Class
Out: 9/11
Due: 9/29 by 11:50 PM
Maximum possible points: 25
Learning Objectives
•Understand the basics of implementing a class
•Understand the relationship between the interface, implementation and
client files
•Understand the difference between public vs private access modifiers
•Understand the basics of overloading binary operators
•Understand the role of accessor, mutator and constructor member func-
tion in a class
Definition 1. The complex numbers are the field Cof numbers of the form
x+iy, where x and y are real numbers and iis the imaginary unit equal to
the square root of -1,√−1 . Very often a complex number is represented by
a single letter, z=x+iy.zmay also be associated with a point in a plane
by using the rectangular coordinates (x, y).
Definition 2. The complex conjugate of a complex number z=x+iy is
defined to be ¯z≡x−iy.
Definition 3. The modulus of a complex number z=x+iy is |z|=
px2+y2.
The set of all complex numbers is referred to as ”Complex,” and is usually
denoted C. In this lab, you will complete a simple complex number ADT.
We will ignore some of the inefficiencies but in a subsequent lab, we will
modify the lab and add some enhancements. But for now, we will live with
the inefficiencies. We will use the rectangular coordinates representation as
described above. The class Complex consists of two member variables: real,
the real part, and imag, the imaginary part.
In your mathematical sojourn you have had countless opportunities to
toy around with scalar quantities. Scalar numbers are the kind of numbers
Duncan 1 Fall 2009
pf3
pf4

Partial preview of the text

Download Complex Number Class - Programming Project 1 | CSC 1254 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Complex Number Class

Out: 9/ Due: 9/29 by 11:50 PM Maximum possible points: 25

Learning Objectives

  • Understand the basics of implementing a class
  • Understand the relationship between the interface, implementation and client files
  • Understand the difference between public vs private access modifiers
  • Understand the basics of overloading binary operators
  • Understand the role of accessor, mutator and constructor member func- tion in a class

Definition 1. The complex numbers are the field C of numbers of the form x + iy, where x and y are real numbers and i is the imaginary unit equal to the square root of -1,

−1. Very often a complex number is represented by a single letter, z = x + iy. z may also be associated with a point in a plane by using the rectangular coordinates (x, y).

Definition 2. The complex conjugate of a complex number z = x + iy is defined to be ¯z ≡ x − iy.

Definition 3.√ The modulus of a complex number z = x + iy is |z| = x^2 + y^2. The set of all complex numbers is referred to as ”Complex,” and is usually denoted C. In this lab, you will complete a simple complex number ADT. We will ignore some of the inefficiencies but in a subsequent lab, we will modify the lab and add some enhancements. But for now, we will live with the inefficiencies. We will use the rectangular coordinates representation as described above. The class Complex consists of two member variables: real, the real part, and imag, the imaginary part. In your mathematical sojourn you have had countless opportunities to toy around with scalar quantities. Scalar numbers are the kind of numbers

that represent only the magnitude of a quantity. For example, the voltage produced by a battery is a scalar quantity. The resistance of a conductor (ohms), or the current through it (amps). This applies only to direct current (DC) circuits. In alternating current (AC) circuits, as you have already seen or will see, quantities such as voltage, current, and resistance (termed impedance in AC circuits) are two-dimensional quantities because they are alternating in direction and amplitude. Thus they can only be adequately modeled using two dimensions. Frequency and phase shift are two dimensions that are considered when measuring these quantities. Your goal in this project is to write the interface and implementation for the complex number class. The public interface for the complex number class should provide the following member functions:

  1. constructors: There will be three versions of the constructor function:

a. Complex() : the default constructor sets both real and imag, pri- vate member variables, to 0. The default constructor is imple- mented for you. b. Complex(double r) : the second constructor sets real to r, the double, and imag to 0. c. Complex(double r, double i) : the third constructor sets real to r and imag to i.

  1. operators: +, -, / and * will be overloaded as non-member functions. For the / operator, when both the real and imaginary parts of the divisor are 0, an exception occurs. The operator must throw an integer, -1. The << operator has already been implemented for you. Make sure you understand how it works. Also, the + non-member operator has been implemented for you.
  2. accessors: implement two accessor member functions:

a. getReal(): this function returns the real part of the complex num- ber. This member function has been implemented for you. b. getImag() : this function returns the imaginary part of the com- plex number.

Copy the following files from the class directory: complex.h, complex.cpp and complextest.cpp. I have also included cmplexexe a working version of the lab. You may copy this file and run it to have a feel for how I expect the program to work when you are done. You will write your own makefile in this lab. Copy the makefile from the previous project and tweak it. Compile your program with your makefile until it works properly. Once you are satisfied that your program properly compiles and is error-free, submit your work. Name your executable file complex; that is, set the EXE variable in your makefile to complex. You may submit your work as many times as you wish once the due time has not elapsed. After the due time, any further submission will mean that you get no points for the lab.

Submitting Your Work

  1. Type make clean at the system prompt to remove any object, core and executable file.
  2. All source code files you submit must have a header with the following:

/**

  • @file filename
  • @author your name
  • @date 9999-99-
  • Description: describe what this file does
  • Course: CS
  • Logon ID: cs1254xx
  • Project #: 1
  • Instructor: Duncan */
  1. Submit your assignment to the grader with the following command: ∼cs1254 dun/bin/p copy 1 This command copies everything in your prog1 directory.
  2. Once p copy is finished, check to see if all required files have been submitted: ∼cs1254 dun/bin/verify 1