HexaDecimal to Binary Classes Constructor Destructor and Inheritance in OOP – C++
HexaDecimal to Binary Classes Constructor Destructor and Inheritance in OOP – C++
In this tutorial, we will code the program of conversion of HexaDecimal to BinaryProgram with Classes and Objects in OOP (C++)
HexaDecimal to Binary Program with Classes and Objects in OOP (C++)
Here, below there is a code of HexaDecimal to Binary Program with Classes and Objects in OOP (C++).
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 66 67 68 69 70 71 72 73 74 75 |
#include<iostream> using namespace std; class Hexa2Binary { public: int HEXA2BINARYFUNCTION() { long int i=0; char binnum[100], hexdec[100]; cout<<"Enter any hexadecimal number : "; cin>>hexdec; cout<<"\nEquivalent Binary value is : "; while(hexdec[i]) { switch(hexdec[i]) { case '0' : cout<<"0000"<<endl<<endl<<endl; break; case '1' : cout<<"0001"<<endl<<endl<<endl; break; case '2' : cout<<"0010"<<endl<<endl<<endl; break; case '3' : cout<<"0011"<<endl<<endl<<endl; break; case '4' : cout<<"0100"<<endl<<endl<<endl; break; case '5' : cout<<"0101"<<endl<<endl<<endl; break; case '6' : cout<<"0110"<<endl<<endl<<endl; break; case '7' : cout<<"0111"<<endl<<endl<<endl; break; case '8' : cout<<"1000"<<endl<<endl<<endl; break; case '9' : cout<<"1001"<<endl<<endl<<endl; break; case 'A' : cout<<"1010"<<endl<<endl<<endl; break; case 'B' : cout<<"1011"<<endl<<endl<<endl; break; case 'C' : cout<<"1100"<<endl<<endl<<endl; break; case 'D' : cout<<"1101"<<endl<<endl<<endl; break; case 'E' : cout<<"1110"<<endl<<endl<<endl; break; case 'F' : cout<<"1111"<<endl<<endl<<endl; break; case 'a' : cout<<"1010"<<endl<<endl<<endl; break; case 'b' : cout<<"1011"<<endl<<endl<<endl; break; case 'c' : cout<<"1100"<<endl<<endl<<endl; break; case 'd' : cout<<"1101"<<endl<<endl<<endl; break; case 'e' : cout<<"1110"<<endl<<endl<<endl; break; case 'f' : cout<<"1111"<<endl<<endl<<endl; break; default : cout<<"\nInvalid hexadecimal digit ="<<hexdec[i]<<endl<<endl; } i++; } } }; int main() { Hexa2Binary HexaToBinary; HexaToBinary.HEXA2BINARYFUNCTION(); } |
Output
HexaDecimal to Binary Program By Using Constructor in OOP (C++)
Here, below there is a code of HexaDecimal to Binary Program by using the constructor in OOP (C++).
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 66 67 68 69 70 71 72 73 74 75 76 |
#include<iostream> using namespace std; class H2BConversion { public: H2BConversion() { long int i=0; char BinaryNumber[100], HexaDecimal[100]; cout<<"Enter any hexadecimal number : "; cin>>HexaDecimal; cout<<"\nEquivalent Binary value is : "; while(HexaDecimal[i]) { switch(HexaDecimal[i]) { case '0' : cout<<"0000"<<endl<<endl<<endl; break; case '1' : cout<<"0001"<<endl<<endl<<endl; break; case '2' : cout<<"0010"<<endl<<endl<<endl; break; case '3' : cout<<"0011"<<endl<<endl<<endl; break; case '4' : cout<<"0100"<<endl<<endl<<endl; break; case '5' : cout<<"0101"<<endl<<endl<<endl; break; case '6' : cout<<"0110"<<endl<<endl<<endl; break; case '7' : cout<<"0111"<<endl<<endl<<endl; break; case '8' : cout<<"1000"<<endl<<endl<<endl; break; case '9' : cout<<"1001"<<endl<<endl<<endl; break; case 'A' : cout<<"1010"<<endl<<endl<<endl; break; case 'B' : cout<<"1011"<<endl<<endl<<endl; break; case 'C' : cout<<"1100"<<endl<<endl<<endl; break; case 'D' : cout<<"1101"<<endl<<endl<<endl; break; case 'E' : cout<<"1110"<<endl<<endl<<endl; break; case 'F' : cout<<"1111"<<endl<<endl<<endl; break; case 'a' : cout<<"1010"<<endl<<endl<<endl; break; case 'b' : cout<<"1011"<<endl<<endl<<endl; break; case 'c' : cout<<"1100"<<endl<<endl<<endl; break; case 'd' : cout<<"1101"<<endl<<endl<<endl; break; case 'e' : cout<<"1110"<<endl<<endl<<endl; break; case 'f' : cout<<"1111"<<endl<<endl<<endl; break; default : cout<<"\nInvalid hexadecimal digit ="<<HexaDecimal[i]<<endl<<endl; } i++; } } }; int main() { H2BConversion A; } |
Output
HexaDecimal to Binary Program By Using destructor in OOP (C++)
Here, below there is a code of HexaDecimal to Binary Program by using the destructor in OOP (C++).
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
#include<iostream> using namespace std; class HD2BConversion { public: HD2BConversion() { long int i=0; char binnum[100], hexdec[100]; cout<<"Please Enter the desired any hexadecimal number : "; cin>>hexdec; cout<<"\nEquivalent Binary value is : "; while(hexdec[i]) { switch(hexdec[i]) { case '0' : cout<<"0000"<<endl<<endl<<endl; break; case '1' : cout<<"0001"<<endl<<endl<<endl; break; case '2' : cout<<"0010"<<endl<<endl<<endl; break; case '3' : cout<<"0011"<<endl<<endl<<endl; break; case '4' : cout<<"0100"<<endl<<endl<<endl; break; case '5' : cout<<"0101"<<endl<<endl<<endl; break; case '6' : cout<<"0110"<<endl<<endl<<endl; break; case '7' : cout<<"0111"<<endl<<endl<<endl; break; case '8' : cout<<"1000"<<endl<<endl<<endl; break; case '9' : cout<<"1001"<<endl<<endl<<endl; break; case
'A' : cout<<"1010"<<endl<<endl<<endl; break; case 'B' : cout<<"1011"<<endl<<endl<<endl; break; case 'C' : cout<<"1100"<<endl<<endl<<endl; break; case 'D' : cout<<"1101"<<endl<<endl<<endl; break; case 'E' : cout<<"1110"<<endl<<endl<<endl; break; case 'F' : cout<<"1111"<<endl<<endl<<endl; break; case 'a' : cout<<"1010"<<endl<<endl<<endl; break; case 'b' : cout<<"1011"<<endl<<endl<<endl; break; case 'c' : cout<<"1100"<<endl<<endl<<endl; break; case 'd' : cout<<"1101"<<endl<<endl<<endl; break; case 'e' : cout<<"1110"<<endl<<endl<<endl; break; case 'f' : cout<<"1111"<<endl<<endl<<endl; break; default : cout<<"\nInvalid hexadecimal digit ="<<hexdec[i]<<endl<<endl; } i++; } } ~HD2BConversion() { long int i=0; char binnum[100], hexdec[100]; cout<<"Please Enter the desired any hexadecimal number : "; cin>>hexdec; cout<<"\nEquivalent Binary value is : "; while(hexdec[i]) { switch(hexdec[i]) { case '0' : cout<<"0000"<<endl<<endl<<endl; break; case '1' : cout<<"0001"<<endl<<endl<<endl; break; case '2' : cout<<"0010"<<endl<<endl<<endl; break; case '3' : cout<<"0011"<<endl<<endl<<endl; break; case '4' : cout<<"0100"<<endl<<endl<<endl; break; case '5' : cout<<"0101"<<endl<<endl<<endl; break; case '6' : cout<<"0110"<<endl<<endl<<endl; break; case '7' : cout<<"0111"<<endl<<endl<<endl; break; case '8' : cout<<"1000"<<endl<<endl<<endl; break; case '9' : cout<<"1001"<<endl<<endl<<endl; break; case 'A' : cout<<"1010"<<endl<<endl<<endl; break; case 'B' : cout<<"1011"<<endl<<endl<<endl; break; case 'C' : cout<<"1100"<<endl<<endl<<endl; break; case 'D' : cout<<"1101"<<endl<<endl<<endl; break; case 'E' : cout<<"1110"<<endl<<endl<<endl; break; case 'F' : cout<<"1111"<<endl<<endl<<endl; break; case 'a' : cout<<"1010"<<endl<<endl<<endl; break; case 'b' : cout<<"1011"<<endl<<endl<<endl; break; case 'c' : cout<<"1100"<<endl<<endl<<endl; break; case 'd' : cout<<"1101"<<endl<<endl<<endl; break; case 'e' : cout<<"1110"<<endl<<endl<<endl; break; case 'f' : cout<<"1111"<<endl<<endl<<endl; break; default : cout<<"\nInvalid hexadecimal digit ="<<hexdec[i]<<endl<<endl; } i++; } } }; int main() { HD2BConversion A; } |
Output
HexaDecimal to Binary Program By Using classed inheritance in OOP (C++)
Here, below there is a code of HexaDecimal to Binary Program by using the classes inheritance in OOP (C++).
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
#include<iostream> using namespace std; class Covnersion { protected: long int i=0; char BinaryNumebr[100], HexaDecimal[100]; }; class hexadecimal : public Covnersion { public: int HTB() { long int i=0; char BinaryNumebr[100], HexaDecimal[100]; cout<<"Please Enter any hexadecimal number : "; cin>>HexaDecimal; cout<<"\nEquivalent Binary value is : "; while(HexaDecimal[i]) { switch(HexaDecimal[i]) { case '0' : cout<<"0000"<<endl<<endl<<endl; break; case '1' : cout<<"0001"<<endl<<endl<<endl; break; case '2' : cout<<"0010"<<endl<<endl<<endl; break; case '3' : cout<<"0011"<<endl<<endl<<endl; break; case '4' : cout<<"0100"<<endl<<endl<<endl; break; case '5' : cout<<"0101"<<endl<<endl<<endl; break; case '6' : cout<<"0110"<<endl<<endl<<endl; break; case '7' : cout<<"0111"<<endl<<endl<<endl; break; case '8' : cout<<"1000"<<endl<<endl<<endl; break; case '9' : cout<<"1001"<<endl<<endl<<endl; break; case 'A' : cout<<"1010"<<endl<<endl<<endl; break; case 'B' : cout<<"1011"<<endl<<endl<<endl; break; case 'C' : cout<<"1100"<<endl<<endl<<endl; break; case 'D' : cout<<"1101"<<endl<<endl<<endl; break; case 'E' : cout<<"1110"<<endl<<endl<<endl; break; case 'F' : cout<<"1111"<<endl<<endl<<endl; break; case 'a' : cout<<"1010"<<endl<<endl<<endl; break; case 'b' : cout<<"1011"<<endl<<endl<<endl; break; case 'c' : cout<<"1100"<<endl<<endl<<endl; break; case 'd' : cout<<"1101"<<endl<<endl<<endl; break; case 'e' : cout<<"1110"<<endl<<endl<<endl; break; case 'f' : cout<<"1111"<<endl<<endl<<endl; break; default : cout<<"\nInvalid hexadecimal digit ="<<HexaDecimal[i]<<endl<<endl; } i++; } } }; int main() { hexadecimal HexaToBinary; HexaToBinary.HTB(); } |
Output