Tuesday, March 10th at 11:59pm
Add an overloaded addition operator to your
Also, put an overloaded display operator in there.
In addition to meeting the requirements from the previous
BigInt class should also have the
following two operators:
You've already written a
<<) to your
Overloading a stream insertion operator for any class always follows the same pattern:
ostream& os) and a const reference to an instance of your class (e.g.
const BigInt &rhs).
rhsto the stream
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
right-hand side of the operator -- and should return a
BigInt that represents the sum of the left and the right
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
When you're happy with your code, use the
turnin program to submit your
BigInt.h files. Use
assignment6 as the
It's chewy on the inside but crunchy on the outside!
-operator to implement BigInt subtraction. If underflow occurs (i.e.
5-10=-5) just return a BigInt of zero.
*operator to implement BigInt multiplication. The more efficiently you can do this, the better.