Tuesday, March 10th at 11:59pm
Add an overloaded addition operator to your BigInt
class.
Also, put an overloaded display operator in there.
In addition to meeting the requirements from the previous
assignments, your BigInt
class should also have the
following two operators:
You've already written a print
method, but that's kind
of awkward. Leave your print
method there, but add an
overloaded stream insertion operator (<<
) to your
class.
Overloading a stream insertion operator for any class always follows the same pattern:
operator<<
.ostream& os
) and a const reference to an
instance of your class (e.g. const BigInt &rhs
).rhs
to the
stream os
.For example:
BigInt b1( "42" ); cout << b1 << endl; // should display 42 to standard output
Add an addition operator to your class.
The addition operator +
should be implemented as a
global friend function of the BigInt
class. This
function should take two BigInt
arguments  the left and
righthand side of the operator  and should return a
BigInt
that represents the sum of the left and the right
arguments.
For example:
BigInt b1( "3" ); BigInt sum1 = 1 + b1; cout << sum1 << endl; // should display 4 BigInt b2( "9" ); BigInt b3( "1" ); BigInt sum2 = b2 + b3; cout << sum2 << endl; // should display 10 BigInt b4( "1999" ); BigInt sum3 = b4 + 3; cout << sum3 << endl; // should display 2002 BigInt b5( "9999999999" ); BigInt b6( "1" ); cout << (b5+b6) << endl; // should display 10000000000
You do not have to worry about overflow beyond 20 digits, i.e. you can assume that the sum of the two numbers will be at most 20 digits long.
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 assignment6
as the
assignment name.
BigInt.cc
BigInt.h
It's chewy on the inside but crunchy on the outside!

operator to implement BigInt
subtraction. If underflow occurs (i.e. 510=5
) just
return a BigInt of zero.*
operator to implement BigInt
multiplication. The more efficiently you can do this, the
better.