CS 202 Fall 2013 > In-Class Challenge for Tuesday, September 24, 2013 |
CS 202 Fall 2013
In-Class Challenge for Tuesday, September 24, 2013
This challenge deals with a C++ class CountMe
.
It is initially specified as follows.
What you are actually to do is found below.
Class CountMe
Initial Specification
- Class
CountMe
should be implemented in header filecountme.h
and source filecountme.cpp
. - Class
CountMe
should have aprivate
static
member variable that keeps track of how many objects of typeCountMe
currently exist.- So it needs to be modified in each constructor and in the destructor, right? It also needs to be initialized to zero.
- Class
CountMe
should have a default constructor. - You may write other public functions, but do not write any accessors.
- There should be a global function
howMany
that returns the number ofCountMe
objects that currently exist. This global function should have access to theprivate
data of classCountMe
. - As always, the class should be implemented according to standard conventions regarding header & source file separation, etc.
- The
const
qualifier should be used correctly. - Your package should compile with program
test_countme.cpp
.
What to Do
Do as many of the following as you can before class ends. After each, please show me your work.
- Write a minimal version of files
countme.h
andcountme.cpp
that compile with the test programtest_countme.cpp
. - Implement class
CountMe
as above, so that all tests pass. - Add an additional option to the class:
keep track of how many constructor calls
and how many destructor calls there have been
for class
CountMe
. Write a program that demonstrates this functionality. The resulting class should still compile with the test program and pass all tests.
CS 202 Fall 2013: In-Class Challenge for Tuesday, September 24, 2013 /
Updated: 24 Sep 2013 /
Glenn G. Chappell