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

Question #184038

Write a program make a class barabitkaar.Given two arrays A[n] & B[n] containing bit strings representing sets A & B respectively, write a code fragment to construct bit string representing the set 𝐴 − 𝐵.


1
Expert's answer
2021-04-22T10:30:36-0400
#include <iostream>

#include <string>

using namespace std;

int main() {

std::string a;

std::string b;

cout << "Enter first bit string A : ";

cin >> a; int n = a.length();

std::cout << "Enter the second bit string B of length " << n<<" ";

cin >> b;

std::string result{ "" };

int delta = 0;

char mn;

for (int i = n - 1; i >-1; i--) {

mn = a[i];

if (delta == 1 && a[i] == '1')

{

mn = '0';

delta = 0;

}

if (delta == 1 && a[i] == '0')

{

mn = '1';

delta = 1;

}

if (mn =='0' && b[i]=='0')

{

result = "0" + result;

}

if (mn == '1' && b[i] == '0')

{

result = "1" + result;

}

if (mn == '1' && b[i] == '1')

{

result = "0" + result;

}

if (mn == '0'&& b[i] == '1')

{

result = "1" + result;

delta = 1;

}

}

if (delta == 1)

{

cout << "Negative binary number in two's complement format ";

}

cout << "A-B = "<<result<<endl;

  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