The objective of this assignment is to practice writing C++ classes which use dynamic memory allocation/deallocation and overloaded operators.
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).
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:
}
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.
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.
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.