Question

In: Computer Science

In C++, Create a program that can try out every possible logical combination of the variables...

In C++, 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. Take note that there are eight different possible combinations of the three variables. Make certain you test all eight of the combinations.

(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 (!A and C)) and (!A and !B)

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

Solutions

Expert Solution

#include<iostream>
using namespace std;

int main()
{
   cout<<"(1)Testing: expression : (A and B) or (A and C)\n";
   bool a[] = {true,false};
int c=0;
cout<<" A | B | C | (A and B) or (A and C)\n";
   for(int i=0;i<2;i++)
       for(int j=0;j<2;j++)
       for(int k=0;k<2;k++)
           {
               bool A = a[i];
               bool B = a[j];
               bool C= a[k];
               bool result =( (A && B) || (A && C) );//(A and B) or (A and C)
               if(result)c++;
               cout<<boolalpha<<A<<"|";  
               cout<<boolalpha<<B<<"|";
               cout<<boolalpha<<C<<"|";
               cout<<boolalpha<<result<<endl;
           }
   if(c==8)cout<<"(A and B) or (A and C) is True Statement\n";
   c=0;
  
   cout<<"(2)Testing: expression : (A and C) and (B and !C)\n";
cout<<" A | B | C | (A and C) and (B and !C)\n";
   for(int i=0;i<2;i++)
       for(int j=0;j<2;j++)
       for(int k=0;k<2;k++)
           {
               bool A = a[i];
               bool B = a[j];
               bool C= a[k];
               bool result =( (A && C) || (B && !C) );// (A and C) and (B and !C)
               if(result)c++;
               cout<<boolalpha<<A<<"|";  
               cout<<boolalpha<<B<<"|";
               cout<<boolalpha<<C<<"|";
               cout<<boolalpha<<result<<endl;
           }
   if(c==8)cout<<" (A and C) and (B and !C) is True Statement\n";
   c=0;
  
  
       cout<<"(3)Testing: expression : (A or B) and !(B or C)\n";
cout<<" A | B | C | (A or B) and !(B or C)\n";
   for(int i=0;i<2;i++)
       for(int j=0;j<2;j++)
       for(int k=0;k<2;k++)
           {
               bool A = a[i];
               bool B = a[j];
               bool C= a[k];
               bool result =( (A || B) && !(B || C));// (A or B) and !(B or C)
               if(result)c++;
               cout<<boolalpha<<A<<"|";  
               cout<<boolalpha<<B<<"|";
               cout<<boolalpha<<C<<"|";
               cout<<boolalpha<<result<<endl;
           }
   if(c==8)cout<<" (A or B) and !(B or C) is True Statement\n";
   c=0;
  
  
       cout<<"(4)Testing: expression : (A or (!A and C)) and (!A and !B)\n";
cout<<" A | B | C | (A or (!A and C)) and (!A and !B)\n";
   for(int i=0;i<2;i++)
       for(int j=0;j<2;j++)
       for(int k=0;k<2;k++)
           {
               bool A = a[i];
               bool B = a[j];
               bool C= a[k];
               bool result =( (A || (!A && C)) and (!A && !B) );// (A or (!A and C)) and (!A and !B)
               if(result)c++;
               cout<<boolalpha<<A<<"|";  
               cout<<boolalpha<<B<<"|";
               cout<<boolalpha<<C<<"|";
               cout<<boolalpha<<result<<endl;
           }
   if(c==8)cout<<" (A or (!A and C)) and (!A and !B) is True Statement\n";
   c=0;
  
  
       cout<<"(5)Testing: expression : ((B and C) or (C and A)) and ((A or B) and C)\n";
cout<<" A | B | C | ((B and C) or (C and A)) and ((A or B) and C)\n";
   for(int i=0;i<2;i++)
       for(int j=0;j<2;j++)
       for(int k=0;k<2;k++)
           {
               bool A = a[i];
               bool B = a[j];
               bool C= a[k];
               bool result =( ((B && C) || (C && A)) && ((A || B) && C) );// ((B and C) or (C and A)) and ((A or B) and C)
               if(result)c++;
               cout<<boolalpha<<A<<"|";  
               cout<<boolalpha<<B<<"|";
               cout<<boolalpha<<C<<"|";
               cout<<boolalpha<<result<<endl;
           }
   if(c==8)cout<<"((B and C) or (C and A)) and ((A or B) and C) is True Statement\n";
   c=0;
}

