Tuesday, February 24th at 11:59pm
For this assignment, you'll add two I/O functions --
load -- to your
In addition to meeting the requirements from the previous
BigInt class should also have the
savethat takes a string filename (
const string &filename, for example) and saves the
BigIntto that file. The function should not return anything. For example:
BigInt b1( "314159" ); b1.save( "mynum.dat" ); // should create a file called 'mynum.dat'
You can write data to the file in any format that you'd like. The
main requirement is that you be able to read that data in again using
load function, which is described next.
loadfunction to your class. Just like the
savefunction, this function should take a const string reference that represents a filename (e.g.
const string &filename). The function should return a
BigIntthat it reads from
filename. For example:
BigInt b1( "314159" ); b1.save( "mynum.dat" ); BigInt b2 = BigInt::load( "mynum.dat" ); b2.print(); // should display "314159"
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
assignment4 as the
Still too easy, huh? Then bring on the...
loadfunctions above to write and read files that are as small as possible. (But no smaller.)
saveBannerthat takes a string filename (
const string &filename, for example) and writes a beautiful ASCII-art version of the
BigIntto that file. The function should not return anything. For example, this code:
BigInt b1( "30" ); b1.saveBanner( "banner.txt" );...might produce a text file called
moe.cs~> ./main moe.cs~> ls *.txt banner.txt moe.cs~> cat banner.txt 333333 00000 33 33 00 00 3 33 00 00 33 00 00 333 00 00 3 33 00 00 33 33 00 00 333333 00000
Bonus points for crazy things like line wrapping or variable-width fonts.