![]() |
|
| Lab 9: Object-Oriented and Multi-module Software | |
|
A demonstration of parts one and two. In particular, we might do the following series of commands: For this lab you must convert your word counting program from Lab 6 into an C++ program that uses classes (or at least one class), and also convert it into a multiple-source-file program.ls make clean make wordcount ls -ltr wordcount testfile make clean ls -ltr make ls -ltr wordcount-l testfile The resource material for the multiple-source-file part of this lab comes from chapters 10 and 11 in the LUPT book. Part One Convert your word counting program so that main() is in one source file, and the rest of the functions are in one or more other source files (depending on what makes logical sense for your program). The type definitions and function prototypes should be placed in one or more header files, and absolutely no executable code should be in header files. Create a Makefile that compiles each source file into its own object file (.o extension), and then links those object files together into an executable named wordcount. Typing just make in your program directory should build the complete program. Your Makefile must also have a "clean" target in it, so that if you type "make clean", all object files and executables built by the Makefile are removed. Part Two Add a clause to your Makefile so that it creates a library (.a extension) that contains the compiled object code of the non-main source code of your program. This library should be named libword.a. Now add a clause to your Makefile so that it can build the same main program, but using the library. The name of the executable should be wordcount-l. Change the Makefile so that the default action (i.e., if you just run make) builds both the wordcount and wordcount-l executables. Part Three Convert your wordcount program to C++. In this conversion, you should not have any struct definitions anymore, but only class definitions. Functions that operated on the linked list of structures (or on one of them) should be converted to methods in the class. There are many ways of making this type of program into an object-based program. You may decide to use multiple classes. You may decide to use a single class. In our in-class example using points, we will first just translate the structures that form the linked list into objects, but that is not the only way to convert the program, and probably not even the best. For this lab, you must submit the source and header files (probably a few files), and the Makefile. As always, commenting and code quality is important. Don't forget that in a Makefile comments are lines beginning with "#". |