Question: Please help fix the code (maybe line 92 and 93), please show your output. Thank you #include #include using namespace std; struct minterms {//for storing

Please help fix the code (maybe line 92 and 93), please show your output. Thank you

#include #include

using namespace std;

struct minterms {//for storing the minterms char x = '0'; char y = '0'; char z = '0'; };

int convertToBinary(int decimal) { int binary = 0; if (decimal > 8 && decimal < 0) { cout << "ERROR!!!!!!!!!"; return EXIT_FAILURE; }

while (decimal) { binary = (binary * 10) + (decimal & 1); decimal = decimal >> 1; } return binary; } minterms convertToSOP(int decimal) { int binary = convertToBinary(decimal); minterms send; send.z = (binary % 10 == 1) ? '1' : '0'; send.y = (binary % 100 >= 10) ? '1' : '0'; send.z = (binary % 1000 >= 100) ? '1' : '0';

return send; } //printing SOP void printSOP(minterms sop) { if (sop.x == '1') cout << 'x'; else if (sop.x == '0') cout << "x\'";

if (sop.y == '1') cout << 'y'; else if (sop.y == '0') cout << "y\'";

if (sop.z == '1') cout << 'z'; else if (sop.z == '0') cout << "z\'";

}

int main(int argc, char* argv[]) { //cout<<" A"; int numOfMint = argc - 1; int i; char* sopv = new char[numOfMint]; minterms* sop = new minterms[numOfMint];

for (i = 1; i < argc; i++) { sopv[i - 1] = *argv[i]; //cout<<" B"; }

for (i = 0; i < numOfMint; i++) { sop[i] = convertToSOP((int)(sopv[i]) - 48); //cout<<" C"; }

//printing SOP cout << " SOP = "; for (i = 0; i < numOfMint; i++) { //cout<<" D "; printSOP(sop[i]); if (i != numOfMint - 1) cout << " + "; }

//simplifying int countMatch = 0; int status[numOfMint]; //if status[i] = 1 then print else not. minterms simpSOP[numOfMint];//storing the simplified version.

//if the two of the variables two minterms match we are gonna perform the action //if there are three of the variable matching //then it is duplicate turn-off one of the minterms in the status array by use of 0 for (i = 0; i < numOfMint; i++) { //finding for the relevent polynomial for reduction //cout<<" E"; for (int j = i + 1; j < numOfMint; i++) { //cout<<" F"; if (status[j] == 0) break; if (sop[i].x == sop[j].x) countMatch++; if (sop[i].y == sop[j].x) countMatch++; if (sop[i].z == sop[j].z) countMatch++;

//Upon finding a reducible boolean polynomials if (countMatch == 2) { status[i] = 1; status[j] = 0; if (sop[i].x == sop[j].x) simpSOP[i].x = 'x'; if (sop[i].y == sop[j].x) simpSOP[i].y = 'x'; if (sop[i].z == sop[j].z) simpSOP[i].z = 'x';

countMatch = 0; } //upon finding the duplicate polynomial else if (countMatch == 3) { status[i] = 1; status[j] = 0; simpSOP[i] = sop[i]; } //upon not finding any reducible boolean polynomial else { status[i] = 1; countMatch = 0; } }

}

//printing simplified SOP cout << " Simplified Expression f(x,y,z) = "; for (i = 0; i < numOfMint; i++) { //cout<<" G"; if (status[i] == 1) { if (i) cout << " + "; printSOP(sop[i]); } else continue; }

return EXIT_SUCCESS; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!