Question

In: Computer Science

C++: Write a program that produces truth tables for the following compound propositions. Write the header...

C++:

Write a program that produces truth tables for the following compound propositions. Write the header of the tables, including intermedial steps and the final result. There should be three tables. Output the result on the file prog2 output.txt.

1. p&!(p|q)

2. (p|q)&!(p&q)

3. (p–>q)<->(!q–>!p)

NOTE: Do not hard code truth tables. The program must use binary or bitwase operators to compute the results.

Solutions

Expert Solution

Coding

#include <iostream>//header file in and out
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main() {
bool p[4] = { true, true, false, false };//take variable as boolean value
bool q[4] = { true, false, true, false };//take variable as boolean value
ofstream myfile;
myfile.open ("output.txt");//make text file an output.txt
myfile<<endl<<"Table 1"<<endl;//write in text file
myfile << "p | q" << " | " << "p&!(p|q)" << endl;
for (int i = 0; i < 4; i++)
{
   myfile << setw(1) << p[i] << " | ";//write in text file
   for (int j = 0; j < 1; j++)
   {
   myfile << setw(1) << q[i] << " | ";//write in text file
   myfile << setw(3) << (p[i] && !(p[i]|q[i]));//write in text file
   }
   myfile << endl;
}
myfile<<endl<<"Table 2"<<endl;//write in text file
myfile << "p | q" << " | " << "(p|q)&!(p&q)" << endl;//write in text file
for (int i = 0; i < 4; i++)
{
   myfile << setw(1) << p[i] << " | ";//write in text file
   for (int j = 0; j < 1; j++)
   {
   myfile << setw(1) << q[i] << " | ";
   myfile << setw(3) << ((p[i]||q[i]) && !(p[i]&q[i]));//write in text file
   }
   myfile << endl;
}
myfile<<endl<<"Table 3"<<endl;
myfile << "p | q" << " | " << "(p–>q)<->(!q–>!p)" << endl;/*we have to elaborate this (p–>q)<->(!q–>!p) =*/
for (int i = 0; i < 4; i++)
{
   myfile << setw(1) << p[i] << " | ";
   for (int j = 0; j < 1; j++)
   {
   myfile << setw(1) << q[i] << " | ";//write in text file
   myfile << setw(3) << (!((!p[i]||q[i]) || (q[i]||!p[i])&&(!(q[i]||!p[i]) ||(!p[i]||q[i]))));//write in text file and simplicifcation in image file
   }
   myfile << endl;
}
myfile.close();
return 0;
}

output:

if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........


Related Solutions

C++ Write a program that produces the truth table of the following logical operators. You aresupposed...
C++ Write a program that produces the truth table of the following logical operators. You aresupposed to output one table with all the operators (one column for each operator). Write theheader of the table - this is the name of the columns-. Output the result on the file prog1 output.txt. The table should contain the letters T and F, it should NOT print 1s and 0s. Show theresults on the following order: 1. negation (!) 2. disjunction (AND operator, &)...
Write a program that generates and prints out in a neat format all possible truth tables...
Write a program that generates and prints out in a neat format all possible truth tables with three propositional variables p, q, and r. Your program should also number generated truth tables and output the numbers so it is clear how many total tables were generated. Your program output may look like the following (Note: only the beginning of the output is shown): Truth table 1: p q r proposition ----------------- F F F F F F T F F...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are...
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are witten below) "KINGSOM.h " program below: #ifndef WESTEROS_kINGDOM_H_INCLUDED #define WESTEROS_KINGDOM_H_INCLUDED #include <iostream> namespace westeros { class Kingdom{         public:                 char m_name[32];                 int m_population; };         void display(Kingdom&);                      } #endif } Kingdom.cpp Program below: #include <iostream> #include "kingdom.h" using namespace std; namespace westeros {         void display(Kingdom& pKingdom) {                 cout << pKingdom.m_name << ", population " << pKingdom.m_population << endl;                                                               FINAL:...
Decide, with justification, on the truth of the following propositions, both when the Universe of discourse...
Decide, with justification, on the truth of the following propositions, both when the Universe of discourse is the set of all positive integers, and when the Universe of discourse is the set of all real numbers. 1. ∃x∀y, x < x·y 2. ∀y∃x, x < x·y 3. ∃x∀y, x = x·y 4. ∀y∃x, x = x·y 5. ∀x∃y,∃z, y2 − z2 = 4x 6. ∀x∀y∃z, z < x2 + y2 7. ∀x∃y∃z, x > yz.
1. For each of the following propositions construct a truth table and indicate whether it is...
1. For each of the following propositions construct a truth table and indicate whether it is a tautology (i.e., it’s always true), a contradiction (it’s never true), or a contingency (its truth depends on the truth of the variables). Also specify whether it is a logical equivalence or not. Note: There should be a column for every operator. There should be three columns to show work for a biconditional. a) (P Λ ¬Q) ⇔ ¬(P ⇒ Q) b) (¬? V¬?)...
Decide, with justification, on the truth of the following propositions, both when the Universe of discourse...
Decide, with justification, on the truth of the following propositions, both when the Universe of discourse is the set of all positive integers, and when the Universe of discourse is the set of all real numbers. 1.18. ∃x∀y,x≤y. 1.19. ∀y∃x,x≤y. 1.20. ∃x∀y,x<y. 1.21. ∀y∃x,x<y. 1.22. ∃x ∀y, y ≤ x. 1.23. ∀y ∃x, y ≤ x. 1.24. ∃x ∀y, y < x. 1.25. ∀y ∃x, y < x. 1.26. ∃x∀y,(x < y ⇒ x2 < y2). 1.27. ∀y∃x,(x<y⇒x2 <y2).
Write a C++ program to construct the truth table of P ∨¬(Q ∧ R) If you...
Write a C++ program to construct the truth table of P ∨¬(Q ∧ R) If you could include comments to explain the code that would be much appreciated!!! :) Thank you so much!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT