Project 0: Memory Management and Using GL

Due: Tuesday, Feb. 4, before 9:00 pm

There are no late submission folders for Project 0. You must turn it in on-time to receive credit.


Objectives


Introduction

In this project, you will complete a C++ class by writing a copy constructor, destructor, and assginment operator. Furthermore, you will write a test program and use Valgrind to check that your program is free of memory leaks. Finally, you will submit your project files on GL. If you have submitted programs on GL using shared directories (instead of the submit command), then the submission steps should be familiar.


Assignment

Step 1: Create your working directory

Create a directory in your GL account to contain your project files. For example, cs341/proj0.

Step 2: Copy the project files

Change to your working directory (using the cd command) and copy the project files with the following command:

cp /afs/umbc.edu/users/c/m/cmarron/pub/www/cs341.s20/projects/proj0files/*.* .

Step 3: Complete the Stack class

The Stack class implements a templated, linked list-based stack. Complete the class by writing the copy constructor, destructor, and assignment operator. The function prototypes are provided in stack.h. Since the class is templated, the implementation will be done entirely in stack.h; there is no stack.cpp file.

Step 4: Test your code

You must write a test program called mytest.cpp that checks correctness of the copy constructor and assignment operator. See driver.cpp for an example of how to use the stack class; output from the program is provided in driver.txt.

Following is a list of essential tests; we refer to the stack created by the copy constructor or on the left side of the assignment operator as the “new” stack; the stack from which the copy is made is the “source:”

Step 5: Check for memory leaks

Run your test programs using Valgrind. For example, assuming you have compiled mytest.cpp, producting the executable mytest.out, run the command

valgrind mytest.out

If there are no memory leaks, the end of the output should be similar to the following:

==8613== ==8613== HEAP SUMMARY: ==8613== in use at exit: 0 bytes in 0 blocks ==8613== total heap usage: 14 allocs, 14 frees, 73,888 bytes allocated ==8613== ==8613== All heap blocks were freed -- no leaks are possible ==8613== ==8613== For lists of detected and suppressed errors, rerun with: -s ==8613== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

The important parts are “in use at exit: 0 bytes” and “no leaks are possible.” The last line is also important as memory errors can lead to leaks.

Step 6: Link your shared directory

Do not complete Steps 6 and 7 until directed to do so by your instructor. The submission directories will not be created until January 31.

Follow the instructions on the Project Submission page to make a symbolic link to the shared directory in your home directory.

Step 7: Submit your files

See the “What to Submit” section, below.


Implementation Notes

Each project has a section on implementation notes. These point out some issues that you might encounter while developing your code. You should look through the Implementation Notes before you start coding.

For Project 0, there are only a few notes:


What to Submit

You must submit the following files to the proj0 submit directory:

If you followed the instructions in the Project Submission page to set up your directories, you can submit your code using the following command:

cp stack.h mytest.cpp ~/cs341proj/proj0/