html> CS222 Lab 6

Lab 6 - Seperate Compilation and Namespaces

The purpose of this lab is to learn how to create multiple files for seperate compilation and how to use programmer-defined namespaces.

Part 1 - Seperate Compilation

Take the code from Display 12.5 in the book and convert it to use seperate compilation. Put the function prototypes for each namespace into a file called "greeting.h". Put the function bodies for each namespace into a file called "greeting.cpp". Finally, put the main function into a file called "lab6.cpp". In the greeting.h file, make sure to include the #ifndef directive to make sure multiple copies of the file are not included.

Compile greeting.cpp and lab6.cpp using

g++ -c <filename>
Link the files together to make the executable using
g++ -o lab6 greeting.o lab6.o

Part 2 - Namespaces

Extend the namespaces in greeting.h and greeting.cpp to include the function void farewell();. The bodies for each farewell function should be different. Modify main.cpp to call farewell(); in each namespace.

What to turn in

Email the files greeting.h, greeting.cpp and lab6.cpp that have the changes you made in Part 2. In the body of the email, cut and paste a log of you using g++ -c <filename> to compile greeting.cpp and lab6.cpp and of you using g++ -o lab6 greeting.o lab6.o to create the executable.