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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#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.