In this lab, you are going to get some practice using const modifiers, overloading operators as friend functions, and separating code into multiple files. By separating the files, the programmer who uses the type will not have access to how values and operations are implemented, similar to how you do not have direct access to vector operations.
The purpose of this exercise is for you to experience the problems that you can encounter with inconsistent use of the const modifier parameter. Read and understand the my_int.cc program. Compile, and read the error messages.
(5pts) What is the error message? (Answer Here)
(10pts) What do you have to do to correct the code? (Answer Here)
//5pts
//Corrected code hereOverload the operator > as a friend function to the my_int class. Include the function declaration and definition, as well as statements in main to test the function you have written. You will have to create two objects of my_int type with values you choose. Test if you have overloaded the operator correctly by comparing the two objects using the > operator. Don't forget to include documentation for this function.
- 3 pts - Function declaration
- 6 pts - Function definition
- 4 pts - statements that test your implementation in
main - 2 pts - documentation
(20 pts) All you have to do is take my_int.cc and separate it into 3 files. It should be separated into interface, implementation, and application files. Details on what each file should contain are as follows:
- Interface - Should include the class definition along with the prototypes and their respective comments. This file will be saved as
my_int.h. Most of the detailed documentation will be in this file. - Implementation - Consists of all the function definitions of the class. This file will be saves as
my_int.cc. You mustincludeyour interface file in your implementation file along with other include directives in the following manner:#include "my_int.h". This file should contain any comments related directly to the implementation of the function. - Application - Whatever file is used to apply the type, in our case the
mainfunction. You also must include the interface file as a directive.
Be sure to include a brief documentation section at the top of each file. Include guards in the interface file are recommended. (#IFNDEF, etc.)
Answer the following in respect to which file (interface, implementation, application) they must be implemented in (2 pts each)
- The class definition
Answer
- The declaration of a function to serve as an ADT operation and is neither a friend nor a member of the class
Answer
- The declaration of an overloaded operator that is to serve as an ADT operation and is neither a friend nor a member of the class
Answer
- The definition of a function that is to serve as an ADT operation, and is neither a friend nor a member of the class
Answer
- The definition of a friend function that is to serve as an ADT operation
Answer
- The definition of a member function
Answer
- The definition of an overloaded operator that is to serve as an ADT operation and is a friend
Answer
- The main part/function of your program
Answer
After seperating the files, answer the following question
- (4 pts) What file is created when the following command is issued?
Answer
g++ -c -Wall my_int.cc
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++ -Wall main.o my_int.o –o mainNow 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.
- (5 pts) Produce a "main" executable
- (5 pts) Produce two .o files
- (5 pts) Clean rule