Specifications:
This is a two-part lab intended to get you to first create a function out of existing code, and then move that function to a separate source code file. Start with the solution to lab2, and modify it so that the actual conversion is done in a function. You need a function called convert() that takes the 3 input variables (source currency, destination currency and source value) as parameters, and returns the converted value. If there was a problem with either the source or destination type, your function should indicate an error condition by returning a negative value. Your main() program gets the 3 input values from the user, calls the function, and then either outputs an error message or the converted value, whichever is appropriate.
For part A of this lab, keep your function in the same file as the main() function, but placed below it. (You will therefore need to include a prototype for the convert() function above the main() function.) Name this file "lab4a.c".
For part B of this lab, move your function to its own file, "utils.c". You will also have to create an associated "utils.h" file, complete with preprocessor directives so that it can only be processed by the compiler once no matter how many times you include it. Your header file is also the appropriate place for any currency conversion-specific constants! Name the program file as "lab4b.c", but keep the utility files as "utils.c" and "utils.h".
Note that for both of these programs (parts A and B), the output is still exactly as specified for lab 2; the only difference is the organisation of the code, which should be completely transparent to the user.
Please only use the given solution for lab 2 as the starting point, even if you got a good mark on your own solution. It will help keep the output consistent between all students, and make it so any small variations won't inadvertently create more work for you.
gcc -c lab4b.c
gcc -c utils.c
This way you can work on each part separately, getting all the compiler errors fixed before linking them together to make an executable program.
When both object files are created, you can link them together using gcc without any flags; just use the .o object files as the parameters, instead of the .c source code files:
gcc lab4b.o utils.o
Of course, you can always do both compiling and linking at the same time, if you want; but you have to put both source code files on the command line:
gcc lab4b.c utils.c
This lab is due before your next scheduled lab, on Wednesday February 11, at 3:30pm.
3 points: lab5a compiles and works.
3 points: lab5b compiles and works.
2 points: proper use of header file (including preprocessor directives) and prototypes
2 points: proper use and placement of parameters, local variables and constants.