Write a program in C++ to check Armstrong number of n digits 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 52 53 |
#include<iostream> #include<math.h> #include<conio.h> using namespace std; class A { public: int num; }; class B : public virtual A { public: int result; }; class C : public virtual A { public: int r; }; class D: public B, public C { public: void T4Tutorials_Get_Number() { int n,n1,a,b; n1=a; n=b; cout<<"check the num of Armstrong or not : "; cin>>n; num=n1; while(num !=0) { num/=10; n++; } num=n1; while (num !=0) { r=num%10; result+=pow(r,n); num /=10; } if(result == n1) cout<<"Armstrong Number : "; else cout<<"Not Armstrong Number : "; } }; int main() { D obj; obj.T4Tutorials_Get_Number(); } |