COMP151: Lab 02

Objective:

To practice using separate compilation and makefiles

Download :

Lab work:

What'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

class Date {
Date();
//...
};

Define the class Date's member variables & member functions.
class implementation

Date::Date() {

//...
};

//...

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
            g++ -c date.cpp

If ((date.o does not exist) or (date.h or date.cpp is modified)), then run "g++ -c date.cpp".

Attention: it is a tab before "g++", NOT spaces!


Assessment tasks:

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:

Compile the program by typing

Submission:

Redirection in Unix

After you finished the program, try the following commands to see what they do: