CS105: Introduction to Computer Programming: C++

Assignment #4: File I/O

Due

Tuesday, February 24th at 11:59pm

Overview

For this assignment, you'll add two I/O functions -- save and load -- to your BigInt class.

Requirements

In addition to meeting the requirements from the previous assignments, your BigInt class should also have the following:

  1. Inside your class, you should add a function called save that takes a string filename (const string &filename, for example) and saves the BigInt to 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 the load function, which is described next.

  2. Add a static load function to your class. Just like the save function, this function should take a const string reference that represents a filename (e.g. const string &filename). The function should return a BigInt that it reads from filename. For example:
      BigInt b1( "314159" );
      b1.save( "mynum.dat" );  
      BigInt b2 = BigInt::load( "mynum.dat" );
      b2.print();              // should display "314159"
    

Compiling and Running

As usual, you should be able to compile your code using the Makefile from the last assignment by typing:

make

If all goes well, you shouldn't see any error messages. Then you can run your code by typing:

./main

Whatever you've included in your main function should run, and any output that is generated should appear on your screen.

Turning it in

When you're happy with your code, use the turnin program to submit your BigInt.cc and BigInt.h files. Use assignment4 as the assignment name.

Submission Checklist

Still too easy, huh? Then bring on the...

Extra Credit (+20%)