Argument Validity & Truth Tables

HI, I am hoping that I can get some guidance on this problem in my Discrete Structures I class. I am a beginner to C++ and my previous C++ class only taught the basics through Arrays and Structs. It also doesn't help that the teacher in this class does not actually teach any programming skills and we are somehow expected to do these problems without her guidance. I apologize if this gets lengthy but I wanted to provide as much information as possible.

Problem: Produce a truth table for an argument and determine if the argument is valid. If the argument is not valid the program will identify which row(s) of the truth table indicate an invalid argument.

The program needs to be able to run any variation of the argument (same number of statements and variables as the example below). The teacher will change the argument code directly so no user input needed.

Example argument:
Premise: (((P v Q) ^ (Q -> R)) XOR (P ^ R)) <-> (R ^ Q)
Conclusion: (P V R)

I know the following information:

p q r
T T T
T T F
T F T
T F F
F T T
F T F
F F T
F F F

The teacher recommended creating two functions - premise and conclusion - both with three parameters (p, q, r) and run it 8 times, one for each row in the truth table. I'm really not sure what that would look like and where it would pass the result to.

I know that I need to be able to evaluate each portion of the premise and conclusion. Another student recommend I create functions AND(), OR(), XOR(), IF(), and IFF() that would be called by entering the argument in the following form:

IFF(XOR(AND(OR(P,Q),IF(Q,R)),AND(P,R)),AND(R,Q))

So many functions within functions and can't even begin to wrap my head around how the results from the functions would be passed to other functions. For example, if one or more parameter is P, Q, or R, I cannot evaluate the truth value without first reading the table above for each row. Then where would I pass that information? There would be two results. If both parameters are 0 or 1, I can evaluate the truth value easily, but that won't always be the case. Am I making this more complicated than it needs to be?

Thank you, any help is surely appreciated.
Last edited on
Problem: Produce a truth table for an argument and determine if the argument is valid. If the argument is not valid the program will identify which row(s) of the truth table indicate an invalid argument.
The program needs to be able to run any variation of the argument (same number of statements and variables as the example below). The teacher will change the argument code directly so no user input needed.
Example argument:
Premise: (((P v Q) ^ (Q -> R)) XOR (P ^ R)) <-> (R ^ Q)
Conclusion: (P V R)
I know the following information:
p q r
T T T
T T F
T F T
T F F
F T T
F T F
F F T
F F F
The teacher recommended creating two functions - premise and conclusion - both with three parameters (p, q, r) and run it 8 times, one for each row in the truth table. I'm really not sure what that would look like and where it would pass the result to.
I know that I need to be able to evaluate each portion of the premise and conclusion. Another student recommend I create functions AND(), OR(), XOR(), IF(), and IFF() that would be called by entering the argument in the following form:
IFF(XOR(AND(OR(P,Q),IF(Q,R)),AND(P,R)),AND(R,Q))

It seems it’s not a totally original problem. Read here:
http://www.chegg.com/homework-help/questions-and-answers/premise-p-v-q-q-r-xor-p-r-r-q-conclusion-p-v-r-create-c-program-generates-truth-table-argu-q11993379
Premise: ((P v Q) ^ (Q -> R) XOR (P ^ R)) <-> (R ^ Q) Conclusion: (P v R) Create a C++ program that generates the truth table for this argument, and indicates if the argument is valid or invalid. If the argument is invalid, identify the row(s) in the truth table that prove the argument is not valid. Your program must be modularized so that the argument can be assessed when your program is graded.
Some more hints:
a. Create a premise function with 3 parameters for the 3 variables.
This function returns the different values (0 or 1) passed to the expression ((P v Q) ^ (Q -> R) XOR (P ^ R)) <-> (R ^ Q).
bool getPremise(bool p, bool q, bool r)
b. Create a conclusion function with 3 parameters for the 3 variables.
This function returns the different values (0 or 1) passed to the expression (P v R)
bool getConclusion(bool p, bool r) { return (p || r); }
c. Loop through all the various boolean value combinations of P, Q, R.
Apply the P, Q and R boolean values to getPremise and getConclusion
Print the results in a truth table set.

It seems also the same errors are repeated: is says “Create a conclusion function with 3 parameters” and gives as an example: bool getConclusion(bool p, bool r), which has got two.

Anyway, the first problem is correlating the symbols you use with the C+ once, since ^ should be the symbol for XOR and so on.
I think the first step is determine if
(((P v Q) ^ (Q -> R)) XOR (P ^ R)) <-> (R ^ Q)
can be translated into:
(((P | Q) & (Q implies R)) XOR (P & R)) == (R & Q)
or not.
Once you have the correct ‘translation’, the code looks feasible.
Topic archived. No new replies allowed.