Factorial Program in C++ using Classes

Lets start C++ Programming with a simple Factorial program using Classes. Classes are nothing but a structure in ‘C’ Language which supports functions. We can write this program very simply within the main function but our main aim is to get started to use Classes and Objects.

In the program below, We are using defining a class with name Factorial. Then we have declared f and n variables as int data type, We then define fact and display functions under the access specifier Public (That means these functions/variables can be used anywhere throughout the program). fact() function communicates with the class with the help of ‘::‘ -> scope resolution operator. We have defined objects in the main function, Objects can be referred as variables of a Structure.