closed account (*DG6DjE8b*)

Hey guys I am really lost on how to do this problem. Plz give me some inputs.

The program must evaluate the truth value of the conjunction, disjunction, and implication of

each value row. For each logical operator, P is the argument to the left of the operator and Q is to

the right. For conjunction: P ^ Q, disjunction: P _ Q, and implication: P ! Q.

Example prog2 input.txt

P Q

T T

T F

F F

For each value row the program must output a corresponding row, in the following format:

P and Q:<T or F> ntP or Q:<T or F> ntP --> Q:<T or F> For the example input given above

the output is found below.

Example prog2 output.txt

P and Q : T P or Q : T P --> Q : T

P and Q : F P or Q : T P --> Q : F

P and Q : F P or Q : F P --> Q : T

.

This is what I did so far

# include<iostream>

#include<fstream>

using namespace std;

bool charTobool (char c)

{

switch (c)

{

case 'T':

return true;

case 'F':

return false;

default:

return false;

}

}

int main()

{

fstream ifile("prog2_input.txt");

char p,q;

ifile>>p>>q;

//process value rows

while(! ifile.eof())

{

if (ifile>>p>>q);

{

bool left= charTobool (p);

bool right = charTobool (q);

if(p=='T' && q =='T' )

{

The program must evaluate the truth value of the conjunction, disjunction, and implication of

each value row. For each logical operator, P is the argument to the left of the operator and Q is to

the right. For conjunction: P ^ Q, disjunction: P _ Q, and implication: P ! Q.

Example prog2 input.txt

P Q

T T

T F

F F

For each value row the program must output a corresponding row, in the following format:

P and Q:<T or F> ntP or Q:<T or F> ntP --> Q:<T or F> For the example input given above

the output is found below.

Example prog2 output.txt

P and Q : T P or Q : T P --> Q : T

P and Q : F P or Q : T P --> Q : F

P and Q : F P or Q : F P --> Q : T

.

This is what I did so far

# include<iostream>

#include<fstream>

using namespace std;

bool charTobool (char c)

{

switch (c)

{

case 'T':

return true;

case 'F':

return false;

default:

return false;

}

}

int main()

{

fstream ifile("prog2_input.txt");

char p,q;

ifile>>p>>q;

//process value rows

while(! ifile.eof())

{

if (ifile>>p>>q);

{

bool left= charTobool (p);

bool right = charTobool (q);

if(p=='T' && q =='T' )

{

Please use code tags. It is the button that has '<>' on it. This makes your post easier to read. I'm also having some issue understanding your goal, could you maybe simplify it please?

Topic archived. No new replies allowed.