For this assignment, you will make the U
class
a (somewhat) STL-compatible container, by adding several methods
and a type.
                
Your U
class must have the same methods as described in HW7, and:
                
U
methods & type:                U(iter, iter)
char
upon indirection.
The iterators are not the same type as U::iterator
.
Instead, they are iterators of any type, where *iter
yields
a char
.
The initial value of the U
object is created from the
string described by the half-open range, as if .append()
were used.
Throw a std::string
error message for the same reasons
that .append()
does.
.begin()
U::iterator
that “points” to the first int
codepoint.
.end()
U::iterator
that “points” just past the last int
codepoint.
U::iterator
int
codepoints
accumulated in the U
object.
.front()
int
codepoint by value.
Throw a std::string
error message if not available.
.back()
int
codepoint by value.
Throw a std::string
error message if not available.
U::iterator
methods:                int
codepoint by value)
No error-checking is required for iterator methods.                 
Const-correctness, both arguments & methods, is your job. For example,
it must be possible to call .begin()
on a const U
.
                
Here is a sample run, where %
is my shell prompt:
                
% cat main.cc #include "U.h" #include <iostream> #include <cassert> using std::cout; using std::hex; using std::showbase; int main() { const char s[] = "\U0001f382 × 11 \u21d2 9\u00be"; U u(s, s+sizeof(s)-1); assert(u == "\U0001f382 × 11 \u21d2 9\u00be"); cout << u << '\n'; // 🎂 × 11 ⇒ 9¾ assert(u.front() == 0x1f382); // birthday cake assert(u.back() == 0xbe); // three-quarters U::iterator it = u.begin(); assert(*it == 0x1f382); // birthday cake it++; assert(*it == ' '); it = u.end(); --it; assert(*it == 0xbe); // ¾ for (auto cp : u) cout << hex << showbase << cp << ' '; cout << '\n'; } % g++ -Wall main.cc U.cc % ./a.out 🎂 × 11 ⇒ 9¾ 0x1f382 0x20 0xd7 0x20 0x31 0x31 0x20 0x21d2 0x20 0x39 0xbe
The requirements are the same as HW7, plus the methods and types shown above.                 
If you have any questions about the requirements, ask. In the real world, your programming tasks will almost always be vague and incompletely specified. Same here.                 
You will turn in at least two files:
U.h
: the interface for class U
U.cc
: the implementation for class U
*.cc
and *.h
files you require.
main
function or main.cc
.
Makefile
.
That’s a lot of files, so construct a tar file, like this:
tar -cvf hw8.tar U.cc U.h other-files …
and turn it in.                 
Use web checkin, or Linux checkin:                 
~cs253/bin/checkin HW8 hw8.tar
Turn in someone else’s work.                 
Modified: 2017-04-27T15:34                  User: Guest                  Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |