Dec 062017
 
Z++ Version 1.0 - Complex number class for Borland/Turbo C++. Includes demo program, an FFT application, and full source code.
File ZPP10.ZIP from The Programmer’s Corner in
Category C++ Source Code
Z++ Version 1.0 – Complex number class for Borland/Turbo C++. Includes demo program, an FFT application, and full source code.
File Name File Size Zip Size Zip Type
SIGNAL.DAT 138 106 deflated
COMPLEX.CPP 8725 1967 deflated
Z_TEST.CPP 5492 1147 deflated
COMPLEX.H 4393 969 deflated
FFT.CPP 16126 4409 deflated
COMPLEX.DOC 6264 2429 deflated

Download File ZPP10.ZIP Here

Contents of the COMPLEX.DOC file




Z++ Version 1.0

Copyright 1992 by Carl Moreland
04/03/92

Z++ is a public domain complex number class written in C++. The distri-
buted files are:

complex.hheader file for Z++
complex.cppsource code for Z++
complex.doc this file
z_test.cppdemonstration of complex numbers
fft.cppfft using Z++
signal.datdata file for testing the fft

To use the complex number class, simply #include "complex.h" in your source
and add complex.cpp to the project or make file. You may use and distribute
this code freely, but all distributed copies must be unmodified, and there
may be no distribution charges. Comments, suggestions for improvement, and
bug reports may be sent to me via CompuServe (72137,2657), or mail them to:

Carl Moreland
4314 Filmore Rd
Greensboro, NC 27409

---------------------------------------------------------------------------
---------------------------------------------------------------------------

Introduction:

---------------------------------------------------------------------------
Complex numbers may be declared or initialized in the following ways:

complex z; // z is initialized to (0,0)
complex z(3); // z = (3,0)
complex z = 3; // z = (3,0)
complex z(3,4); // z = (3,4)
complex z = complex(3,4) // z = (3,4)
complex z = x; // set equal to a double/float/int
complex z1 = z2; // set equal to another complex

Uninitialized complex variables are set to (0,0) by the default construc-
tor, and variables that are set equal to a single number have their imagi-
nary part set to zero.

The following operators are available:

=see above
+ +=addition
- -=subtraction
* *=multiplication
/ /=division
^power (z1^z2)
== !=comparison

The following functions are available:

rereal part
imimaginary part
realreal part
imagimaginary part
magmagnitude (sqrt(x**2 + y**2))
argargument (atan(y/x))
angangle (same as argument)
phphase (same as argument)
conjcomplex conjugate (x, -y)
normnorm (x**2 + y**2)
absabsolute value (same as magnitude)
sqrtsquare root
powpower
expexponential
lognatural log
lnnatural log
log10log (base 10)
coscosine
sinsine
tantangent
acosarccosine
asinarcsine
atanarctangent
coshhyperbolic cosine
sinhhyperbolic sine
tanhhyperbolic tangent
rtoprectangular-to-polar conversion
ptorpolar-to-rectangular conversion
topolarconverts z to polar form
torectconverts z to rectangular form

SetArgMode
SetPrintMode See text below
SetLetter

---------------------------------------------------------------------------

Most features of Z++ are standard. However, there are a few things that
are unique and should be explained.


The conversion functions rtop() and ptor() accept a complex number as
the argument and return a new complex number as the converted result. The
member methods topolar() and torect() will convert the instance internally
and return a reference to it. Remember though that all math functions ex-
pect arguments in rectangular notation, not polar. If you convert a number
to polar and try to take the cosine, for instance, you will not get the
correct results.


There are two modes that can be set in Z++. The argument mode deter-
mines whether complex arguments (from the functions arg(), ang(), & ph())
are returned in radians (the default) or degrees. This mode can be set by
calling the function SetArgMode() with either Z_RADIANS or Z_DEGREES as
the mode parameter:

z1.SetArgMode(Z_DEGREES);

Because this mode is represented as a static class variable, setting it
will affect all complex numbers. The command above appears to set this mode
only for instance z1, which is not true. To eliminate this confusion, there
is a static instance named Complex declared in complex.h which should be
used to set this mode:

Complex.SetArgMode(Z_DEGREES);

Either way will work, but the second has the appearance of being global.


The other mode is the print mode which affects the format of cout. This
mode can be set by calling the function SetPrintMode() with either Z_COMMA
or Z_LETTER as the mode parameter:

Complex.SetPrintMode(Z_COMMA)
Complex.SetPrintMode(Z_LETTER)

The first mode causes complex numbers to printed with the format (x, y) by
cout. The second mode causes them to be formatted as x iy. Like the argu-
ment mode, this mode is global for all complex numbers and therefore should
be set using the Complex instance.


Electrical engineers prefer to use the letter j as the complex operator
(the letter i denotes AC current). There is a function called SetLetter()
which accepts a character argument:

Complex.SetLetter('j');

If the print mode is set to Z_LETTER then cout will print a complex number
with the format x jy.


Finally, besides the instance Complex used above there are four other
static instances declared:

Z0 = complex(0,0)
Z1 = complex(1,0)
Zi = complex(0,1)
Zinf = complex(HUGE_VAL, HUGE_VAL)

These are common useful numbers that can be used for assignments, compari-
sons, and equations.

---------------------------------------------------------------------------

FFT note:

The FFT program that is included was originally written in C and ran on
DOS, VMS, and Unix. It's purpose was to transform sinusoidal data from an
analog-to-digital converter and display the harmonics and relative bits of
accuracy. I have only converted the fft() routine to use the Z++ complex
numbers; the rest of the program remains pure C. The data file included for
testing the FFT is the actual results from a 12-bit ADC.


 December 6, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)