Write a program in C++ to convert a decimal number into an octal without using an array using Single inheritance in object oriented programming(OOP) .
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 |
/* Single inheritance C++ Program to convert a decimal number into an octal */ #include<iostream> using namespace std; class T4Tutorials { protected : int i,j,dn; }; class T4Tutorials2 : public T4Tutorials { private : int temp,oc_num; public : int conversion() { cout<<"Enter the octal Number : "; cin>>dn; temp=dn; i=1; for(j=dn ; j>0 ; j=j/8) { oc_num=oc_num+(j%8)*i; i=i*10; } cout<<"Your Entered Value is : "<<temp; cout<<"\tOctal Value of your Input is : "<<oc_num; } }; int main() { T4Tutorials2 a; a.conversion(); } |
Output
Enter the octal Number : 10
Your Entered Value is : 10
Octal Value of your Input is : 12