Site icon T4Tutorials.com

Octal to Binary Conversion Program with Classes and Objects in OOP – C++

Octal to Binary Conversion Program with Classes and Objects in OOP – C++

In this tutorial, we will try to code the program of Octal to Binary Conversion with Classes and Objects in OOP – C++

Program to Convert Octal to Binary with Classes and Objects in OOP – C++

Here, we have demonstrated the Program to Convert the Octal value into the Binary values with Classes and Objects.

#include<iostream>
using namespace std;
class Octal2BinaryCoversion
{
	
	public:
		
		int OCTAL2BINARY()
		{
		
		long int i=0;
		char octnum[1000];
		cout<<"Enter Any Octal Number = ";
		cin>>octnum;
		cout<<endl;
		cout<<"Equilent binary value = ";
		
		while(octnum[i])
		{
			switch(octnum[i])
			{
			case'0':cout<<"000";
			break;
				case'1':cout<<"001";
			break;
				case'2':cout<<"010";
			break;	
			    case'3':cout<<"011";
			break;
				case'4':cout<<"100";
			break;
				case'5':cout<<"101";
			break;
				case'6':cout<<"110";
			break;
				case'7':cout<<"111";
			break;
				default : cout<<"~ninvalid octal number"<<octnum[i];
			
			break;
		}
		i++;
		cout<<endl<<endl<<endl;
	}
}
};

int main()
{
	Octal2BinaryCoversion OctalToBinary;
	OctalToBinary.OCTAL2BINARY();
}

Output

Figure:
Octal to Binary Conversion Program with Classes and Objects in OOP – C++

Program to Convert Octal to Binary Using Constructor in OOP – C++

Here, we have demonstrated the Program to Convert the Octal value into the Binary values using the constructor.

#include<iostream>
using namespace std;
class Conversion
{
	
	public:
		
		 Conversion()
		{
		
		long int i=0;
		char octnum[1000];
		cout<<"Enter Any Octal Number = ";
		cin>>octnum;
		cout<<endl;
		cout<<"Equilent binary value = ";
		
		while(octnum[i])
		{
			switch(octnum[i])
			{
			case'0':cout<<"000";
			break;
				case'1':cout<<"001";
			break;
				case'2':cout<<"010";
			break;	
			    case'3':cout<<"011";
			break;
				case'4':cout<<"100";
			break;
				case'5':cout<<"101";
			break;
				case'6':cout<<"110";
			break;
				case'7':cout<<"111";
			break;
				default : cout<<"~ninvalid octal number"<<octnum[i];
			
			break;
		}
		i++;
		cout<<endl<<endl<<endl;
	}
}
};

int main()
{
	Conversion A;
	
}

Output

Figure: Octal to Binary Conversion Program with Classes and Objects in OOP – C++

Program to Convert Octal to Binary Using Destructor in OOP – C++

Here, we have demonstrated the Program to Convert the Octal value into the Binary values using the destructor.

#include<iostream>
using namespace std;
class Conversion
{
	
	public:
		
		 Conversion()
		{
		
		long int i=0;
		char octnum[1000];
		cout<<"Enter Any Octal Number = ";
		cin>>octnum;
		cout<<endl;
		cout<<"Equilent binary value = ";
		
		while(octnum[i])
		{
			switch(octnum[i])
			{
			case'0':cout<<"000";
			break;
				case'1':cout<<"001";
			break;
				case'2':cout<<"010";
			break;	
			    case'3':cout<<"011";
			break;
				case'4':cout<<"100";
			break;
				case'5':cout<<"101";
			break;
				case'6':cout<<"110";
			break;
				case'7':cout<<"111";
			break;
				default : cout<<"~ninvalid octal number"<<octnum[i];
			
			break;
		}
		i++;
		cout<<endl<<endl<<endl;
	}
}
~Conversion()
		{
		
		long int i=0;
		char octnum[1000];
		cout<<"Enter Any Octal Number = ";
		cin>>octnum;
		cout<<endl;
		cout<<"Equilent binary value = ";
		
		while(octnum[i])
		{
			switch(octnum[i])
			{
			case'0':cout<<"000";
			break;
				case'1':cout<<"001";
			break;
				case'2':cout<<"010";
			break;	
			    case'3':cout<<"011";
			break;
				case'4':cout<<"100";
			break;
				case'5':cout<<"101";
			break;
				case'6':cout<<"110";
			break;
				case'7':cout<<"111";
			break;
				default : cout<<"~ninvalid octal number"<<octnum[i];
			
			break;
		}
		i++;
		cout<<endl<<endl<<endl;
	}
}
};

int main()
{
	Conversion A;
	
}

Output

Figure: Octal to Binary Conversion Program with Classes and Objects in OOP – C
+
+
Exit mobile version