0% found this document useful (0 votes)
1K views3 pages

Lab 13

This laboratory assignment involves practicing const parameter modifiers, overloading operators as friend functions, and separating a C++ program into multiple files. Students will modify an existing program called my_int.cc to address const issues, overload the > operator as a friend function, and separate the code into three files - a header file my_int.h, implementation file my_int.cc, and application file main.cc. Finally, students are asked to write a makefile to compile the files into an executable called main.

Uploaded by

api-281360950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views3 pages

Lab 13

This laboratory assignment involves practicing const parameter modifiers, overloading operators as friend functions, and separating a C++ program into multiple files. Students will modify an existing program called my_int.cc to address const issues, overload the > operator as a friend function, and separate the code into three files - a header file my_int.h, implementation file my_int.cc, and application file main.cc. Finally, students are asked to write a makefile to compile the files into an executable called main.

Uploaded by

api-281360950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Laboratory Assignment #13: Const parameter modifiers, overloading

operators, separate compilation, makefiles


(90 pts.)

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

Create a directory called Lab13 inside your 2400 directory.

2. const Parameter Modifier


Purpose of this exercise is for you to experience the problems that you can encounter by
inconsistent use of the const modifier parameter (pg 638). First copy the following
program from he course account on prime (lab13 directory) to your subdirectory.
my_int.cc
Then read and understand the program. After that compile the program and check the
error messages. Answer question # 1 on the answer sheet. After correcting the problem
recompile and run the program. Answer questions 2-3 on the answer sheet. You can
find more information on this topic on pages 638 - 640.

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.

You might also like