CS 202 Fall 2013  >  In-Class Challenge for Thursday, October 17, 2013

CS 202 Fall 2013
In-Class Challenge for Thursday, October 17, 2013

Class Func

You are given an abstract base class Func, defined in files func.h and func.cpp. This class has a virtual member function f, which in const, takes an int and returns an int. It should be overridden in each derived class.

What to Do

Do as many of the following as you can before class ends. Along the way, maintain a program that demonstrates whatever functionality you have written. To allow for faster writing, put all the code you write into a single file.

  1. Using as little code as possible, write:
    • At least two derived classes of Func, each with a different f member.
    • A main program that creates a vector of shared_ptr<Func>, places pointers to at least three derived class objects in the vector, then iterates through the vector, calling the f member with some integer parameter.

Note: Your compiler should have shared_ptr. If it does not, then you can use plain pointers (Func *). But I suggest you get a new compiler.


CS 202 Fall 2013: In-Class Challenge for Thursday, October 17, 2013 / Updated: 17 Oct 2013 / Glenn G. Chappell