To practice using separate compilation and makefiles
Date, and main
functionWhat's class declaration, definition and implementation?
| C++ code | Explanation | |
| class declaration | class Date; |
Introduce a class called "Date" to the complier, but without any detail information. |
| class definition |
|
Define the class Date's member variables & member functions. |
| class implementation |
|
Generate the code of class Date. |
Why use separate compilation?
Separate the interface and the actual implementation
What's makefile?
"Auto" compile many files at once! and more!
| Code in makefile | Explanation |
| # #Comp151, Lab02 #Basic Makefile under Unix |
Everything after the character "#" is a comment. |
|
date.o: date.h date.cpp |
If (( 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.
Date.hDate.cppmain.cppChange 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.cpp to generate object code date.omain.cpp to generate object code main.o
"lab02"Compile the program by typing
gmake" to compile the program into executable codedate.h date.cpp date.o main.o main.cpp Makefile lab02)
into ~/comp151/lab02After you finished the program, try the following commands to see what they do:
lab02 < input.txt" to read input from filelab02 < input.txt > output.txt" to read
input from file and output to file