| 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
CountMeshould be implemented in header filecountme.hand source filecountme.cpp. - Class
CountMeshould have aprivatestaticmember variable that keeps track of how many objects of typeCountMecurrently exist.- So it needs to be modified in each constructor and in the destructor, right? It also needs to be initialized to zero.
- Class
CountMeshould have a default constructor. - You may write other public functions, but do not write any accessors.
- There should be a global function
howManythat returns the number ofCountMeobjects that currently exist. This global function should have access to theprivatedata of classCountMe. - As always, the class should be implemented according to standard conventions regarding header & source file separation, etc.
- The
constqualifier 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.handcountme.cppthat compile with the test programtest_countme.cpp. - Implement class
CountMeas 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