CS253

CS253: Software Development with C++                

Spring 2017                

HW 7                

CS253 HW7: Operators!                

Description                

For this assignment, you will enhance U and P by adding a few operators.                 

Methods                

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:                 

Const-correctness, both arguments & methods, is your job. For example, it must be possible to concatenate two const U objects.                 

Concatenation and Appending                

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.                 

Comparison                

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.

Sample Run                

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.

Requirements                

The requirements are the same as HW6, plus:                 

Hints                

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:                

You will turn in at least four files:

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

How to receive negative points:                

Turn in someone else’s work.                 

Modified: 2017-04-16T16:01                 

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