CMSC 202 Spring 2001

Project 2

A Big Binary ADT


Assigned  05 March 2001
Due  18 March 2001


Background

    Large scale projects generally consist of many objects, each of which brings an ADT to life.  These classes use each other's services and may include other objects as their own private data members.  One of the advantages of object oriented programming is the ability to design, develop and test each class independently of the others. Testing a class is accomplished by writing a test program that can be used to exercise the class by invoking each public method in various states.
    In this project, you will develop a class according to the ADT specifications below.  A test program has been written for you.  Your job is to implement the class in such a way that it passes all the tests.

Description

    On the Linux system at UMBC, integer variables are 32 bits in length.  However, sometimes programs require values that exceed 32 bits in size.  To fill this void  you will implement a BigBinary class which emulates a 40-bit integer. (Yes, we know that our system supports a 64-bit "long long" variable type,  and therefore BigBinary isn't' really needed if it's just 40-bits long, but we didn't want to deal with 65+ bit integers).  Because the BigBinary represents integer values, it makes good sense to overload many arithmetic, logical and bit oriented operations so that we can use BigBinary objects just like the integers that they are designed to support.

    The main driver for this project, Proj2.C is being provided for you.  This program takes two integer values as command line arguments and exercises them as BigBinary objects.  Your job is to implement the BigBinary class described below so that you can compile, link and run Proj2.  You should run Proj2 using all combinations of values -- both positive, both negative, etc.

    You will also be exposed to the "make" utility and "makefiles".  A makefile is also provided for you for this project, and the TAs will discuss makefiles in discussion session this week.  You are responsible for providing your own makefile for all future projects in this course.

    Your Tasks:

  1. Copy the file /afs/umbc.edu/users/d/e/dennis/pub/CMSC202/Proj2/Proj2.C into your directory.
  2. Copy the file /afs/umbc.edu/users/d/e/dennis/pub/CMSC202/Proj2/Makefile into your directory.
  3. Implement the BigBinary class as described below.  Remember that your class definition should be in your .H file and the implementation in your .C file.  NO CODE is to be written in the .H file.
  4. Compile, link and test your BigBinary class until it successfully supports all required operations used in Proj2.C (and therefore produces the proper output)
  5. Submit  the required files

ADT Definitions

    The BigBinary class must support the following public operations.  You may create as many private data members or private member functions as you wish, but you may not provide any public operations other than those listed here. The specific parameters and return type of some operations are not specified and are up to you.  Also, if there is a choice between implementing these operations as member or non-member (possibly friend) functions, that choice is also up to you.  Just remember the two fundamental rules:
  1. You MAY NOT  provide any public operations other than those listed here
  2. Your class must work with Proj2.C found in Mr. Frey's public directory

Implementation Requirements and Restrictions

Implementation Hints


2's Complement

    Almost all computers represent values as binary numbers using the 2's complement representation.  In this representation, the high-order bit (bit [0] of your array) is the "sign" bit.  If the bit is on, the value represented is negative.  If the sign bit is off, the value is positive (or zero).
    To change a positive value to negative, or a negative value to positive there are two steps
  1. Complement all the bits (change all 0s to 1 and all 1s to 0, including the sign bit)
  2. Add one
    For example, let's change change +5 to -5:
  1. Represent +5 in binary -- 00000101
  2. Complement             --    11111010
  3. Add one                   --    11111011  to get -5
    We can validate this representation by adding this binary value with +5  to get 0.
              11111011    -5
         + 00000101   + 5
           --------   ---
           00000000     0

    Similarly, we can change -5 back to +5 with same steps

  1. -5 in binary --  11111011
  2. Complement--   00000100
  3. Add one--         00000101 = 5

Hexadecimal

    Because humans don't deal well with lots of 1s and 0s, computer scientists often use the hexadecimal (base 16) number system to represent values.  In this system, there are 16 symbols -- 0 - 9, A, B, C, D , E, F where 0 - 9 have their usual meaning, A = 10, B = 11, and so forth.
    Since 16 = 24, each group of 4 binary bits can be represented by one hex symbol.  To change from binary to hex, group your binary digits in groups of 4 starting with the least significant bits and translate them into hex symbols based on the values listed above. For example, to change 01011100101 in to hex.
  1. Break the bits into groups of four starting at the right -- 010 1110 0101.  If the leftmost group has less than 4 digits, that's okay.
  2. Now compute the value of each group:

  3.         010 = 2    1110 = 14  0101 = 5
  4. Form the hexadecimal value:     2E5

Sample Output

    You can use this sample output to compare  your results.  Please note that this sample is not complete.  Since Proj2 takes two numeric command line arguments, you should test every possible combination of positive, negative and zero values in every possible order.
    Also note that the graders may not use the same values used to generate this output.
    Your output does not have to be exact, but must be similar and easy to read.


Makefiles

    The "make" utility is used to help control projects with large number of files.  It consists of targets, rules, and dependencies.
For this project, simply typing the command make or make Proj2 at the Unix prompt will compile and link your source files with Proj2.C and produce a new executable called Proj2.  Typing make clean will remove any extraneous files in your directory such as .o files,  and core files.  Typing make cleanest removes all .o files, core, Proj2 and backup files made by your editor.  Copy the file /afs/umbc.edu/users/d/e/dennis/CMSC202/Proj2/Makefile to your directory.
    See a documented makefile for more information, or see the Project page for a link to even more info about make


What to Submit

    For this project, you must submit the following files:
  1. Your makefile -- it must be named "makefile" or "Makefile".  The graders will simply type "make" and your files must compile and link all source files as appropriate
  2. BigBinary.H-- the definition file for the BigBinary class.
  3. BigBinary.C -- the implementation file for the BigBinary class