Constructor overloading and Destructor C++ Program to convert octal to decimal number
Write the Octal to Decimal number program in C++ using constructor overloading and destructor?
Octal to Decimal number program in C++ with constructor and destructor
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 | #include<iostream> #include<math.h> using namespace std; class convert{ private: int dnumber=0,rem,T4Tutorials_Octal; public: convert() // COnstructor { int i; cout<<"Enter the Number"; cin>>T4Tutorials_Octal; for(i=0;T4Tutorials_Octal>0;i++) { rem=T4Tutorials_Octal%10; dnumber=dnumber+rem* pow(8,i); T4Tutorials_Octal=T4Tutorials_Octal/10; } cout<<"The decimal is "<<dnumber; } ~convert() // Destructor { } }; int main() { convert c1; return 0; } |
Octal to Decimal number program in C++ with constructor Overloading
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 54 55 56 57 58 59 60 61 62 63 64 65 | #include<iostream> #include<math.h> using namespace std; class convert{ private: int T4Tutorials_Decimal=0,rem; int i; public: convert(int noct) { for(i=0;noct>0;i++) { rem=noct%10; T4Tutorials_Decimal= T4Tutorials_Decimal+rem*pow(8,i); noct=noct/10; } cout<<"decimal num is"<<T4Tutorials_Decimal; } convert(long int aoct) { for(i=0;aoct>0;i++) { rem=aoct%10; T4Tutorials_Decimal=T4Tutorials_Decimal+rem*pow(8,i); aoct=aoct/10; } cout<<"decimal num is"<<T4Tutorials_Decimal; } }; int main() { int choice; cout<<"Enter Choice: "; cin>>choice; switch(choice) { case 0: { int noct; cout<<"Enter num:"; cin>>noct; convert c(noct); break; } case 1: { int long aoct; cout<<"Enter num:"; cin>>aoct; convert c(aoct); break; } default: cout<<"Invalid Input"; } } |