Upon reflection, you have decided that the class U
, from HW5,
is trying to do too many things. It reads data files, decodes UTF-8,
parses properties files, counts properties, etc. That’s too much!
                
For this assignment, you will split the functionality of the HW5
U
class into two classes, U
and P
. The U
class will
handle UTF-8 translations, and the P
class will handle properties.
                
More precisely, the U
class will accumulate a series of UTF-8
characters (via ctor, .readfile()
, and .append()
,
and return them as either UTF-8 strings (via .get()
)
or as integer Unicode code points (via .codepoint()
).
                
On the other hand, the P
class will read a properties file
(via ctor or .readfile()
), accumulate property counts
(via .count()
) and return the count for a given property
(via .count()
).
                
Most methods of the HW5 U
class will have counterparts in
the new classes, but some are different.
                
U
                Your U
class must have the following public methods:
                
U
, and copies the information.
std::string
arguments: a data filename.
The file is read as if readfile
were called.
Throws a std::string
error message upon error.
U
, and copies the information.
readfile
std::string
filename, and reads the UTF-8 characters from
it. Throws a std::string
error message upon error. If called
again, the data accumulates.
append
std::string
(not a filename), and treats the UTF-8
characters in it as if they were the result of calling readfile
.
Throws a std::string
error message upon error.
get
std::string
.
get
int
index, and returns a std::string
containing the
UTF-8 character at that point. The first UTF-8 character is at index
zero. Throws a std::string
error for an invalid index.
get
get
, but takes two int
values: starting and ending positions.
They represent a half-open interval: get(7,9)
returns a
std::string
containing two UTF-8 characters, the one at 7 and the
one at 8.
Throws a std::string
error for an invalid argument.
codepoint
int
index, and returns a int
value representing
the Unicode codepoint character at that point.
The first UTF-8 character is at index zero.
Throws a std::string
error for an invalid index. .get()
, except that it returns an int
.
size
int
.
empty
true
iff the object
is empty (no characters).
clear
You may define other methods or data, public or private, as you see fit.                 
P
                Your P
class must have the following public methods:
                
P
, and copies the information.
std::string
arguments: a property filename.
The file is read as if readfile
were called.
P
, and copies the information.
readfile
std::string
property filename, and reads property
information. Throws a std::string
error message upon error.
props
std::set<std::string>
of the names
of all the possible properties, as read from the properties file.
count
int
codepoint, and counts it. It is not an error
to count a codepoint which has no corresponding property.
count
std::string
which is a property name (e.g., Lu
)
and returns the number of times that characters with that property
have been encountered via the other .count()
.
size
readfile
.
empty
true
iff the object
is empty (no property names).
clear
You may define other methods or data, public or private, as you see fit.                 
Const-correctness, for both classes, both arguments & methods, is your
job. For example, it must be possible to call .size()
on a
const
object, or to pass a const string
to .readfile()
.
                
Foo
,
then you should turn in Foo.h
and Foo.cc
.
*.cc
files, as shown below.
Here is an example of how we may test your code.
“%
” is my shell prompt.
                
% tar -xf hw6.tar % cp -f some-other-place/main.cc . % cat main.cc #include "U.h" #include "P.h" #include <iostream> using namespace std; const string pub="/s/bach/a/class/cs253/pub/"; // ~ only works in shells int main() { try { U u; u.append("a³+b³≠c³"); P p(pub+"UnicodeData.txt"); for (int i=0; i<u.size(); i++) p.count(u.codepoint(i)); cout << "Should be 8: " << u.size() << '\n' << "Should be 2: " << p.count("Sm") << '\n' << "Should be b³: " << u.get(3,5) << '\n'; try { u.readfile("/bogus"); } catch (const string &msg) { cout << "I expected this: " << msg << '\n'; } return 0; } catch (const string &msg) { cout << "Unexpected error: " << msg << '\n'; } } % g++ -Wall *.cc % ./a.out Should be 8: 8 Should be 2: 2 Should be b³: b³ I expected this: U::readfile: can’t open /bogus %
Don’t just modify your current U.h
and U.cc
files. You might
need them, someday. Instead, create HW5 and HW6 directories and put the
different versions there. mkdir is your friend. Disk space is cheap.
                
main()
function.
If you do, you will lose one full point.
exit()
, or emit any output.
P::readfile
is called twice
on the same object.
P::count(int)
is not defined before
P::readfile
is called.
P::count(int)
is not defined if P::readfile
has been called twice. That’s because calling P::readfile
twice invokes undefined behavior. At that point, all bets are off!
count
, return zero if that property is not defined,
or no characters with that property have been encountered.
For example, .count("<*>")
will return zero,
since that’s a very poor property.
main()
function.
If you do, you will lose one full point.
<stdio.h>
or <cstdio>
facilities,
such as scanf
, fopen
, and getchar
.
ifstream
.
new
/delete
/new[]
/delete[]
,
if you must do your own memory allocation.
main()
function.
If you do, you will lose one full point.
65
)
instead of char constants ('A'
) for printable characters.
"Something went wrong"
is not good enough.
main()
function.
If you do, you will lose one full point.
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 hw6.tar U.cc U.h P.cc P.h other-files …
and turn it in.                 
Use web checkin, or Linux checkin:                 
~cs253/bin/checkin HW6 hw6.tar
Turn in someone else’s work.                 
Modified: 2017-04-05T16:08                  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 |