Write a program in C++ to convert a Octal number to a Decimal number 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 |
#include<iostream> #include<math.h> using namespace std; class a { protected: int rem,T4Tutorials_Octal,count; }; class b:virtual public a { protected: int T4Tutorials_Octal; }; class c:public b { public: int input() { cout<<"Please Enter an octal number:"; cin>>T4Tutorials_Octal; } int show() { int decimalnumber=0; for(count=0;T4Tutorials_Octal>0;count++) { rem = T4Tutorials_Octal%10; decimalnumber = decimalnumber+ rem*pow(8,count); T4Tutorials_Octal=T4Tutorials_Octal/10; } cout<<"decimal equivalent is"<<decimalnumber; } }; int main() { c obj; obj.input(); obj.show(); } |
Output
Please Enter an octal number: 9
decimal equivalent is 9
Latest posts by Prof. Fazal Rehman Shamil (see all)
- Why do we need various number systems in computer science? - April 16, 2021
- 5 Best Places to Study Engineering - March 19, 2021
- How Students Can Pick a Good Custom-Paper Writing Service? - March 5, 2021