Answer to Question #183335 in C++ for zain ul abdeen

Question #183335
Make a class in BaraBitKaar. Input two binary number. Sabtract two binary number.
BaraBitKaar Sabtract( BaraBitKaar b);
When this function called in main() like following example:
BaraBitKaar p( "01111111111100000000000001111111101010100101111111111111111111111111111111111111111111111111111111111011111101110101111101011011");
BaraBitKaar q( "00111111111100000000000001111111101010100101111111111111111111111111111111111111111111111111111111111011111101110101111101011011");
BaraBitKaar r;
r = p.sabtract(q); //this is how sabtract is supposed to be used to sabtract p and q. Notice r receives the return which is of type BaraBitKaar.
r.PrintBinary();
1
Expert's answer
2021-04-20T16:21:12-0400
#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;
}
};

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);

return 0;
 }

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