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 ofnin the class’ member variable -
int getNumber( )returns the current value of theNumberclass member variable -
void printNumber( )prints the value of theintmember variable -
bool isNegative( )checks whether the value of theintmember variable is negative -
bool isDivisibleBy ( int n )checks whether theintmember 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.