CS23 W'09 - Homework exercises 5

Contributing 10%, marked out of 30, due 12noon Fri 13th February.

These exercises focus on the design and implementation of a larger data structure and supporting functions in C99, and the design, implementation, and creation of common code libraries under the Linux operating system. In particular, successful completion of the questions will again enhance your understanding of C's pointers and structures, and your understanding of the Linux online manuals.

Develop each solution in one or more files in its own directory, each with its own Makefile.

How to submit your work:
The following sequence of Linux commands should be used to submit your work by the deadline:
  • Change to your (topmost) directory containing your solutions, e.g.    cd cs23/hw5
  • In this directory create a simple text file, named README, describing anything "unusual" about how your solutions should be located, compiled, executed, and considered.
  • Think of a 6 character random word or number, we'll use AAAAAA
  • Issue the commands:
         tar   zcvf ~cs23/homework/hw5/$USER-AAAAAA.tgz .    (notice the dot on the end of this line)
         chmod 644  ~cs23/homework/hw5/$USER-AAAAAA.tgz
    
    (and determine what is happening here!)

Grading will focus on the correctness of your solutions, but will also consider good coding style - including consistent formatting, selection of identifier names, and use of meaningful comments.

Good luck.

Chris McDonald
February 2009.


  • Introduction to Q1, Q2, and Q3: The C99 language does not provide a single set of standard functions to provide a GUI (unlike Java). Instead, there are a number of widely-used GUI toolkits, or libraries, to build GUIs on a variety of operating system platforms. One such toolkit is Tcl/Tk (pronounced tickle-T-K), which is really a "scripting language" with graphical commands. Because GUI toolkits are often quite large, learning them quickly can be difficult, and so we often employ just a subset of their features to meet our needs.

    The simple game jawbreaker is often seen on Windows-CE based PDAs and mobile phones. It is a little like the game tetris in that the objective is to maximize your score by arranging (falling) items. While tetris requires you to arrange the falling items, jawbreaker requires you to select sets of adjacent, identically colored items to make them fall.

    A number of items form a set, iff:

    The game proceeds as follows:

    The directory http://www.cs.dartmouth.edu/~chris/cs23/jawbreaker/ contains some files to get you started - take a copy of all files.


    1. Before you start any coding - design a list of tests that will enable you to extensively test an eventual implementation of jawbreaker.

    2. [10 marks] Design and develop your own implementation of jawbreaker. You will only need to extend the file jawbreaker.c. In particular, you will not need to modify (nor understand) any of the Tcl/Tk GUI code, but you will call the provided functions to interact with the GUI.

      Complete your program by 12noon Wednesday 11th. and place a copy of it in your home directory with the following commands:

                cp  jawbreaker  ~/jawbreaker
                chmod  755  ~/jawbreaker
      
      this will enable other students to copy and execute your program, but they will not be able to see your source code. Testers should just run and test other students' programs, but should not look at the code.

      You may exprience some difficulties getting your application to display the graphical output, depending on where you're working and what software you have installed on you laptops.

      If sitting at a Linux machine in S.001, then you will need to compile and link your jawbreaker on a machine that has the Tcl/Tk libraries installed (e.g. moose.cs.dartmouth.edu).

      Login to moose with:

          ssh -X moose.cs.dartmouth.edu
              ....develop, compile and link your program (logged into moose)
          ./jawbreaker (logged into moose)
      

      If working on your own Linux or Macintosh laptop, the above command sequence should also work from anywhere on campus.

    3. [10 marks] In your role as a tester, test another student's program against the tests that you previosuly developed.

      You should test the code of the student immediately after you from this list.

      Here, marks are not being awarded, or deducted, for the success or failure of the other student's program. Marks are awarded for your description of how their program performs against your tests.

      Write your test-report as a simple ASCII-text file, do not submit it as an MS-Word document nor as HTML.

    4. [10 marks] A dictionary data structure is often used to provide a mapping between a word (a string) and its definition (another string). A hash table is often used to implement the dictionary, as it can provide (almost) constant speed lookups. At the core of the hash table is a hashing function, which is a many-to-one function mapping a string to an integer. An example of one such hashing function is:

          #include <stdlib.h>
      
          int hash(char *str)
          {
              int h = 0;
      
              while(*str) {
                  h = h * 8 + *str ;
                  ++str;
              }
              return( abs(h) );
          }
      

      Design and develop code to implement a dictionary using a hash table. We will need code to add new definitions, to determine if a requested definition exists, and to fetch a requested definition. For simplicity, assume that we'll never remove definitions. Firstly, test your implementation with some simple data such as:

                H <tab> hydrogen
                He <tab> helium
                Li <tab> lithium
                Be <tab> beryllium
      

      Then (and this is the main exercise) develop one or more sets of test data that thoroughly test your implementation. In a separate (plain text) file, explain how each of your chosen data sets tests your implementation.

    5. [0 marks] Very difficult and not being assessed.

      Consider a text file of data consisting of a number of lines of four integers each. Each line contains the non-negative x, y, and z integer coordinates of a point in a rectangular prism (it is not necessarily a cube). Each line of 3 coordinates also contains a single data measurement taken at those coordinates - it could be the temperature, radiation intensity, or air pressure from inside a nuclear reactor. Any data points not explicitly provided are considered to have the value zero.

      The data has been captured by a device that flys around randomly in the 3D space, and so the data points "arrive" in any order. As such, you don't really know the bounds of the 3D space until you've finished reading all of the data. However, you only have time to read and record the data items once (as the reactor melts down!) so you'll need to build a 3D data structure "on the fly".

      Write a program which is able to read in all of the data points, dynamically growing a 3D data structure to hold the rectangular prism of data as necessary.

      This question is actually developing a 3-D version of our TSV library. Could we develop an N-D version?