Number Class Definition with Separate Files

Learn to create a class with separate headers and cpp files.

Challenge

Rewrite the Number class from “Number Class with Methods defined Inside it” and “Number Class with Methods defined Outside it” with class declaration in the Number.h file. The class definition is in the Number.cpp file. Use the class from the main.cpp file.

Sample run

If you correctly implement the code in header and cpp files, and don’t change the code in main.cpp, then you should expect to see the following console output after running your coding exercise:

1234
5 does not divide 1234
Absolute value of 1234 is 1234

Coding exercise

Your job is to write method definitions in the cpp class. The code for main ( ) is already given.

Get hands-on with 1400+ tech skills courses.