For this assignment, you will enhance U
and P
by adding a few
operators.
                
In the examples that follow, assume that u
is a U
object,
p
is a P
object, and s
is a std::string
object.
                
Your classes must have the same methods as described in HW6. In addition, you must define:                 
u = s;
u + u
u + s
s + u
u += s
u += u
std::string
representing a single code point,
as UTF-8 characters, like .get(int index)
:
std::string operator[](int index)
std::string
error message for a bad index.
U
to an output stream:
ostream << u
P
to an output stream:
ostream << p
U
object or a P
object in a
boolean context. A U
or P
is false
iff it is empty.
if (p)
while (!u)
u == u
u == s
s == u
u != u
u != s
s != u
<
, >
, etc., are harder to define, so we’re not doing those.
Const-correctness, both arguments & methods, is your job. For example,
it must be possible to concatenate two const U
objects.
                
Concatenating two U
objects, or a U
and a std::string
,
produces a U
object. It contains the characters from the
left-hand-side object, followed by the characters from the
right-hand-side object.
                
When comparing two U
objects, or a U
and a std::string
, only
compare the accumulated characters. Compare them in the normal way that
std::string
objects are usually compared.
"Sita"
is equal to "Sita"
"Rama"
is not equal to "Sita"
"Sita"
is not equal to "Sitakanta"
Here is a sample run, where %
is my shell prompt:
                
% cat main.cc #include "U.h" #include "P.h" #include <iostream> #include <cassert> using namespace std; const string pub="/s/bach/a/class/cs253/pub/"; // ~ only works in shells int main() { U u; assert(!u); u = "a"; u += " \u263a"; // happy face (lowercase u) { U u2; const string space = " "; u2 += space; u2.append("\U0001f42e"); // cow face (uppercase U) u += u2; } const U u3 = u; assert(u3); assert(u3.size() == 5); assert(u3[0] == "a"); // Let’s start easy. assert(u3.codepoint(2) == 0x263a); // happy face is U+263a assert(u3.codepoint(4) == 0x1f42e); // cow is U+1f42e assert(u3 == u); assert(u3 == "a \u263a \U0001f42e"); assert("a \u263a \U0001f42e" == u3); assert("☮☮☮" != u3); // Cows are peaceful, but … cout << "A happy cow: " << u3 << endl; // a ☺ 🐮 // (If your terminal manages it) P p; assert(!p); p.readfile(pub+"UnicodeData.txt"); assert(p); for (int i=0; i<u3.size(); i++) p.count(u3.codepoint(i)); assert(p.count("Ll")==1); assert(p.count("So")==2); assert(p.size() == 29); cout << "There are " << p.size() << " distinct properties.\n"; } % g++ -Wall main.cc U.cc P.cc % ./a.out A happy cow: a ☺ 🐮 There are 29 distinct properties.
The requirements are the same as HW6, plus:                 
"theta"
is a const char *
, not a std::string
.
"gamma"s
(with a trailing s
) is a const std::string
, however.
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 four files:
U.h
: the interface for class U
U.cc
: the implementation for class U
P.h
: the interface for class P
P.cc
: the implementation for class P
*.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 hw7.tar U.cc U.h P.cc P.h other-files …
and turn it in.                 
Use web checkin, or Linux checkin:                 
~cs253/bin/checkin HW7 hw7.tar
Turn in someone else’s work.                 
Modified: 2017-04-16T16:01                  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 |