CMPT 225 Assignment 0, Part b: Basic Stack and Makefile

In this exercise, you are to:
  1. Make a small modification to the basic stack class described in lecture;
  2. Write a C++ program that tests the modified basic stack class.
  3. Create a "make file" for the class and test program.

Modifying the basic stack class

The change is to add a new function:
 int size() 
which returns the current size of the stack. Remember that you need to add something to both the header file and the .cpp file.

Creating your main function

Your main function should do the following:
  1. Print out your name, login id, and student number, in that order, one item per line;
  2. Create an instance of the basic stack class;
  3. Read in a sequence of positive integers from the keyboard, one per line, and terminated by any negative integer;
  4. Output a blank line, followed by a line with the length of the sequence, followed by a line with the sum of the values in the sequence, followed by another blank line; To determine the size of the sequence you must use the stack size function;
  5. Output the sequence of integers in reverse order, one per line, and not including the terminating negative integer;
  6. Output a (exactly one) "goodbye" line;

Creating your program

Follow the same process as for Part a. You may (actually, should) create your basic stack class by downloading and modifying the example code from the course web page. Do not change the names of the two files implementing the class. Call the file with your main function a0b.cpp. (You may create it by modifying the stack test file, basic_int_stack_test.cpp.)

Creating the make file

The process of re-compiling multi-file programs during developement and testing quickly becomes tedious, partly because of dependencies between files. Any time a file is changes, all compilation units which depend on it must be re-compiled, and in the correct order. Using scripts, like the one provided with the basic stack class, is only slightly less tedious. "Make" or "Build" systems are designed to help with this. (Every decent IDE has such a system built in.) The standard build program that comes with Unix systems, including Linux, is called "make". To use make, you first create a file called a "Makefile", which describes the dependencies and compilation steps to build your program. You should begin this exercise by reading some make tutorials, perhaps one or both of these: make tutorial at Mr. Book; make tutorial at Now, write a Makefile for this assignment exercise. It should support at least the following two commands:
uname@hostname: ~$ make a0b
which should create an object file 'basic_int_stack.o' and then an executable 'a0b', and
uname@hostname: ~$ make clean
which should delete these. To demonstrate that they work, you need to:
  1. use ls to verify there is no basic_int_stack.o and no lab2 executable;
  2. run make a0b;
  3. run ls to verify the intended files were created;
  4. run . /a0b to verify it works;
  5. run make clean;
  6. run ls to verify the .o and executable files were removed.


Once you are sure that your programs (a0b.cpp and the Makefile) work, ensure you bet your grade by:
  1. Showing your TA that the sequence of commands given above does what it should;
  2. Submitting a .zip file containing four files (the two files for your modified basic stack class, your a0b.cpp, and your Makefile) to Coursys (the course management system).