Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this assignment will have you designing a program which can test multiple combin

ID: 3662267 • Letter: T

Question

this assignment will have you designing a program which can test multiple combinations of the Boolean variables A, B, and C, and determine which combinations of them will yield true values. However this time the logical statement is much larger, designed in the style of a Logical Circuit. As all three problems are designed with the same connections but differing logical gates, for this assignment you’ll need to work with functions to lessen the amount of time it takes to write this code. Your output will look similar to assignment 2 as well, with the eight different combinations of the variables A, B, and C, as well as the resulting output for each of the three logical circuits. You will find the three problems as well as a listing of what each gate represents in the attached link. Code in C++ only

PROBLEM 1 AND OR NOT PROBLEM 2 NAND NOR XOR XNOR NAND PROBLEM 3

Explanation / Answer

C ++ Code:

#include <iostream>

using namespace std;

char *decimal_to_binary(int);
void ckt1(void);
void ckt2(void);
void ckt3(void);
bool char_bool(char);

int main()
{
int a, b, c, num, binary[3];
cout<<endl << "__________________________________________________________________";
cout << endl << endl << "**** Logical Circuit 1 ****" << endl;
ckt1();
cout<<endl << "__________________________________________________________________";
cout << endl << endl << "**** Logical Circuit 2 ****" << endl;
ckt2();
cout<<endl << "__________________________________________________________________";
cout << endl << endl << "**** Logical Circuit 3 ****" << endl;
ckt3();
cout<<endl << "__________________________________________________________________";

return 0;
}

//Logical Circuit1
void ckt1()
{
int i;
bool binary[3];
char *pointer;
int a1,b1;
bool a, b, c, op, c1, c2;
for(i=0;i<8;i++)
{
pointer = decimal_to_binary(i);

a = char_bool(pointer[0]);
b = char_bool(pointer[1]);
c = char_bool(pointer[2]);

c1 = a && b;
c2 = (c || a) && (b || c);
op = (!(c1 && c2) && (c1 || c2));
cout<< endl << "Binary: " << a << b << c << " Output: " << op;
}
free(pointer);
}

//Logical Circuit2
void ckt2()
{
int i;
bool binary[3];
char *pointer;
int a1,b1;
bool a, b, c, op, c1, c2, c21, c22;
for(i=0;i<8;i++)
{
pointer = decimal_to_binary(i);

a = char_bool(pointer[0]);
b = char_bool(pointer[1]);
c = char_bool(pointer[2]);

c1 = !(!(a && b));
c21 = c || a;
c22 = !(b || c);
c2 = (!(c21 && c22) && (c21 || c22));
op = c1 && c2;

cout<< endl << "Binary: " << a << b << c << " Output: " << op;
}
free(pointer);
}

//Logical Circuit3
void ckt3()
{
int i;
bool binary[3];
char *pointer;
int a1,b1;
bool a, b, c, op, c1, c2, c21, c22;
for(i=0;i<8;i++)
{
pointer = decimal_to_binary(i);

a = char_bool(pointer[0]);
b = char_bool(pointer[1]);
c = char_bool(pointer[2]);

c1 = a || b;
c21 = !(c || a);
c22 = !(!(b && c) && (b || c));
c2 = !(c21 && c22);
op = !(!(c1 && c2) && (c1 || c2));

cout<< endl << "Binary: " << a << b << c << " Output: " << op;
}
free(pointer);
}


bool char_bool(char ch)
{
bool a;
if(ch == '0')
return false;
else
return true;
}

//Convert from decimal to binary

char *decimal_to_binary(int n)
{
int c, d, count;
char *pointer;

count = 0;
pointer = (char*)malloc(5+1);

if ( pointer == NULL )
exit(EXIT_FAILURE);

for ( c = 2 ; c >= 0 ; c-- )
{
d = n >> c;

if ( d & 1 )
*(pointer+count) = 1 + '0';
else
*(pointer+count) = 0 + '0';

count++;
}
*(pointer+count) = '';

return pointer;
}

Sample Output:

__________________________________________________________________

**** Logical Circuit 1 ****

Binary: 000 Output: 0
Binary: 001 Output: 1
Binary: 010 Output: 0
Binary: 011 Output: 1
Binary: 100 Output: 0
Binary: 101 Output: 1
Binary: 110 Output: 0
Binary: 111 Output: 0
__________________________________________________________________

**** Logical Circuit 2 ****

Binary: 000 Output: 0
Binary: 001 Output: 0
Binary: 010 Output: 0
Binary: 011 Output: 0
Binary: 100 Output: 0
Binary: 101 Output: 0
Binary: 110 Output: 1
Binary: 111 Output: 1
__________________________________________________________________

**** Logical Circuit 3 ****

Binary: 000 Output: 1
Binary: 001 Output: 0
Binary: 010 Output: 1
Binary: 011 Output: 1
Binary: 100 Output: 1
Binary: 101 Output: 1
Binary: 110 Output: 1
Binary: 111 Output: 1
__________________________________________________________________
Process returned 0 (0x0) execution time : 0.089 s
Press any key to continue.