CS253: Software Development with C++

Spring 2018

HW 5

CS253 HW5: Time to get classy!                


For this assignment, you will write a class called Serial (that’s a capital letter S) which builds upon your previous work. Specifically, you will provide Serial.h (capital S), which will contain the interface of class Serial, and hw5.a, which will contain the implementation of class Serial.                 

The class will, conceptually, contain a serialized string. You can add values to the back of the string, and retrieve values from the front of the string. Adding values makes the string longer, and retrieving values makes the string shorter. In addition, you can set and retrieve the accumuated serialized string.                 

Values can only be added to the back of the string, and can only be removed from the front of the string. That is, if you add, in order, the int 3, the char 'x', and the short 5, then the first thing removed must be an int, which will be 3, followed by a char, followed by a short. It’s a FIFO queue.                 

In the previous paragraphs, the string is merely for exposition. How you actually store the data in this class is up to you.                 


Your class must have the following public methods:                 

Default constructor
Accumulated string is initially empty.
Copy constructor
Takes another Serial, and copies the information.
Assignment operator
Takes another Serial, and copies the information.
Add the datum to the back of the serialized string.
get(bool &)
get(short &)
get(int &)
get(long &)
get(char &)
get(string &)
Remove the datum from the front of the serialized string, and unserialize it into the variable, replacing any previous value. throw a descriptive std::string upon any problem.
Retrieve the accumulated serialized string, without changing the object.
Set the accumulated serialized string.
Returns a int that is the size, in bytes, of the accumulated serialized string.
Returns true if the accumulated serialized string is empty, false if not.

Const-correctness, both arguments & methods, is your job. For example, it must be possible to call .size() on a const Serial, or to pass a const string to .put().                 

You may define other methods or data, public or private, as you see fit.                 

It is highly recommended that you override << to display the contents of a Serial.                 


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

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a


You will have to write a main() function to test your code. Put it in a separate file, and do not make it part of hw5.a. You will also have to create Serial.h, and put it in hw5.tar.                 

We will test your program by doing something like this:                 

    tar -x <hw5.tar
    mkdir /some/place/test-dir
    cp hw5.a Serial.h /some/place/test-dir
    cd /some/place/test-dir
    cp /none/of/your/business/test-program.cc .
    g++ -Wall test-program.cc hw5.a

We will supply a main program to do the testing that we want. You should do something similar.                 

Sample Run                

Here is a sample run, where % is my shell prompt:                 

    % cat assignment_test.cc
    #include "Serial.h"
    #include <iostream>
    #include <string>
    #include <cassert>

    using namespace std;

    int main() {
        cout << "Test begins\n";
        Serial s;

        assert(s.str() == "" && s.size()==0 && s.empty());

        assert(s.str() == "i\x04" && s.size()==2 && !s.empty());
        assert(s.str() == "i\x04" "c5" && s.size()==4);
        assert(s.str() == "i\x04" "c5" "l\x10\x42" && s.size()==7);

        int i; char c; long l;

        assert(i == 4 && s.str() == "c5" "l\x10\x42" && s.size()==5); 

        assert(c == '5' && s.str() == "l\x10\x42" && s.size()==3); 

        // The next item is a long.  Try to get a char, which will fail.
        bool caught = false;
        try {
        catch (string st) {
            caught = true;

        assert(l == 66 && s.empty());

        string st = "foobar";
        assert(st == "xyz" && s.empty());

        cout << "Test ends\n";

        return 0;

    % g++ -Wall assignment_test.cc hw5.a
    % ./a.out
    Test begins
    Test ends


The requirements are the same as those for HW4, plus:                 

Tar file                

How to submit your homework:                

    ~cs253/bin/checkin HW5 hw5.tar

How to receive negative points:                

Turn in someone else’s work.                 

User: Guest                 

Edit History Source

Modified: 2018-04-02T17:07                 

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