Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

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

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

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

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

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

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

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

Fazal Rehman Shamil Click Here to Know More
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325
Dear Professors and Resarchers!You are welome to Cite these tutorials in your research or slides etc. Please don't forget to mention the reference of website. Copy Paste of text is strcitly forbidden. Images can be reuse because images are protected with watermark.