COSC 160: Data Structures

Homework 1
Fall 2021

Due: F 9/3 @ 5 PM
Optional

This homework is to get you familiar with how you'll be submitting projects this semester. You are to

  1. Implement Stack<T> as a stack that can store at most 100 objects using an automatically allocated array as described in sections 5.1.3 and 5.1.4.
  2. Compile and test the project on cs-class-1 (class-1.cs.georgetown.edu), ensuring it works with the Makefile I have provided. You might find the screencast on Makefiles helpful.
  3. Submit the project to Autolab. You can submit to the compile check five times. You can submit to the autograder two times.

Excruciating Detail

If you haven't already, set up your shell account. To determine what shell you're using type:

cs-class-1% echo $SHELL
You should see "/bin/bash".

If you want to configure bash, the Bourne Again Shell, using my configuration, from your top-level directory, copy the following file from the top-level directory maloofm:

cs-class-1% cp ~maloofm/mm.bashrc ./.bashrc
To apply the settings in the file, type
cs-class-1% source .bashrc

From now on, the settings in this file will be applied whenever you log in.

Implement Stack<T>. To do this, connect to class-1.cs.georgetown.edu and copy a zip file containing starter files from my directory to your current directory on class-1/cs-class-1 using the command:

cs-class-1% cp ~maloofm/cosc160/hw1.zip ./
You can at this point transfer the zip file to your laptop and unzip it, or you can unzip the file on cs-class-1 using the command:
cs-class-1% unzip hw1.zip
Unzipping this file creates a directory named hw1 that includes a Makefile and a file containing the public interface for Stack<T>. To descend into the directory, type
cs-class-1% cd hw1
At this point you can transfer the files in the hw1 directory to your laptop if you plan to use it for development.

Your implementation Stack<T> must not change the public interface. Instead of deriving exceptions from RuntimeException derive them from logic_error. As you can see in the private section of Stack<T>, we can declare an automatically allocated array as follows:

T contents[100];
This creates a C array of T objects of size 100. Write the public methods of Stack<T> to perform the specified stack operations using this array.

For this and all other assignments, you can use any C++ compiler to develop your program, but your project must compile and run on class-1/cs-class-1 using GNU g++ 8.4.1. To check the compiler's version, type

cs-class-1% g++ -v
You should see the following output:
Using built-in specs.
...
gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC)

All projects must have a file main.h with all of the necessary include directives. Keep in mind that file names on Linux machines are case sensitive, and on Macs they probably are not, even though it's a Unix machine. For example, on a Mac, if you have a file named "Stack.h" and include "stack.h", it will compile on a Mac, but it won't compile on cs-class-1 or on Autolab.

For this and all other assignments, you must provide a working Makefile for your project. The Makefile must produce an executable with the default name a.out. There must be a clean target that removes a.out and all of the .o files. You should be able to use Makefile that I've provided with the appropriate modifications.

If you are not developing on cs-class-1, use secure ftp to transfer your files from your computer into this directory.

For all of your submissions, you must include a file named HONOR that includes the following statement:

Name
NetID

In accordance with the class policies and Georgetown's Honor Code,
I certify that, with the exceptions of the course materials and those
items noted below, I have neither given nor received any assistance
on this project.

All of the files for your project should be in the directory hw1. For this assignment, the files you need are:

If you need to include a message about your submission, then place the message in a plain-text file named README. Place the README file in the project's directory. You can also use .cc as the file extension.

Before submitting, to reduce the size of the zip file, remove the executable and .o files by typing 'make clean':

cs-class-1% make clean
rm -f a.out *.o
Also make sure you remove all debugging output before submitting.

(Additional useful Unix commands)

When you're ready to submit your project for autograding, create a zip file of directory's contents by typing

cs-class-1% make submit
This command creates a zip file named submit.zip in the current directory that includes all of the files that you have specified in the Makefile. You must edit and update the Makefile as you develop and test your project.

To see the contents of the zip file, type:

cs-class-1% cd ..
cs-class-1% unzip -l submit.zip
Archive:  submit.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      937  2020-07-03 11:21   Makefile
       31  2020-07-03 11:50   Makefile.dep
      150  2020-07-03 11:49   main.cpp
      115  2020-07-03 11:21   main.h
      265  2020-07-03 11:21   stack.h
      221  2020-07-03 11:21   HONOR
---------                     -------
     2053                     5 files
It is imperative that the zip file contains only the files of your project with no subdirectories.

Use a secure file-transfer program (sftp or FileZilla) to transfer the zip file from cs-class-1 to your laptop. (You can also produce the zip file on your laptop.)

To submit the zip file, use your browser to log on to Georgetown's instance of Autolab. For projects, you will have five compile checks and two project submissions. The compile checks help you ensure that your project submission compiles against the autograder, whereas the project submissions run your program against the autograder. To perform a compile check, navigate to the hw1c assignment, and submit your file submit.zip. To submit your project for automatic grading, navigate to the hw1 assignments, and submit your file submit.zip.

Once you've submitted your project, it is important to keep an electronic copy on cs-class-1, which preserves the modification date and time of your project. If the submission system breaks or you submit the wrong project, then we will need to look at the modification date and time of your project to ensure that you submitted it before it was due.

Once you receive a grade for a project, you can remove the zip file, the project directory, or both. To remove the zip file, type:

cs-class-1% rm submit.zip
You will follow this same process for each assignment.

Plan B

If Autolab is down, upload your zip file to Canvas.

Copyright © 2020 Mark Maloof. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed.