CS209 lab4
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l4.html
-
For this lab you should submit all source code (C
files), and the result(s) of running the program on (a few)
test cases.
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code).
-
The above material should be submitted via BLACKBOARD
before
the deadline of 5pm
Wednesday 23rd. February 2011. You will lose 20% for each day
(or part of day) the lab is late.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated. Please see
http://www.nuigalway.ie/engineering/documents/plagiarism_guide_students
_v4.pdf. You risk getting zero for your lab if it is found to be
plagiarized.
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/
This lab is based on using structures in C to represent and manipulate
complex numbers.
Write a program in C that reads in from the user four (4) real
numbers, x1, y1, x2, y2,
that represent the complex numbers
z1 = x1 +iy1
and
z2 = x2 +iy2.
Represent the complex numbers in your program
as a structure
typedef struct
{
float x;
float y;
} comp;
Write functions in your program to
-
add two complex numbers
-
multiply two complex numbers
-
divide the first complex number by the second (Hint: to divide the
complex number a+ib by c+id, we simply multiply above and below
by c-id to get [(a+ib)(c-id)]/[(c+id)(c-id)].....)
-
determine which complex number has larger modulus
(the value of x2 + y2).
and print out these results to the screen.
You must use structures, and you must use a separate
function for each calculation.
©
NUI, Galway