Starting from:

$30

Lab1: Truth tables

CS 278
Lab1: Truth tables
A truth table for a compound proposition with three propositional variables p, q, and r consists of four
columns: a column with truth-values of p, a column with truth-values of q, a column with truth-values of
r, and a column with truth-values of the compound proposition.
p q r Proposition
F F F
F F T
F T F
F T T
T F F
T F T
T T F
T T T
The eight blank cells in the fourth column can be filled in many different ways, each by either T or F.
Two tables are the same when the truth values of propositions are the same for each combination of
truth values of variables. Two tables are different when the truth values of propositions are different for
at least one combination of truth values of variables. Below are examples of two different truth tables
(they have different values in the 3rd row):
Truth table 1: Truth table 2:
p q r proposition p q r proposition
F F F T F F F T
F F T F F F T F
F T F T F T F F
F T T T F T T T
T F F F T F F F
T F T F T F T F
T T F T T T F T
T T T F T T T F
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 T F F
F T T F
T F F F
T F T F
T T F F
T T T F
Truth table 2:
p q r proposition
-----------------
F F F F
F F T F
F T F F
F T T F
T F F F
T F T F
T T F F
T T T T
Truth table 3:
p q r proposition
-----------------
F F F F
F F T F
F T F F
F T T F
T F F F
T F T F
T T F T
T T T F
. . . (and so on)
Implementation details:
 All possible truth tables must be automatically generated by your program. That is, the last
column values must be automatically generated (e.g., use eight nested loops to do it). The first
three columns of truth tables could be hard-coded in your program.
 All truth tables must be numbered in the output.
 Printed truth tables must have ‘T’s and ‘F’s in them (do not use ‘1’ and ‘0’).
What to submit:
 Submit the source code of your program using Canvas. That is, submit *.java file if you wrote
in Java, *.cpp file if you wrote in C++, etc.
 If you write your program in a programming language other than Java, then submit instructions
on how to compile and run your program on CS machines.

More products