Lab 13
Lab 13
1 Introduction
In this lab, you are going to get some practice using const modifiers, overloading
operators as friend functions and in order to define a class so that it is an ADT you need
to divide the program into separate files. By doing so the programmers who use the type
do not have access to how values and operations are implemented.
1.1
Laboratory Preparation
3. Overloading Operators
Overload the operator > as a friend function to the my_int class. Include the function
declaration and the function definition. Also include the necessary statements in the
main to test the function you have written. You will have to create two objects of
my_int type with values you choose. Then compare and see whether youre overloaded
> operator is working correctly. (Dont make any changes to the existing statements in
the main function.). Dont forget to include the documentation for this function. Look at
question # 4 on the answer sheet for the point distribution. For more information, look at
pages 644 646 in your text.
4. Separate compilation
All you have to do is to take my_int.cc and separate it into 3 files (interface,
implementation and application file) More on pp 704 718.
Details on what each file should contain as follows:
The class definition along with the prototype comments must be in a separate file
called the interface file. This file will be saved as my_int.h Most of the
detailed documentation will be in this file.
The implementation file consists of all the function definitions of the class. This
file will be saved as a my_int.cc file. You must include your interface file in
your implementation file along with other include directives in the following
manner: #include my_int.h
This file should contain comments for each function.
Your main function is in a separate file called application file saved as a .cc
file. Also you have to include the interface file as a directive. (as in b).
Include your name and a brief description in all three files. Look at display12.1 12.3 on
pgs 707 - 712
For example, your application file is called main.cc, how can you produce an
executable called main? Do not compile the .h file.
g++ -c Wall main.cc
g++ -c Wall my_int.cc
g++ main.o my_int.o -o main
or
g++ -Wall *.cc o main
or
g++ -Wall main.cc my_int.cc o main
5. Makefiles
Now write a short makefile for your project. Recall you need to use
patterns. The first pattern in the file should be:
main: main.o my_int.o
g++ main.o my_int.o o main
Now write a patterns that produce the .o files main.o and my_int.o.
Be sure to also include a pattern to clean-up after yourself.
Answer questions 5 - 8 on the answer sheet.