Design a program that converts an octal number into binary numbers. Use a constructor.
#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();
}
Comments
Leave a comment