(C++ Only) Class practice 2
This practice problem will require you to implement member functions of a class.
This question is similar to demo3
of handout H804.
Given class declaration for CountDown
, you are required to implement it's
member functions.
In addition, you will also need to write your own main.cpp
to test your
implementation.
The header to be used must be called p023.h
with the following content:
#ifndef _P023
#define _P023
class CountDown {
int count;
public:
CountDown(int val);
void reset(int val);
void doCount();
};
#endif
Here, ifndef
is a conditional preprocessor macro to ensure the same header
does not get included twice, which will cause compiler errors saying duplicated
class declaration.
The three member functions should do the following things:
The constructor should initialise the value of that object's
count
value toval
.reset
should set the value of that object'scount
value toval
.doCount
check ifcount
's value is 0. If it is, output in a single lineCounting ends! Bling bling bling!
. If it is not, outputCounting:
, then the value ofcount
, make the value ofcount
one less (-1).
Input Specification
No input specification. OJ will automatically judge your implementation of
p023.cpp
.
Output Specification
No output specification. OJ will automatically judge your implementation of
p023.cpp
.
Comments