CS170 Compile Lab Exercise
The program you will work with is a simple one, but it is spread out
over several files. i.e.
The idea is that the main function, Calculatr.cpp, is the controller
for a simple calculator.
Each of the functions for the calculater - add, subtract, and so on -
are in separate files.
Only two functions, Add and Modulus, are complete at the moment.
Your goal for this exercise will be to build the entire calculator.
To make this easier to work with, create a directory for the files by
entering something like:
- you can chose whatever directory name you like, and put it wherever
you like in your Hercules disk space.
These instructions will use the directory name CalculatrPgm
Copy the files
from the CS Dept's anonymous ftp site to your Hercules account space
by entering the commands:
- Now move into your new directory with the command:
Compile each C++ program file to produce object files.
(Remember to use the -c option!)
Link the object files to produce an executable file called "Calculatr".
Run the executable file with the command:
Be sure to enter INTEGER numeric values when asked for input.
Now that you've seen the program running, use whatever editor you
like and have a look at the source code.
Start with Calculatr.h so that you can see what the
"Data_Type" statement is all about.
The remainder of that file shows the function prototypes for
each module in the program.
As you add new modules, you will have to add new prototypes here.
Make your life tons easier by getting the Makefile
for this project.
Start adding modules to the program.
Rembember that each module should be a separate file
e.g. Subtract.cpp, Multiply.cpp, and Divide.cpp.
Subtract and multiply are
straightforward but you will want to look at the ModNums.cpp file
to see how to code to prevent divide by zero for your divide module.
Each time you add a file for a new module, you will have to modify
your Calculatr.cpp and Calculatr.h files.
As you develop the modules for this program, remember that you
do not have to recompile all of the modules each time
you make a change - only recompile the one
you are currently working on.
Copyright: Department of Computer Science, University of Regina.