Homework 0

Successful completion of this assignment prior to submitting the first programming assignment is mandatory.

This assignment takes the student through a review of topics in Unix, Emacs, g++, and Make that represent essential skills for the course, and creates some directories, links, and Unix shell commands that will also be needed. Most of this material is a review from previous courses. The grading is pass/fail. The material will be covered on exams.

Homework 0 is divided into two parts. The first deals with basics of Unix and file editing. The second deals with compiling with g++ and project build with make.

Part a: Unix and Emacs

Educational Objectives: After completing part a, the student should be able to accomplish the following:

Operational Objectives:

  1. Install a set of Emacs initialization files
  2. Create a directory for your course files
  3. Create a symbolic link to the course library
  4. Create Unix commands clean, c4530, and co4530

Deliverables: One file hw0a.txt, to be submitted after completing Part b.

Procedural Requirements

  1. If you have not obtained a CS account, do so now at http://system.cs.fsu.edu/. You will not be able to continue until you have an active CS account. You will also need a secure shell login. See the course organizer for access to SSH software.

  2. Log in to your CS account. In your home directory, create a directory named cop4530. From within this directory, create subdirectories named as follows:

    hw0
    hw1
    hw2
    hw3
    hw4
    proj1
    proj2
    proj3
    

    Change permissions for all of the directories to 700 by issuing the command

    chmod 700 *
    

    Read and understand aboutthis command in the on-line Unix manual pages (man chmod).

  3. Create a symbolic link to the course home directory by issuing the following command:

    ln -s /home/courses/cop4530p/spring11 cop4530p
    

    This should create a link from "cop4530p" to the course library files. Now a long listing of your cop4530 directory should produce something like the following:

    lrwxrwxrwx  1 username CS-Course  31 Dec  7 12:52 cop4530p -> /home/courses/cop4530p/spring11
    drwx------  2 username CS-Course 512 Dec  7 12:54 hw0
    drwx------  2 username CS-Course 512 Dec  7 12:54 hw1
    drwx------  2 username CS-Course 512 Dec  7 12:54 hw2
    drwx------  2 username CS-Course 512 Dec  7 12:54 hw3
    drwx------  2 username CS-Course 512 Dec  7 12:54 hw4
    drwx------  2 username CS-Course 512 Dec  7 12:54 proj1
    drwx------  2 username CS-Course 512 Dec  7 12:54 proj2
    drwx------  2 username CS-Course 512 Dec  7 12:54 proj3
    

    The symbolic link is in effect a short cut over to the course library for use in file manipulation commands, such as cd and cp.

  4. Get back into your home directory (issue the command cd with no argument). Unless you already have a customized setup for emacs, do the following three commands:

    1. cp ~cop4530p/.emacs .
    2. mkdir .lisp
    3. cp ~cop4530p/.lisp/* .lisp/
    These commands create a set of configuration files that are read by Emacs on startup.

    You may also wish to set emacs to correctly indent braces in code - see the FAQ for details on how to accomplish this.

  5. Remaining in your home directory, issue the command

    ls -al

    This will show a long (-l) listing (ls) of all (-a) of the contents of the directory, including those items that are normally ignored by the ls command. Get into your directory named .bin. (Create ~/.bin if it does not already exist.) Using emacs, create a file named clean with the following contents:

    #!/bin/sh
    rm $1/*~
    rm $1/*.o
    rm $1/*.x
    

    Then issue the command

    chmod 700 clean

    What you have just accomplished is the creation of a Unix script clean that executes from the command line. This command takes one argument (denoted by $1 in the code) intended to be a directory (or path). Execution of the command will safely remove all of the Emacs backup files (ending in "~"), object code files (ending in ".o"), and executables (which will end in ".x" by convention in this course) from the directory. This is very handy to keep from cluttering your work space.

  6. Copy the following two files from ~/cop4530/cop4530p/examples/scripts into .bin: c4530 and co4530. (Assuming you are still in the .bin directory, these copies should be created by the following command:

    cp ~cop4530p/spring11/examples/scripts/* .
    

    Change the permissions on these files so that they are executable, as described above for your clean command. Also, look at these files using emacs. What does c4530 do? What does co4530 do? (To answer these questions, look at the manual for g++ by entering the command man g++.) Finally, issue the command hash or, if that is an unknown command, rehash, which will incorporate the three new commands into your login session. (This will happen automatically in all new login sessions.)

Technical Requirements and Specifications

  1. This is the documentation phase of the assignment, to be completed inside your subdirectory ~/cop4530/hw0.

  2. Use Emacs to create a text file named hw0a.txt. Type the following information at the top of this file:

    COP 4530 Spring 2011
    Homework Assignment 0
    (Your Name)
    CS  Username: (Your CS Username   - used for login to CS account)
    FSU Username: (Your ACNS Username - used for login to Blackboard)
    

    Save the file and close Emacs. Issue the command

    clean .
    

  3. Open the file hw0a.txt with Emacs in one window, and open a second window to the same directory. In this second window, you will issue commands and copy/paste the resulting screen output into hw0a.txt. Specifically:

    Copy/paste screen output into hw0a.txt that documents each of following commands:

    1. ls -l ~/cop4530
    2. ls -l ~/cop4530/hw0
    3. ls -l ~/.bin
    4. more ~/.bin/c4530
    5. more ~/.bin/co4530
    6. more ~/.bin/clean

    Save and close the file, but do not submit. It will be part of the material submitted after completing part b.

Part b: g++ and Make

Educational Objectives: After completing part b, the student should be able to accomplish the following:

Operational Objectives: This assignment consists of a sequence of steps performed with a Unix login session. To document your completion of these steps, copy/paste the screen results into a file named hw0b.txt through emacs. The result should be a makefile for managing the build of the Square1 game.

Deliverables: Five (5) files: hw0a.txt, hw0b.txt, makefile, makefile2, square1.cpp

Procedural Requirements

  1. Create two logins to your CS account, one on shell and one on linprog. (These will be two separate text windows.) In each login window, change to the directory cop4530/hw0 that you already created as part of Homework 0a. Complete the rest of this assignment inside this subdirectory.

  2. Use the shell login and Emacs to create a text file named hw0b.txt. Type the following information at the top of this file:

    COP 4530 Spring 2011
    Homework Assignment 0b
    (Your Name)
    CS  Username: (Your CS Username   - used for login to CS account)
    FSU Username: (Your ACNS Username - used for login to Blackboard)
    

  3. Use the linprog login to copy the file tests/ftvector.cpp into the hw0 directory. Try to compile this into an executable using g++:

    g++ ftvector.cpp

    What goes wrong? Try again with the command

    c4530 ftvector

    What file is created by the second command? Explain why the second command works and the first does not.

  4. Clean (clean .) the directory and issue the commands

    co4530 ftvector
    g++ -o test.x ftvector.o
    

    What files are created? Run the executable, and try to make sense out of the interface. This is a test program for the TVector<char> container, which we will study in the next couple of weeks.

  5. Copy the following files into your assignment directory:

    hw0/square1.cpp
    cpp/integer.h
    cpp/integer.cpp
    tcpp/tvector.h
    tcpp/tvector.cpp
    

    Issue the following commands

    g++ -c -I. square1.cpp
    g++ -c -I. integer.cpp
    g++ -ogame.x square1.o integer.o
    

    What new files are created? Try playing the game by running the executable.

  6. Now remove the files tvector.h and tvector.cpp, and repeat the three commands. What happens? Use emacs to look inside the remaining files to arrive at an explanation. Issue the following modified commands:

    g++ -Wall -Wextra -c -I. -I/home/courses/cop4530p/spring11/tcpp square1.cpp
    g++ -Wall -Wextra -c -I. -I/home/courses/cop4530p/spring11/tcpp integer.cpp
    g++ -ogame.x square1.o integer.o
    

    What is the effect of the modified commands? Look at the on-line manual for g++ and its parent gcc (type man g++ and then man gcc) to find out about the -I, -W, and -Wall flags, and explain why these new commands work.

  7. Now remove the files integer.h and integer.cpp from your directory and issue the commands:

    g++ -Wall -Wextra -c -I. -I/home/courses/cop4530p/spring11/cpp -I/home/courses/cop4530p/spring11/tcpp square1.cpp
    g++ -Wall -Wextra -c -I. -I/home/courses/cop4530p/spring11/cpp -I/home/courses/cop4530p/spring11/tcpp /home/courses/cop4530p/spring11/cpp/integer.cpp
    g++ -ogame.x square1.o integer.o
    

    What happens? Why? (Play the game some more, and copy/paste a bit of this play screen into hw0b.txt.)

  8. Now remove the object and executable files (using clean .) and issue these commands:

    co4530 square1
    co4530 /home/courses/cop4530p/spring11/cpp/integer
    g++ -ogame.x square1.o integer.o
    

    What is the effect of these commands? Which are easier, the raw g++ commands or these customized command line scripts?

  9. Now we are ready to create a "simple" makefile named makefile. Start by copying the file ~cop4530p/spring11/hw0/makefile.partial to ~/cop4530/hw0/makefile. Edit this file, following the hints provided by the documentation. The idea is to accomplish two things:

    1. Capture the file dependencies implied by #include<> statements; and
    2. Capture the compile commands explored above.
    The file dependencies will guide the compilations required to build (and re-build) a project. The make utility ensures that the compile commands are issued in an appropriate order for the project build.
    Note 1: Dependencies begin in column 1, while compile commands begin with a TAB.
    Note 2: Acknowledge dependencies only from your code files to each other and to the library. Don't acknowledge dependencies created by the library itself.
    Note 3: You need to remove all object and executable files before attempting to build, otherwise the test may not be adequate. This is easily accomplished using the command

    clean .

    created in Homework 0a. Now from inside your Emacs session, place your cursor where you would like the makefile to be placed and enter this Emacs command:

    Ctrl-X i makefile
    

    This will place the makefile in the document.

  10. Finally we are ready to create the kind of makefile you will need for your programming projects. This makefile, named makefile2, will do essentially the same things as the simple one, but it will be more flexible through the use of macros. Begin by copying hw0/makefile2.partial to hw0/makefile2. Edit this file, using the completed lines as a guide, until it properly creates game.x. Be sure to use the macros to define the various paths that are hard-coded in the first makefile. Build with this makefile using the command:

    make -f makefile2

    Keep trying until this command builds the executable without error messages. (See note above about cleaning old object and executable files when testing.)

  11. Here are some experiments to illustrate some of the benefits of using makefiles.

    1. Build twice in a row, without cleaning up in between. You should get the message "'game.x' is up to date.".
    2. Build, then make a small change in square1.cpp and build again without cleaning up in between. You should see only the appropriate files updated.

  12. Submit the files hw0a.txt, hw0b.txt, makefile, makefile2, square1.cpp using the project submit system:

    1. Copy the file ~cop4530p/spring11/hw0/hw0submit.sh into hw0
    2. Change permissions of this file to 700 (executable).
    3. From the shell login, enter the command hw0submit.sh
    4. You should see something on screen as follows:

      yourname@shell:~/cop4530/hw0>hw0submit.sh
      Changing directory to ....
      Archiving...
      a makefile 1K
      a makefile2 1K
      a square1.cpp 3K
      a hw0a.txt 2K
      a hw0b.txt 2K
      Sending mail...
      Cleaning up...
      yourname@shell:~/cop4530/hw0>
      
    5. Check your CS email (from shell) to verify that you receive two automatic responses to the submit:
      1. An email acknowledging receipt of the submission.
      2. An email containing the contents of what was received.
      Be sure that these agree with what you thought was submitted, and correct if necessary. Items may be re-submitted as many times as you like. The new submission is just copied over the old one.

  13. Submit scripts do not work on the program and linprog servers, because they do not suipport email. To see what happens if you try, try it: From your program login, enter the command hw0submit.sh.

Technical Requirements and Specifications

  1. Performance of each procedural step above should be documented in your file hw0b.txt. Documentation should either be a snippet of screen output or, where questions are asked, the answer to the question.

  2. Each makefile should correctly produce two object code files square1.o and integer.o and one executable game.x.

  3. The makefiles should use absolute path names for the course library (i.e., defined from the root /home/courses/...) and use relative self-reference for the assignment directory (i.e., ".").

  4. Your documentation for playing game.x should show that you found an integer with "palindromic period" at least 25 (and not one of those listed in the documentation for square1.cpp). For example:

    SQUARE1: Enter an Integer (0 to quit): 7801686
    Successful on iteration 55. Found the following palindrom:
       8834453324841674761484233544388
    

    shows that the integer 7801686 yields the palindromic integer 8834453324841674761484233544388 after 55 steps (that is, it has palindromic period 55).