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:                 
Serial
, and copies the information.
Serial
, and copies the information.
put(bool)
put(short)
put(int)
put(long)
put(char)
put(string)
get(bool &)
get(short &)
get(int &)
get(long &)
get(char &)
get(string &)
throw
a descriptive std::string
upon any problem.
str()
str(string)
size()
int
that is the size, in bytes, of the
accumulated serialized string.
empty()
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
make
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
./a.out
We will supply a main program to do the testing that we want. You should do something similar.                 
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()); s.put(4); assert(s.str() == "i\x04" && s.size()==2 && !s.empty()); s.put('5'); assert(s.str() == "i\x04" "c5" && s.size()==4); s.put(66L); assert(s.str() == "i\x04" "c5" "l\x10\x42" && s.size()==7); int i; char c; long l; s.get(i); assert(i == 4 && s.str() == "c5" "l\x10\x42" && s.size()==5); s.get(c); 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 { s.get(c); } catch (string st) { caught = true; } assert(caught); s.get(l); assert(l == 66 && s.empty()); s.str("S\x03xyz"); string st = "foobar"; s.get(st); 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:                 
main()
in hw5.a
.
.get()
the wrong type will result in a descriptive
error std::string
being thrown, but a subsequent attempt to get
the correct type must succeed.
hw5.tar
*.cc
)
*.h
), including Serial.h
Makefile
, with a capital M
)
Makefile
’s default target must create the library file
hw5.a
.
Makefile
must use at least -Wall
when compiling.
~cs253/bin/checkin HW5 hw5.tar
Turn in someone else’s work.                 
User: Guest