Write a program in C++ to convert a decimal number into octal without using an array and Virtual base Class 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 35 36 37 38 39 40 41 42 |
// #include<iostream> using namespace std; class T4Tutorials_Base_Class { public : int n; }; class parent1 :public virtual T4Tutorials_Base_Class { public : int i; }; class parent2 :public virtual T4Tutorials_Base_Class { public : int j; }; class derived :public parent1 , public parent2 { protected : int oc_num; public : conv() { cout<<"Please Enter Any Number to change in to octal : “<<endl; cin>>n; i=1; for(j=n ; j>0 ; j=j/8) { oc_num+=(j%8)*i; i*=10; } cout<<"Your Entered Value is : "<<n; cout<<"\tOctal Value of your Input is : "<<oc_num; } }; int main() { derived a; a.conv(); } |
Output
Please Enter Any Number to change in to octal : 12
Your Entered Value is : 12
Octal Value of your Input is : 14
FAQ
Decimal to octal conversion.
write a program to convert the given decimal number into octal number using the for loop.
Decimal to octal conversion using OOP Classes.
Decimal to octal conversion with classes, inheritance and multiple inheritence.
Decimal to octal conversion by virtual base class.