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

Assignment : Create a program that can try out every possible logical combinatio

ID: 3661901 • Letter: A

Question

Assignment: Create a program that can try out every possible logical combination of the variables A, B, and C, and determine which combinations will yield a true statement. A few things to take note of, first there are eight different possible combinations of the three variables. Make certain you test all eight of the combinations. The code itself will account for 50pts. Include the combinations of A, B, and C that cause the statement to be true for an additional 50pts.

(1)  (A and B) or (A and C)

(2) (A and C) and (B and !C)

(3) (A or B) and !(B or C)

(4) (A or (B and C)) and (!C and !B)

(5) ((B and C) or (C and A)) and (!(A or B) and C)

Please read each of the five carefully and make sure your code accurately reproduces the logical statement given for each problem. Note that the exclamation symbol indicates the logical “NOT” operator, and the parentheses indicate which order the statements are to be performed in. Keep in mind since you’re testing all possible combinations of input for all five logical statements, you’ll have forty answers generated by your program, in total.

Answer must be in C++

Explanation / Answer

Good Wises,

Program in C++:

#include <iostream>

using namespace std;

int main()
{
int i=0,ct=0;
int a[8]={0,0,0,0,1,1,1,1};
int b[8]={0,0,1,1,0,0,1,1};
int c[8]={0,1,0,1,0,1,0,1};
cout << "Hello " << endl;
while(i<8)
{
if((a[i] and b[i])or(a[i] and c[i]))
{
cout<<"(A and B) or (A and C) is true for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i]<<endl;
ct++;
}

/*else

cout<<"(A and B) or (A and C) is false for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i]<<endl; */
  
i++;
}
if(ct==0)
cout<<"(A and B) or (A and C) is false for all combinations of values of A,B and C ";
i=0;
ct=0;
while(i<8)
{
if((a[i] and c[i])and(b[i] and (not(c[i]))))
{
cout<<"(A and C) and (B and !C) is true for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i]<<endl;
ct++;
}

/* else

cout<<"(A and C) and (B and !C) is false for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i]<<endl;*/   
i++;
}
if(ct==0)
cout<<"(A and C) and (B and !C) is false for all combinations of values of A,B and C ";
i=0;
ct=0;
while(i<8)
{
if((a[i] or b[i])and not((b[i] or c[i])))
{
cout<<"(A or B) and !(B or C) is true for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i]<<endl;
ct++;
}

/*else

cout<<"(A or B) and !(B or C) is false for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i]<<endl;*/
i++;
}
if(ct==0)
cout<<"(A or B) and !(B or C) is false for all combinations of values of A,B and C ";
i=0;
ct=0;
while(i<8)
{
if((a[i] or (b[i] and c[i]))and ((not c[i]) and not(b[i])))
{
cout<<"(A or (B and C)) and (!C and !B) is true for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i]<<endl;
ct++;
}

/* else

  cout<<"(A or (B and C)) and (!C and !B) is true for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i]<<endl; */
i++;
}
if(ct==0)
cout<<"(A or (B and C)) and (!C and !B) is false for all combinations of values of A,B and C ";
i=0;
ct=0;
while(i<8)
{
if(((b[i] and c[i]) or (c[i] and a[i])) and (not(a[i] or b[i]) and c[i]) )
{
cout<<"((B and C) or (C and A)) and (!(A or B) and C) is true for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i] <<endl;
ct++;
}

/* else

cout<<"((B and C) or (C and A)) and (!(A or B) and C) is true for A="<<a[i]<<" B="<<b[i]<<" C="<<c[i] <<endl; */
i++;
}
if(ct==0)
cout<<"((B and C) or (C and A)) and (!(A or B) and C) is false for all combinations of values of A,B and C ";
return 0;
}

Output:

Hello
(A and B) or (A and C) is true for A=1 B=0 C=1
(A and B) or (A and C) is true for A=1 B=1 C=0
(A and B) or (A and C) is true for A=1 B=1 C=1
(A and C) and (B and !C) is false for all combinations of values of A,B and C
(A or B) and !(B or C) is true for A=1 B=0 C=0
(A or (B and C)) and (!C and !B) is true for A=1 B=0 C=0
((B and C) or (C and A)) and (!(A or B) and C) is false for all combinations of values of A,B and C

Explaination:

Initially I took 3 arrays a,b,c to represent all the combinations they can have,as below

int a[8]={0,0,0,0,1,1,1,1};
int b[8]={0,0,1,1,0,0,1,1};
int c[8]={0,1,0,1,0,1,0,1};

thus we have

a b c

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

Then using while loop I checked for all combinations against each statement an dhence 5 while loop were run.

In each while loop a counter ct is used to count the number of combinations of values of a,b and c for which the statement is true.

After the while loop the counter ct is checked, if it is 0, then it means the statement is false for all combinations of values of a,b and c.

This program prints only the combinations for which the statement was true.

If the commented lines are uncommented then even the combinations for which the statement is false will also be printed.

Thus printing all possible outcomes with its true or false status.

I felt only true one's are cool. If you want all the 40 answers remove the comments for commented lines.

Hope this is clear.