Site icon T4Tutorials.com

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++).

#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

Figure: HexaDecimal to Binary Program with Classes and Objects in OOP (C++)

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++).

#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

Figure: HexaDecimal to Binary Program with Classes and Objects in OOP (C++)

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++).

#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

Figure: HexaDecimal to Binary Program with Classes and Objects in OOP (C++)

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++).

#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

Figure: HexaDecimal to Binary Program with Classes and Objects in OOP (
C
++)
Exit mobile version