Site icon T4Tutorials.com

C++ program for factorial using Multiple inheritance

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

C++ program for factorial using Multiple inheritance

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

};
//child class
class fact_function_factorial: public 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

More Practice on Factorial problem in C++

  1. Factorial Program in C++
  2. factorial using single inheritance
  3. Factorial Program in C++ using Class Objects
  4. factorial using Multiple inheritances
  5. C++ program for factorial using Constructor DestructorFactorial Of A Number By Using The Recursion
  6. Factorial Program with structures and pointers C++
  7. Factorial Program with Nested Structure C++
  8. factorial of a no. by defining the member functions outside the class