Make a class BaraBitkaar Add, subtract,multiply and divide a four function in your BaraBitKaar class as follows .
BaraBitKaar Subtract(BaraBitKaar b); Add(BaraBitKaar b);
When this function called in main() like following example: 16byte binary number.
BaraBitKaar p( "01111111111100000000000001111111101010100101111111111111111111111111111111111111111111111111111111111011111101110101111101011011");
BaraBitKaar q( "00111111111100000000000001111111101010100101111111111111111111111111111111111111111111111111111111111011111101110101111101011011");
BaraBitKaar r;
r = p.Add(q); //this is how Add is supposed to be used to add p and q. Notice r receives the return which is of type BaraBitKaar.
r.PrintBinary(); //
should be able to add numbers p and q and put the result in r.
#include <iostream>
#include<math.h>
using namespace std;
class A8
{
public:
int num=679854635;
};
class decimal:public virtual A8
{
public:
int decimal;
void assign_num()
{
decimal=num*1.00;
}
void display1()
{
cout<<"\nDecimal:"<<decimal;
}
};
class hexadeciaml:public virtual A8
{
public:
char hexaDeciNum[100];
int i = 0;
int n=num;
void assign_num2()
{
while(n!=0)
{
int temp = 0;
temp = n % 16;
if(temp < 10)
{
hexaDeciNum[i] = temp + 48;
i++;
}
else
{
hexaDeciNum[i] = temp + 55;
i++;
}
n = n/16;
}
}
void display2()
{
cout<<"\n Hexa:";
for(int j=i-1; j>=0; j--)
cout << hexaDeciNum[j];
}
};
class binary:public virtual A8
{
public:
char binary[100];
int i = 0;
int n=num;
void assign_num3()
{
while(n!=0)
{
int temp = 0;
temp = n % 2;
if(temp < 10)
{
binary[i] = temp + 48;
i++;
}
n = n/2;
}
}
void display3()
{
cout<<"\n binary:";
for(int j=i-1; j>=0; j--)
cout << binary[j];
}
};
class data:public decimal,public hexadeciaml,public binary
{
public:
void assign()
{//decimal
assign_num();
display1();
//hexadeciaml
assign_num2();
display2();
//binary
assign_num3();
display3();
}
};
int main() {
std::cout << "Conversion\n";
data a;
a.assign();
}
Comments
Leave a comment