Write a program class name BaraBitKaar
BaraBitKaar Add(BaraBitKaar b);
When this function called in main() like following example:
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(); //
#include<iostream> #include<stdlib.h>
using namespace std;
class BaraBitkaar{
int a[100]; int b[100]; int c[100];
public:
void geta(int p,int q)
{ if(q! =0)
{
if(q!=1) {
cout<<"wrong digit";
exit(0); } } a[x]=y; }
void getb(int u,int v)
{
if(v!=0)
{
if(v!=1)
{
cout<<"n Wrong digit";
exit(1);
}
}
b[u]=v;
}
void add()
{ int i;
c[0]=0;
for(i=3;i>-1;i--) c[i+1]=a[i]+b[i];
for(i=4;i>-1;i--) { if(c[i]==2)
{ c[i-1]=c[i-1]+1; c[i]=0; }
else if(c[i]==3)
{ c[i-1]=c[i-1]+1; c[i]=1; } }
cout<<"n The result is : "<<endl;
for(i=0;i<5;i++)
cout<<c[i];
}
};
int main()
{ BaraBitkaar p;
int i,j,k;
cout<<"n Enter the elements of p number ";
for(i=0;i<4;i++)
{
cin>>k;
p.geta(i,k);
}
cout<<"n Enter the elements of q number ";
for(i=0;i<4;i++)
{
cin>>k;
p.getb(i,k);
}
p.add();
}
Comments
Leave a comment