CS253

CS253: Software Development with C++                

Spring 2017                

HW 5                

CS253 HW5: Time to get classy!                

Description                

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.                 

Methods                

Your class must have the following public methods:                 

Default constructor
Accumulated string is initially empty. No properties so far.
Copy constructor
Takes another U, and copies the information.
Test Constructor
Takes two 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.
Assignment operator
Takes another U, and copies the information.
Destructor
Destroys.
readfile
Takes a 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
Takes a std::string properties filename. Parses that file. Throws a std::string error message upon error.
size
Returns total number of UTF-8 characters read, as an int.
get
Takes no arguments, and returns all the accumulated UTF-8 characters as one big std::string.
get
Takes an 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
Like get, but takes two ints, 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
Takes a std::string which is a property name (e.g., Lu) and returns how many times characters with that property have been encountered.
props
Takes no arguments; returns a 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.                 

Sample Run                

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³
    %

Requirements                

  1. Do not turn in a main() function. If you do, you will lose one full point.
  2. No requirements are inherited from previous assignments, except as explicitly mentioned.
  3. The very first three lines of each source file must be comments, containing, in this order, one per line:
    • your name
    • the date
    • the purpose of this program
  4. Your code must not exit(), or emit any output.
  5. If it can be opened, you may assume that the properties file is properly formatted, as described in HW4. It may be out of order, or have holes.
  6. It is not defined what happens if propfile is called more than once on the same object.
  7. It is acceptable to call propfile before, or after calling readfile. Don’t assume either order.
  8. For 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.
  9. Do not turn in a main() function. If you do, you will lose one full point.
  10. You may not assume that the input files contain valid UTF-8 encoded characters.
  11. You may assume that the Unicode characters described by the properties file are in the range U+0000–U+10FFFF.
  12. You may not use C-style <stdio.h> or <cstdio> facilities, such as scanf, fopen, and getchar.
    • Instead, use use C++ facilities such as ifstream.
  13. You may not use C-style dynamic memory via malloc, calloc, realloc, free, and the like.
    • Use new/delete/new[]/delete[], if you must do your own memory allocation.
    • Containers are easier!
  14. No global variables.
  15. You may not leak memory.
  16. Do not turn in a main() function. If you do, you will lose one full point.
  17. Do it yourself:
    • You may not use u16_string(cpp), u32_string(cpp), wstring, wcout, wchar_t, etc.
    • You may not use any of the C++ wide-character facilities.
    • You may not use an external program via popen, system, or the like.
    • You have to do any UTF-8 character decoding/encoding yourself.
  18. For readability, don’t use ASCII int constants (65) instead of char constants ('A') for printable characters.
  19. Several instances of this class must be able to co-exist, without interfering with each other.
  20. Your header file must not pollute the namespace.
  21. Strings thrown as errors must contain reasonable error messages, describing the error. "Something went wrong" is not good enough.
  22. We will compile your program as shown above.
    • If that generates warnings, you will lose a point.
    • If that generates errors, you will lose all points.
  23. Do not turn in a main() function. If you do, you will lose one full point.

Ask                

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.                 

How to submit your homework:                

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

How to receive negative points:                

Turn in someone else’s work.                 

Modified: 2017-03-17T16:45                 

User: Guest                 

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building