CS60 Homework 10 --------------------- Due: Mon. Nov 3rd at 1:00pm Complex Number Arithmetic Library ----------------------------------- The task of homework 10 is to write a simple library that performs arithmetic on complex numbers. Complex numbers are numbers that consist of a real part and imaginary part such that they can be used as points on the imaginary plane. We can think of a pair of integers (x,y) as the complex number (x+yi) where i is the square root of -1. There is a a pre-written header file, on the website, that contains the definition of a complex number type: struct complex_t { int x; int y; }; Also on the website there is an code file that I have written and that needs implementation of the following functions: int addcomplex(struct complex_t *result, struct complex_t *a, struct complex_t *b); int mulcomplex(struct complex_t *result, struct complex_t *a, struct complex_t *b); the prototypes of which are also in the included header file. Your task is to implement these two functions and create a library called libcomplex.a which contains the complied object code of the function implementation. Finally, you need to create a Makefile that compiles your code and my code, creates a library, and finally links the object file 'hw10.o' with your library to create and executable. You must explicitly create a library file called 'libcomplex.a' that is used in linking using the '-lcomplex' directive to gcc, it is not sufficient to simply link your code's .o file with hw10.o. You may NOT edit the hw10.c file that I have written, the goal of this project is to write a complex number library which does not require editing hw10.c. Complex Arithmetic ------------------ Assuming we have two complex numbers representations (a,b) and (c,d) (which correspond to the complex numbers a+bi and c+di), arithmetic is performed in the following manner: (a,b) + (c,d) = (a+c, b+d) and (a,b) * (c,d) = (a*c - b*d, a*d + b*c) The program hw10.o performs the following operations in the following order: (10,1) + (10,1) (500,40) + (0,0) (12,11) * (3,10) (100,43) * (1,0) (0,1) * (0,1) Turnin --------------- The turnin tag for this assignment is 'hw10' and must include the code for the complex number arithmetic functions, a Makefile, and a typescript showing compilation using make (gcc must have -ansi -pedantic flags as usual) and execution of the resulting binary. Sample Output ---------------- [nurmi@localhost hw10]$ ls Makefile complex.h hw10.c typescript complex.c hw10 hw10.outline [nurmi@localhost hw10]$ make clean rm -f complex.o libcomplex.a hw10.o [nurmi@localhost hw10]$ make cc -I./ -c -o complex.o complex.c making libcomplex ar rs libcomplex.a complex.o ar: creating archive libcomplex.a cc -I./ -c -o hw10.o hw10.c making all gcc -ansi -pedantic hw10.o -o hw10 -L./ -lcomplex [nurmi@localhost hw10]$ ./hw10 Res1: 20 + 2i Res2: 500 + 40i Res3: -74 + 153i Res4: 100 + 43i Res5: -1 + 0i [nurmi@localhost hw10]$ ls Makefile complex.h hw10 hw10.o libcomplex.a complex.c complex.o hw10.c hw10.outline typescript [nurmi@localhost hw10]$ make clean rm -f complex.o libcomplex.a hw10.o [nurmi@localhost hw10]$ ls Makefile complex.h hw10.c typescript complex.c hw10 hw10.outline [nurmi@localhost hw10]$