Hw5 6 Continuation of Hw5 5 Let P3

CS253 HW5: Time to get classy!

Description

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.

Methods

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.
Destructor
Destroys.
put(bool)
put(short)
put(int)
put(long)
put(char)
put(string)
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.
str()
Retrieve the accumulated serialized string, without changing the object.
str(string)
Set the accumulated serialized string.
size()
Returns a int that is the size, in bytes, of the accumulated serialized string.
empty()
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.

Debugging

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

            export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a          

Testing

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.

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());          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     %        

Requirements

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

  • Do not put main() in hw5.a.
  • Attempting to .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.

Tar file

  • The tar file for this assignment must be called: hw5.tar
  • It must contain:
    • source files (*.cc)
    • header files (*.h), including Serial.h
    • Makefile (Makefile, with a capital M)
  • The Makefile's default target must create the library file hw5.a.
  • Your Makefile must use at least -Wall when compiling.

How to submit your homework:

  • Use web checkin, or Linux checkin:
          ~cs253/bin/checkin HW5 hw5.tar        

How to receive negative points:

Turn in someone else's work.

raymondwhint1963.blogspot.com

Source: https://www.cs.colostate.edu/~cs253/Spring18/HW5

0 Response to "Hw5 6 Continuation of Hw5 5 Let P3"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel