Tuesday, February 17th at 11:59pm
For this assignment, you'll
BigInt
class,isEven
function to your BigInt
class,In addition to meeting the requirements from the previous
assignment, your BigInt
class should also have the
following:
const string &s
, for example)
and creates a new BigInt
out of it:
string s = "0"; BigInt b1( s ); b1.print(); // should print '0' (without quotes) BigInt b2( "314159" ); b2.print(); // ...and '314159' BigInt b3( "123456789" ); b3.print(); // ...and '123456789' BigInt b4( "99999999999999999999" ); b4.print(); // ...and '99999999999999999999'Remember, you shouldn't display any leading zeros or whitespace when printing your number.
const BigInt &other
, for example) and
creates a new BigInt
that has the same value as the
BigInt
that is passed in. For example:
string s = "0"; BigInt b1( s ); b1.print(); // should print '0' (without quotes) BigInt b2( b1 ); b2.print(); // ...and '0' again BigInt b3( "99999999999999999999" ); b3.print(); // should print '99999999999999999999' BigInt b4( b3 ); b4.print(); // ...and '99999999999999999999' again
isEven
. It should take no arguments, and return a
boolean value that is true if the BigInt
is even, false
otherwise. For example:
string s = "0"; BigInt b1( s ); cout << b1.isEven() << '\n'; // should print '1' (booleans display as 0 and 1) BigInt b2( "314159" ); cout << b2.isEven() << '\n'; // ...not even, so we should see '0' BigInt b3( "42" ); cout << b3.isEven() << '\n'; // ...even, so we expect '1'
const
keyword where you think it's appropriate. Remember,
variables can be const if they're not supposed to change, and class
functions can be const if they're not supposed to change any data in
the class.
If you just can't stand using const
in some place that
you think it could possibly appear, justify your reasoning in a
comment.
As usual, you should be able to compile your code using the Makefile from the last assignment by typing:
If all goes well, you shouldn't see any error messages. Then you can run your code by typing:
Whatever you've included in your main
function should
run, and any output that is generated should appear on your
screen.
When you're happy with your code, use the
turnin program to submit your BigInt.cc
and
BigInt.h
files. Use assignment3
as the
assignment name.
BigInt.cc
BigInt.h
You've finished, and there's nothing new on the internet, so it's time for...
Add the following public utility functions to your
BigInt
class:
toString
function that takes no arguments, and
returns a string
version of the number (can you do this
efficiently?)hashCode
function that takes no arguments, and
returns an unsigned int
that represents a hash code of
the number (make sure to implement a good hash
function -- otherwise, the gods
of cryptography will smite you, and nobody wants that.)