For this assignment, you will write a class called U
(that’s a
capital letter) which builds upon your previous work. The class will
read a properties file, and UTF-8 characters from a number of files.
It will provide information about the properties, and the accumulated
string.
                
Your class must have the following public methods:                 
U
, and copies the information.
std::string
arguments: a properties filename, and some
literal data. It parses the properties file as if propfile
were
called, then processes the literal data as if it were read from a file.
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.
propfile
std::string
properties filename. Parses that file.
Throws a std::string
error message upon error.
size
int
.
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
s, 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.
propcount
std::string
which is a property name (e.g., Lu
)
and returns how many times characters with that property have
been encountered.
props
std::set<std::string>
of the names
of all the possible properties, as read from the properties file.
Const-correctness, both arguments & methods, is your job. For example,
it must be possible to call .get()
on a const U
,
or to pass a const string
to .readfile()
.
                
You may define other methods or data, public or private, as you see fit.                 
Here is a sample run, where %
is my shell prompt:
                
% cat main.cc #include "U.h" #include <iostream> using namespace std; const string pub="/s/bach/a/class/cs253/pub/"; // ~ only works in shells int main() { U foo(pub+"UnicodeData.txt", "a³+b³≠c³"); cout << "Should be 8: " << foo.size() << '\n' << "Should be 2: " << foo.propcount("Sm") << '\n' << "Should be b³: " << foo.get(3,5) << '\n'; return 0; } % g++ -Wall main.cc U.cc % ./a.out Should be 8: 8 Should be 2: 2 Should be b³: b³ %
main()
function.
If you do, you will lose one full point.
exit()
, or emit any output.
propfile
is called more than once
on the same object.
propfile
before, or after calling
readfile
. Don’t assume either order.
propcount
, return zero if that property is not defined,
or no characters with that property have been encountered.
For example, propcount("Gnarly düde!")
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.                 
Don’t turn in tar archives or anything like that.
Just turn in U.cc
and U.h
. You must turn in both files.
We will ignore any other files that you turn in.
                
Use web checkin, or Linux checkin:                 
~cs253/bin/checkin HW5 U.cc U.h
Turn in someone else’s work.                 
Modified: 2017-03-17T16:45                  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 |