Project 3: Variably-Sized Integers

Assigned:  11 March 2002

Homework Due:  24 March 2002

Project Due: 31 March 2002


Objective

The objective of this assignment is to practice writing C++ classes which use dynamic memory allocation/deallocation and overloaded operators.


Background

We want to write a class which will mimic the behavior of C++ unsigned int type, but whose size will be determined at runtime by the value to be stored in each particular instance.  There will be no "maximum" value for the class; any string of hexadecimal characters will have a corresponding VarInt object (up to fundamental memory limitations, of course).

 


Assignment

You will implement the class whose definition is shown below.  You may add whatever private data members and public or private functions you see fit; however, you must implement all public member functions whose prototypes are shown here (meaning the same names, parameter types, and return types, and const-ness).  We will be linking your compiled code in with our own main function for testing purposes, so you need not submit a main function definition; however, you will probably want to write one for yourself to help with testing your class implementation.

class VarInt
{
    public:
              ~VarInt ( );  // destructor; destroys all dynamically-allocated memory

              VarInt ( string hex_representation );  // Parameter: a string of hexadecimal digits

 

             VarInt ( const VarInt & ); // Copy constructor; new VarInt will be an exact copy of original,
                                                    // but not share any memory with copied object.

            VarInt& operator = ( const VarInt & );  // Assignment operator; same behavior as copy constructor

            VarInt& operator+ ( const VarInt & ) const;  // Addition

            VarInt& operator- ( const VarInt & ) const;  // Subtraction

            bool operator< ( const VarInt& ) const;  // Less than

            bool operator> ( const VarInt& ) const; // Greater than

            bool operator== ( const VarInt& ) const; // Equality

            bool operator!= ( const VarInt& ) const; // Inequality

            void Print ( ) const;  // Prints out the hexadecimal representation of a VarInt 

            int GetNumDigits ( void ) const; // returns number of hex digits needed to store a VarInt's value

    private:
               

}


Homework Portion

The homework portion of this project will be worth 15% of the project grade.  For the homework, create a plain text file (end the filename in .txt) which includes the prototypes of the functions you intend to use, the class definition(s) you intend to use, and a one- to two-paragraph (approximately) description of how you intend to solve the problem and the general design of your class(es).  You may use pseudocode if you wish.  (This file is not intended to be compiled; it is only for you to express the design of your program.)  Your homework will be graded both on the merits of your design and on the extent to which you follow that design in the implementation of your program.  Remember to submit your homework file by the homework due date.  Late homework submissions are not accepted.


Requirements

  1. Write your program in C++, using the g++ compiler installed on the linux systems at UMBC (linux.gl.umbc.edu) under directory /usr/local/bin. Use C++ input and output, not printf and scanf.  The graders will compile your code using the -ansi and -Wall switches, so make sure to test your program with these.
  2. As per the syllabus, your project must compile (under the above-mentioned compiler) in order to receive credit.  See the syllabus for more details.
  3. You must follow the course style guidelines listed on the course web page.  Your makefile must, when "make VarInt" is run, produce .o file(s) which can be successfully linked in with the main function used for grading.
  4. Write and submit separate header and class files, as discussed in lecture.
  5. Be sure that in your class definition and implementation, you have spelled the names of all public member functions listed above, and the name of the class, correctly!  Failure to do so will cause your code not to compile with the main function used for grading.
  6. You must use new and delete for dynamic memory allocation and deallocation (not malloc and free).
  7. You must name your VarInt header file VarInt.h .  Additionally, your VarInt.h must #include any header files necessary for compiling with your code; the file containing the main function used for grading will only #include VarInt.h .

 


Turning in your program

You must include the following statement in a comment section of your program:

 

I have read and I understand the course policy on cheating. By submitting the following program, I am stating that the program was produced by my individual effort.

Turn in your homework and program files using the submit utility, by using the following command at the unix prompt:

submit cs202_02 < hw3 | proj3 > filename

where filename is the name of the file you wish to submit.  Remember to submit a plain text file for the homework assignment, your C++ source and header files for the project, and your makefile.  After entering this command, you should get a confirmation that submit was successful:

Submitting filename...OK

You can check your submission by entering the command:

submitls cs202 < hw3 | proj3 >

This will show the names of all files you have submitted for the homework or project, along with the size and submission date and time of each.  


Late Policy Reminder

This project is due by midnight (1 minute after 11:59pm) on Sunday, 31 March 2002. We will use the system clock as the final arbiter of time and date. Projects turned in up to 24 hours late will receive a 10% penalty; project submitted between 24 and 48 hours late will receive a 25% penalty.  Projects will not be accepted past 48 hours after the due date.  Late homework submissions are not accepted.