To practice using separate compilation and makefiles
Date, and main function
What's class declaration, definition and implementation?
||Introduce a class called "Date" to the complier, but without any detail information.|
||Define the class Date's member variables & member functions.|
||Generate the code of class Date.|
Why use separate compilation?
Separate the interface and the actual implementation
"Auto" compile many files at once! and more!
|Code in makefile||Explanation|
#Basic Makefile under Unix
|Everything after the character "#" is a comment.|
date.o: date.h date.cpp
Attention: it is a tab before "g++", NOT spaces!
To make use the idea of separate compilation. You should first download the file Date_all.cpp which contains the Date classes' declarations, implemntation and a short main program. You should then separate the Date class declaration and implementation into separate files and also put the program into a separate file.
Change the main program to an interactive one that asks the day, month and year and then prints it.
Write a makefile that compiles the programas as follows:
date.cppto generate object code
main.cppto generate object code
Compile the program by typing
gmake" to compile the program into executable code
date.h date.cpp date.o main.o main.cpp Makefile lab02) into
After you finished the program, try the following commands to see what they do:
lab02 < input.txt" to read input from file
lab02 < input.txt > output.txt" to read input from file and output to file