C/C++ Programming: Lab 3. Structures in C

Part 1 should be completed in the lab period, part 2 in your own time and submitted at the START of your next lab period.

At the end of this lab you have to be familiar with how structures could be used to represent complex numbers and how functions for operations such as addition of complex numbers could be implemented.


Part 1: The basic definition of complex number is real and imaginary parts. Use the following structure to perform operations under the complex numbers:

typedef struct
       double re, im;
        } complex;

 Note that in this if two variables are defined as:
 
       complex x, y, z;
 an operation such as
:
 
       z = x + y;
 will not be allowed. Instead you have to implement the required operations in terms of functions.
   



Part 2. write complex number routines for multiplication, division and substraction, using the same structures as defined in Part1.

The functions have to be called using both call by value and call by reference. The data have to be processed using Pointers. The operations of more than 2 variables have to be performed, i.e. initial task can contain the following expression: a+b*c-d, where a,b,c,d are complex numbers.

4 examples of running program for your choice have to be given. The examples have to covered all build-in features of calculator for complex numbers.

YOU WILL BE REQUIRED TO SUBMIT THIS PROGRAM AT THE START OF YOUR SECOND LAB SESSION.


Comments.

In the lab you will be using C/C++ Borland 4.5 compiler. You can run this compiler by using: Start->Miscellaneous Software -> Programming Tools -> C & C++ -> Borland C & C++ 4.5

Type your program into the text edit window. Remember to save it to your home directory, give it a sensible name: File->Save As

Compile your program. Project->Compile

Highlight the error in the message window and the line in error in the text edit window is displayed. Recompile until there are no errors.

See the Debug menu for run and debug options.