C++ program for factorial using Multi-level inheritance

Let us see the C++ program for finding the factorial of a number using the Multi-level inheritance.

C++ program for factorial using Multi-level inheritance

#include<iostream>
using namespace std;
//main class
class factorial
{
	public:
	unsigned long long fact=1;
	void display();	
};
//child of main class
class input_factorial: public factorial
{
	public:
	int num;
	int input();

};
//child of another child class
class fact_function_factorial: public input_factorial
{
	public:
		void fact_function();
};
int input_factorial::input()
{
	cout<<"Please enter a number: ";
	cin>>num;
}

void fact_function_factorial::fact_function()
{
	for(int i=1;i<=num;i++)
{
fact=fact*i;
}
}

void factorial::display()
{
	cout<<"Factorial of entered number is: "<<fact;
}

int main()
{
	fact_function_factorial object;
	
	object.input();
	object.fact_function();
	object.display();
}

Output

C++ program for factorial using Multi-level inheritance

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.