Number Class with Methods defined Outside it
Learn to implement a class with member methods defined outside it.
We'll cover the following
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 ofn
in the class’ member variable -
int getNumber( )
returns the current value of theNumber
class member variable -
void printNumber( )
prints the value of theint
member variable -
bool isNegative( )
checks whether the value of theint
member variable is negative -
bool isDivisibleBy ( int n )
checks whether theint
member variable is divisible byn
-
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.