Number Class with Methods defined Inside it
Learn to implement a class with member methods defined inside it.
We'll cover the following...
We'll cover the following...
Challenge
Write a self-sufficient class called Number that maintains an int member variable. It should have the following methods inside it 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 ofNumberclass member variable -
void printNumber( )prints the value ofintmember variable -
bool isNegative( )checks whether the value ofintmember variable is negative -
bool isDivisibleBy ( int n )checks whether theintmember variable is divisible byn -
int absoluteValue( )returns the absolute value of member variable
Coding exercise
Your job is to define the methods inside the Number class given below.