(C++ Only) Class practice 2


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C++, Python3

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:

  1. The constructor should initialise the value of that object's count value to val.

  2. reset should set the value of that object's count value to val.

  3. doCount check if count's value is 0. If it is, output in a single line Counting ends! Bling bling bling!. If it is not, output Counting:, then the value of count, make the value of count 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

There are no comments at the moment.