Answer to Question #331735 in C++ for Amy

Question #331735

Design a program that converts an octal number into binary numbers. Use a constructor.

1
Expert's answer
2022-04-21T07:02:56-0400
#include <iostream>
#include <cmath>

using namespace std;

class ConversionToBin
{
	int bin;
public:
	ConversionToBin(int octal):bin(0)
	{
		int dNum = 0, count = 0;
		while (octal != 0)
		{
			dNum += (octal % 10)*pow(8, count);
			++count;
			octal /= 10;
		}
		count = 1;
		while (dNum != 0)
		{
			bin += (dNum % 2)*count;
			dNum /= 2;
			count *= 10;
		}
	}
	void Display()
	{
		cout <<"Converted bunary is "<< bin;
	}
};

int main()
{
	ConversionToBin a(55);
	a.Display();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS