CS253: Software Development with C++

Spring 2018

HW 7

CS253 HW7: I/O Streams!                

Description                

For this assignment, you will write two classes, IFSerial and OFSerial. They will behave much like ifstream and ofstream, except that they will read & write serialized data.                 

Methods                

Your classes must have the folowing operators & methods:                 

IFSerial:

OFSerial:

The above may be methods, or free functions, as you wish.                 

Const-correctness, both arguments & methods, is your job. For example, it must be possible to call .eof() on a const IFSerial.                 

You may add other functions, methods, or operators, public or private, as you wish.                 

.eof()                

.fail()                

Boolean context                

FSerial.h                

Errors                

Test program                

Here is a sample test program:                 

    % cat test.cc
    #include "FSerial.h"
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <cassert>

    using namespace std;

    int main() {
        cout << "Test begins.\n";
        {
            OFSerial out("data");
            out << true;
            out << 'x' << 42;
        }

        IFSerial in("data");
        bool b; char c; int i;
        in >> b >> c;
        in >> i;
        assert(b);
        assert(c == 'x');
        assert(i == 42);
        assert(in);
        assert(!in.fail());
        assert(!in.eof());
        in >> i;
        assert(!in);		// same as in.fail()
        assert(in.fail());	// a conversion (in >> i) failed
        assert(in.eof());	// we hit end-of-file


        // Read the raw datafile
        ifstream raw("data");
        string data;
        while (raw.get(c))
            data += c;
        assert(data == "t" "cx" "i\x10\x2a");   // true, 'x', 42

        // Try writing to a file that can’t be created.
        OFSerial o("/this/does/not/exist");
        assert(!o);
        assert(o.fail());
        o << 9371647;	    // Must not complain, throw, or exit.
        assert(!o);
        assert(o.fail());

        cout << "Test ends.\n";
        return 0;
    }
    % g++ -Wall test.cc hw7.a
    % ./a.out
    Test begins.
    Test ends.

Debugging                

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements                

Requirements are not inherited, except as noted below:

Testing                

Tar file                

How to submit your homework:                

    ~cs253/bin/checkin HW7 hw7.tar

How to receive negative points:                

Turn in someone else’s work.                 

User: Guest                 

Check: HTML CSS
Edit History Source

Modified: 2018-04-20T14:28                 

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building