Site icon T4Tutorials.com

Virtual base class C++ Program TO find perfect numbers within range

Write a C++ program to find the perfect numbers within a given number of range by using the virtual base class in Object Oriented Programming.

#include<iostream>
using namespace std;
class A
{
	protected:
 	int num,T4Tutorials_SUM;
    
};
class B:public virtual A
{
  protected:
 	int st,end;
 	B()
 	{
 		st=10;
 		end=50;
	}	
	 
};
class C:public virtual A
{
 public:
 	int i;
};
class D:public B, public C
{
    public:
	 void show()
    {
	 	for(num=st;num<=end;num++)
	{
		i=1;
		T4Tutorials_SUM=0;
		while(i<num)
		{
			if(num%i==0)
			T4Tutorials_SUM=T4Tutorials_SUM+i;
			i++;
		}
		if(T4Tutorials_SUM==num)
		cout<<"The perfect number within the given range are given below."<<endl<<num<<endl;
    }	
    } 
};	
int main()
{
	D object_t4tutorials;
//	obj.in();
	object_t4tutorials.show();
	
}

Output

The perfect number within the given range are given below.

28

FAQ

c++ program to find perfect numbers in a given range by using the virtual base class in OOP.
Develope a c++ program for perfect numbers by using the virtual base class in OOP.
write a program in c++ to find the perfect numbers between 1 and 100 by using the virtual base class in OOP.
Develope a program in c++ to find the perfect numbers between 1 and 10 by using the virtual base class in OOP.
print the perfect numbers in a given range in c++ by using the virtual base class in OOP.
Perfect number in c++ by using the virtual base class in OOP.
c++ program to find perfect number using function by using the virtual base class in OOP.

Exit mobile version