output:

(1)Testing: expression : (A and B) or (A and C)
A | B | C | (A and B) or (A and C)
true|true|true|true
true|true|false|true
true|false|true|true
true|false|false|false
false|true|true|false
false|true|false|false
false|false|true|false
false|false|false|false
(2)Testing: expression : (A and C) and (B and !C)
A | B | C | (A and C) and (B and !C)
true|true|true|true
true|true|false|true
true|false|true|true
true|false|false|false
false|true|true|false
false|true|false|true
false|false|true|false
false|false|false|false
(3)Testing: expression : (A or B) and !(B or C)
A | B | C | (A or B) and !(B or C)
true|true|true|false
true|true|false|false
true|false|true|false
true|false|false|true
false|true|true|false
false|true|false|false
false|false|true|false
false|false|false|false
(4)Testing: expression : (A or (!A and C)) and (!A and !B)
A | B | C | (A or (!A and C)) and (!A and !B)
true|true|true|false
true|true|false|false
true|false|true|false
true|false|false|false
false|true|true|false
false|true|false|false
false|false|true|true
false|false|false|false
(5)Testing: expression : ((B and C) or (C and A)) and ((A or B) and C)
A | B | C | ((B and C) or (C and A)) and ((A or B) and C)
true|true|true|true
true|true|false|false
true|false|true|true
true|false|false|false
false|true|true|true
false|true|false|false
false|false|true|false
false|false|false|false


Process exited normally.
Press any key to continue . . .


Related Solutions

1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
Create a C++ program that consists of the following: In maincreate the following three variables:...
Create a C++ program that consists of the following: In main create the following three variables: A char named theChar A double named theDouble An int named theInt Fill each of these variables with data taken as input from the keyboard using a single cin statement. Perform the following task on each variable: Increment theChar by one Decrement theDouble by two Square theInt This should be done on separate lines. Output the value of each variable to the screen on...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Create a C Program that reads a file and replaces every other letter with an asterisk....
Create a C Program that reads a file and replaces every other letter with an asterisk. The first integer 'num' is the number of lines. Include an "Error" Message and exit the program if:    The wrong name for the input/output file is given    The input/output file can not be opened input.txt 7 Never Have We Ever Played A Game output.txt 7 N*v*r *a*e W* *v*r *l*y*d * G*m*
a basketball coach was criticized in a newspaper for not trying out every combination of players....
a basketball coach was criticized in a newspaper for not trying out every combination of players. if the team roster has 14 players and every player can play every position how many 5-player combinations are possible?
Problems create a C++ program that will do the followings - define 3 double variables x,...
Problems create a C++ program that will do the followings - define 3 double variables x, y, z - calculate the value of y as the following formula: y = 2*x*x+4*x+5 and print x and y; - assign a new value to x: x=5.6 - calculate the value of z as the following formula z = (y*y)/4 + (x*x)/5 - print x, y,x
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases in which the initial unit is Fahrenheit or something not recognizable. Your program should incorporate Fahrenheit to Celsius, Fahrenheit to Kelvin and unknown initial units (display an error message for this last one). You must use functions to calculate Fahrenheit degrees.
reate a C# program. -Create 5 variables as decimals: Count, pricce, subtotal, tax, and total -Use...
reate a C# program. -Create 5 variables as decimals: Count, pricce, subtotal, tax, and total -Use a do while loop. If the price is not -1, the loop continues. Show count number (ie: Item 1, Item 2, Item 3...) Enter price Get subtotal Increase count -Calculate tax(0.035%) and total Show total count, subtotal, tax,and total Output: Item1: $2.00 Item2:: $3.00 Item3: $1.00 Item4: $-2 (Note: A negative number will not be substracted. It will only be ignored) There are 3...
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input...
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input a description of several process schedules (i.e., lists of send, receive or print operations). The output of your program will be a linearization of these events in the order actually performed, annotated with Lamport clock values. The input of the program will be a collection of processes, each with a list of operations to perform. The processes are named p1...pn for some n (you...
(In C) Note: Can you create an example code of these tasks. use any variables you...
(In C) Note: Can you create an example code of these tasks. use any variables you wish to use. postfix expressions: (each individual text (T), (F), (NOT), etc is a token) F T NOT T F NOT T T T AND F T F NAND (1) Create stack s. (2) For each token, x, in the postfix expression: If x is T or F push it into the stack s. (T = true, F = false) Else if x is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT