CS253

CS253: Software Development with C++                

Spring 2017                

HW 8                

CS253 HW8: Container!                

Description                

For this assignment, you will make the U class a (somewhat) STL-compatible container, by adding several methods and a type.                 

Methods                

Your U class must have the same methods as described in HW7, and:                 

U methods & type:                

U::iterator methods:                

No error-checking is required for iterator methods.                 

Const-correctness, both arguments & methods, is your job. For example, it must be possible to call .begin() on a const U.                 

Sample Run                

Here is a sample run, where % is my shell prompt:                 

    % cat main.cc
    #include "U.h"
    #include <iostream>
    #include <cassert>

    using std::cout;
    using std::hex;
    using std::showbase;

    int main() {
        const char s[] = "\U0001f382 × 11 \u21d2 9\u00be";

        U u(s, s+sizeof(s)-1);
        assert(u == "\U0001f382 × 11 \u21d2 9\u00be");
        cout << u << '\n';			// 🎂 × 11 ⇒ 9¾

        assert(u.front() == 0x1f382);		// birthday cake
        assert(u.back() == 0xbe);		// three-quarters
        U::iterator it = u.begin();
        assert(*it == 0x1f382);			// birthday cake
        it++;
        assert(*it == ' ');
        it = u.end();
        --it;
        assert(*it == 0xbe);			// ¾

        for (auto cp : u)
            cout << hex << showbase << cp << ' ';
        cout << '\n';
    }
    % g++ -Wall main.cc U.cc
    % ./a.out
    🎂 × 11 ⇒ 9¾
    0x1f382 0x20 0xd7 0x20 0x31 0x31 0x20 0x21d2 0x20 0x39 0xbe 

Requirements                

The requirements are the same as HW7, plus the methods and types shown above.                 

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 two files:

That’s a lot of files, so construct a tar file, like this:

    tar -cvf hw8.tar U.cc U.h other-files

and turn it in.                 

Use web checkin, or Linux checkin:                 

    ~cs253/bin/checkin HW8 hw8.tar

How to receive negative points:                

Turn in someone else’s work.                 

Modified: 2017-04-27T15:34                 

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