Number Class with Methods defined Outside it

Learn to implement a class with member methods defined outside it.

Challenge

Write a Number class that maintains an int. It should have the following member functions defined outside this class to perform various operations on the int:

  • void setNumber ( int n ) stores the value of n in the class’ member variable

  • int getNumber( ) returns the current value of the Number class member variable

  • void printNumber( ) prints the value of the int member variable

  • bool isNegative( ) checks whether the value of the int member variable is negative

  • bool isDivisibleBy ( int n ) checks whether the int member variable is divisible by n

  • int absoluteValue( ) returns the absolute value of the member variable

Coding exercise

Your job is to define the methods outside the Number class given below.

Get hands-on with 1400+ tech skills courses.