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...
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?
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*
C++ language You will create a Hangman class. Possible private member variables: int numOfCharacters; //for the...
C++ language You will create a Hangman class. Possible private member variables: int numOfCharacters; //for the secret word char * secretWord; char *guessedWord; public: //please create related constructors, getters, setters,constructor() constructor() You will need to initialize all member variables including the two dynamic variables. destructor() Please deallocate/freeup(delete) the two dynamic arrays memories. guessALetter(char letter) 1.the function will check if the letter guessed is included in the word. 2. display the guessed word with related field(s) filled if the letter guessed...
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
create a program in java that will evaluate a logical expression (compound proposition) based on the...
create a program in java that will evaluate a logical expression (compound proposition) based on the given truth values of individual propositional variables. The logical expression may include the logical AND or the logical OR operators. The NOT operator will be included in the variable names itself. So, a proposition such as ¬a would appear as na in the logical expression. Here is an example of a logical expression using proper notation: a ∧ b ∨ ¬c ∨ d This...
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.
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track of the statistics for a kid’s soccer team. The program will have a structure that defines what data the program will collect for each of the players. The structure will keep the following data: Players Name (string) Players Jersey Number (integer) Points scored by Player (integer) The program will have an array of 12 players (use less for testing and development, use a constant...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT