Building on previous assignment, make new functions Multiply and Divide in class BaraBitkaar i.e.
BaraBitKaar Multiply(BaraBitKaar b);
void Divide(BaraBitKaar b, BaraBitKaar & quotient, BaraBitKaar & remainder); //Notice that quotient and remainder are returned through parameters (pass by reference).
#include<iostream>
using namespace std;
class BaraBitKaar{
public:
BaraBitKaar(){
}
void sub(int a, int b){
int sub=0;
sub=a-b;
cout<<" sum of the given binary number be:"<<sub<<endl;
}
void mul(int a, int b){
int mul;
mul=a*b;
cout<<"multiplication of the given binary number be:"<<mul<<endl;
}
void div(int a, int b){
int div=0;
div=a/b;
cout<<"the division of the given binary number be:"<<div<<endl;
}
};
int main(){
BaraBitKaar bar;
char c,d;
//first input
cout<<"please enter input 1"<<endl;
uint32_t a = 0;
while ((c=getchar()) != '\n') {
a <<= 1;
a += (c - '0') & 1;
}
printf("%u\n", a);
//second input
cout<<"please enter input 2"<<endl;
uint32_t e = 0;
while ((d=getchar()) != '\n') {
e <<= 1;
e += (d - '0') & 1;
}
printf("%u\n", e);
bar.sub(a,e);
bar.div(a,e);
bar.mul(a,e);
return 0;
}
Comments
Leave a comment