Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Overloading Operators, Makefiles, Seperate Compilation, and Const Parameter Modifiers

Introduction

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.

Const Parameter Modifier (20 pts)

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 here

Overloading Operators (15 pts)

Overload 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.

Scoring

  • 3 pts - Function declaration
  • 6 pts - Function definition
  • 4 pts - statements that test your implementation in main
  • 2 pts - documentation

Separate Compilation (40 pts)

(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 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 any comments related directly to the implementation of the function.
  • Application - Whatever file is used to apply the type, in our case the main function. 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)

  1. The class definition

Answer

  1. The declaration of a function to serve as an ADT operation and is neither a friend nor a member of the class

Answer

  1. 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

  1. 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

  1. The definition of a friend function that is to serve as an ADT operation

Answer

  1. The definition of a member function

Answer

  1. The definition of an overloaded operator that is to serve as an ADT operation and is a friend

Answer

  1. The main part/function of your program

Answer


After seperating the files, answer the following question

  1. (4 pts) What file is created when the following command is issued?

Answer

g++ -c -Wall my_int.cc

Makefiles (25 pts)

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 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.

Makefile Scoring

  • (5 pts) Produce a "main" executable
  • (5 pts) Produce two .o files
  • (5 pts) Clean rule

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages