Anyone happen to know about truth table?
Author |
Message |
Fantasy #1 / 13
|
Anyone happen to know about truth table?
I want to study how truth table is written in C. erm, it is about entering a string containing the expression to be evaluated, e.g. A.B+C, from here is evaluate the answer whether is it 1 or 0. You see i don't know the codes so it can do the calcuation to be written in C. Is there anything i missed? Do u need a truth table to be based on? -- - <-------------------FantasyZ----------------------->
ooO_(_)_Ooo_______________ __|_____|_____|_____|_____|__ _|_Born_|__to__|__be__|_Free__-|
|
Mon, 23 Dec 2002 03:00:00 GMT |
|
|
Mal Ka #2 / 13
|
Anyone happen to know about truth table?
Quote:
> I want to study how truth table is written in C. > erm, it is about entering a string containing the expression to be > evaluated, e.g. A.B+C, from here is evaluate the answer whether is it 1 or > 0. > You see i don't know the codes so it can do the calcuation to be written in > C. > Is there anything i missed? Do u need a truth table to be based on?
It is not very clear what you are looking for. It is difficult to study 'truth tables' written in C because they are not known to the standard. However your mention of the expression 'A.B+C' suggests that you are really interested in C's boolean or logical operators. I assume that '.' represents logical 'and' and '+' represents logical 'or' in your expression. In C the corresponding operators are '&&' and '||'. In general logical expressions take the value 'true' or 'false', not 1 or 0. In C any non-zero integer value is taken to represent 'true' while 'false' is always represented by an integer value of zero. However 'true' values generated by a logical or relational expressions are coded as 1. Malcolm Kay
|
Mon, 23 Dec 2002 03:00:00 GMT |
|
|
Fantasy #3 / 13
|
Anyone happen to know about truth table?
I wonder is that any source code for it i can look into? -- - <-------------------FantasyZ----------------------->
ooO_(_)_Ooo_______________ __|_____|_____|_____|_____|__ _|_Born_|__to__|__be__|_Free__-|
Quote:
> > I want to study how truth table is written in C. > > erm, it is about entering a string containing the expression to be > > evaluated, e.g. A.B+C, from here is evaluate the answer whether is it 1 or > > 0. > > You see i don't know the codes so it can do the calcuation to be written in > > C. > > Is there anything i missed? Do u need a truth table to be based on? > It is not very clear what you are looking for. > It is difficult to study 'truth tables' written in C > because they are not known to the standard. > However your mention of the expression 'A.B+C' suggests that you > are really interested in C's boolean or logical operators. I assume > that '.' represents logical 'and' and '+' represents logical 'or' > in your expression. In C the corresponding operators are '&&' and > '||'. In general logical expressions take the value 'true' or 'false', > not 1 or 0. In C any non-zero integer value is taken to represent > 'true' while 'false' is always represented by an integer value of > zero. However 'true' values generated by a logical or relational > expressions are coded as 1. > Malcolm Kay
|
Mon, 23 Dec 2002 03:00:00 GMT |
|
|
Lew Pitch #4 / 13
|
Anyone happen to know about truth table?
Quote: >I wonder is that any source code for it i can look into?
How about... #include <stdio.h> #include <stdlib.h> #define TRUTH(a) (((a) != 0) ? 'T' : 'F') int main(void) { int p1, p2; printf("a b ~a a.b a+b a^b\n"); printf("= = == === === ===\n"); for (p1 = 0; p1 < 2 ; ++p1) { for (p2 = 0; p2 < 2; ++p2) { char a, b; a = TRUTH(p1); b = TRUTH(p2); printf("%c %c ", a, b); printf("%c ", TRUTH(!a)); /* not A */ printf("%c ", TRUTH(a && b)); /* A and B */ printf("%c ", TRUTH(a || b)); /* A or B */ printf("%c", TRUTH(a ^ b)); /* A xor B */ printf("\n"); } } return EXIT_SUCCESS; Quote: }
>> > I want to study how truth table is written in C. >> > erm, it is about entering a string containing the expression to be >> > evaluated, e.g. A.B+C, from here is evaluate the answer whether is it 1 >or >> > 0. >> > You see i don't know the codes so it can do the calcuation to be written >in >> > C. >> > Is there anything i missed? Do u need a truth table to be based on? >> It is not very clear what you are looking for. >> It is difficult to study 'truth tables' written in C >> because they are not known to the standard. >> However your mention of the expression 'A.B+C' suggests that you >> are really interested in C's boolean or logical operators. I assume >> that '.' represents logical 'and' and '+' represents logical 'or' >> in your expression. In C the corresponding operators are '&&' and >> '||'. In general logical expressions take the value 'true' or 'false', >> not 1 or 0. In C any non-zero integer value is taken to represent >> 'true' while 'false' is always represented by an integer value of >> zero. However 'true' values generated by a logical or relational >> expressions are coded as 1. >> Malcolm Kay
Lew Pitcher Information Technology Consultant Toronto Dominion Bank Financial Group
(Opinions expressed are my own, not my employer's.)
|
Mon, 23 Dec 2002 03:00:00 GMT |
|
|
Lew Pitch #5 / 13
|
Anyone happen to know about truth table?
Oops, I goofed (last minute changes caught me) Here's a better one #include <stdio.h> #include <stdlib.h> #define TRUTH(a) ((a) != 0) int main(void) { int p1, p2; printf("a b ~a a.b a+b a^b\n"); printf("= = == === === ===\n"); for (p1 = 0; p1 < 2 ; ++p1) { for (p2 = 0; p2 < 2; ++p2) { int a, b; a = TRUTH(p1); b = TRUTH(p2); printf("%d %d ", a, b); printf("%d ", TRUTH(!a)); /* not A */ printf("%d ", TRUTH(a && b)); /* A and B */ printf("%d ", TRUTH(a || b)); /* A or B */ printf("%d", TRUTH(a ^ b)); /* A xor B */ printf("\n"); } } return EXIT_SUCCESS; Quote: }
?
Quote:
>>I wonder is that any source code for it i can look into? >How about... >#include <stdio.h> >#include <stdlib.h> >#define TRUTH(a) (((a) != 0) ? 'T' : 'F') >int main(void) >{ > int p1, p2; > printf("a b ~a a.b a+b a^b\n"); > printf("= = == === === ===\n"); > for (p1 = 0; p1 < 2 ; ++p1) > { > for (p2 = 0; p2 < 2; ++p2) > { > char a, b; > a = TRUTH(p1); b = TRUTH(p2); > printf("%c %c ", a, b); > printf("%c ", TRUTH(!a)); /* not A */ > printf("%c ", TRUTH(a && b)); /* A and B */ > printf("%c ", TRUTH(a || b)); /* A or B */ > printf("%c", TRUTH(a ^ b)); /* A xor B */ > printf("\n"); > } > } > return EXIT_SUCCESS; >}
>>> > I want to study how truth table is written in C. >>> > erm, it is about entering a string containing the expression to be >>> > evaluated, e.g. A.B+C, from here is evaluate the answer whether is it 1 >>or >>> > 0. >>> > You see i don't know the codes so it can do the calcuation to be written >>in >>> > C. >>> > Is there anything i missed? Do u need a truth table to be based on? >>> It is not very clear what you are looking for. >>> It is difficult to study 'truth tables' written in C >>> because they are not known to the standard. >>> However your mention of the expression 'A.B+C' suggests that you >>> are really interested in C's boolean or logical operators. I assume >>> that '.' represents logical 'and' and '+' represents logical 'or' >>> in your expression. In C the corresponding operators are '&&' and >>> '||'. In general logical expressions take the value 'true' or 'false', >>> not 1 or 0. In C any non-zero integer value is taken to represent >>> 'true' while 'false' is always represented by an integer value of >>> zero. However 'true' values generated by a logical or relational >>> expressions are coded as 1. >>> Malcolm Kay >Lew Pitcher >Information Technology Consultant >Toronto Dominion Bank Financial Group
>(Opinions expressed are my own, not my employer's.)
Lew Pitcher Information Technology Consultant Toronto Dominion Bank Financial Group
(Opinions expressed are my own, not my employer's.)
|
Mon, 23 Dec 2002 03:00:00 GMT |
|
|
Fantasy #6 / 13
|
Anyone happen to know about truth table?
Ahhh..... I know that!!! I know how to do that..... That is simple.. what I really don't know is how to create a program that will evaulate a expression eg, A+B.C. By entering this expression it evaulate the answer 1 or 0........ that is what is don't know.... erm anyone? pls..... -- - <-------------------FantasyZ----------------------->
ooO_(_)_Ooo_______________ __|_____|_____|_____|_____|__ _|_Born_|__to__|__be__|_Free__-|
Quote: > Oops, I goofed (last minute changes caught me) > Here's a better one > #include <stdio.h> > #include <stdlib.h> > #define TRUTH(a) ((a) != 0) > int main(void) > { > int p1, p2; > printf("a b ~a a.b a+b a^b\n"); > printf("= = == === === ===\n"); > for (p1 = 0; p1 < 2 ; ++p1) > { > for (p2 = 0; p2 < 2; ++p2) > { > int a, b; > a = TRUTH(p1); b = TRUTH(p2); > printf("%d %d ", a, b); > printf("%d ", TRUTH(!a)); /* not A */ > printf("%d ", TRUTH(a && b)); /* A and B */ > printf("%d ", TRUTH(a || b)); /* A or B */ > printf("%d", TRUTH(a ^ b)); /* A xor B */ > printf("\n"); > } > } > return EXIT_SUCCESS; > } > ?
> >>I wonder is that any source code for it i can look into? > >How about... > >#include <stdio.h> > >#include <stdlib.h> > >#define TRUTH(a) (((a) != 0) ? 'T' : 'F') > >int main(void) > >{ > > int p1, p2; > > printf("a b ~a a.b a+b a^b\n"); > > printf("= = == === === ===\n"); > > for (p1 = 0; p1 < 2 ; ++p1) > > { > > for (p2 = 0; p2 < 2; ++p2) > > { > > char a, b; > > a = TRUTH(p1); b = TRUTH(p2); > > printf("%c %c ", a, b); > > printf("%c ", TRUTH(!a)); /* not A */ > > printf("%c ", TRUTH(a && b)); /* A and B */ > > printf("%c ", TRUTH(a || b)); /* A or B */ > > printf("%c", TRUTH(a ^ b)); /* A xor B */ > > printf("\n"); > > } > > } > > return EXIT_SUCCESS; > >}
> >>> > I want to study how truth table is written in C. > >>> > erm, it is about entering a string containing the expression to be > >>> > evaluated, e.g. A.B+C, from here is evaluate the answer whether is it 1 > >>or > >>> > 0. > >>> > You see i don't know the codes so it can do the calcuation to be written > >>in > >>> > C. > >>> > Is there anything i missed? Do u need a truth table to be based on? > >>> It is not very clear what you are looking for. > >>> It is difficult to study 'truth tables' written in C > >>> because they are not known to the standard. > >>> However your mention of the expression 'A.B+C' suggests that you > >>> are really interested in C's boolean or logical operators. I assume > >>> that '.' represents logical 'and' and '+' represents logical 'or' > >>> in your expression. In C the corresponding operators are '&&' and > >>> '||'. In general logical expressions take the value 'true' or 'false', > >>> not 1 or 0. In C any non-zero integer value is taken to represent > >>> 'true' while 'false' is always represented by an integer value of > >>> zero. However 'true' values generated by a logical or relational > >>> expressions are coded as 1. > >>> Malcolm Kay > >Lew Pitcher > >Information Technology Consultant > >Toronto Dominion Bank Financial Group
> >(Opinions expressed are my own, not my employer's.) > Lew Pitcher > Information Technology Consultant > Toronto Dominion Bank Financial Group
> (Opinions expressed are my own, not my employer's.)
|
Tue, 24 Dec 2002 03:00:00 GMT |
|
|
Regi #7 / 13
|
Anyone happen to know about truth table?
Quote:
> Ahhh..... I know that!!! I know how to do that..... > That is simple.. what I really don't know is how to create a program that > will evaulate a expression eg, A+B.C. By entering this expression it > evaulate the answer 1 or 0........ that is what is don't know.... erm > anyone? > pls.....
The problem is that it is about the third time that guys here tell you that your question is not clearly asked, and you persist to ask it again exactly in the same form. Rgis
|
Tue, 24 Dec 2002 03:00:00 GMT |
|
|
Joona I Palast #8 / 13
|
Anyone happen to know about truth table?
:> :> Ahhh..... I know that!!! I know how to do that..... :> :> That is simple.. what I really don't know is how to create a program that :> will evaulate a expression eg, A+B.C. By entering this expression it :> evaulate the answer 1 or 0........ that is what is don't know.... erm :> anyone? :> pls..... : The problem is that it is about the third time that guys here tell you : that your question is not clearly asked, : and you persist to ask it again exactly in the same form. From what _I_ understand, FantasyZ wants a program that inputs an expression like "A+B.C" and outputs a value that is either 1 or 0. Kind of like so:
How many variables? 3 Value of "A"? 1 Value of "B"? 1 Value of "C"? 0 Enter expression? A+B.C The value of "A+B.C" is 1. If that's what he wants, he should study expression evaluation algorithms based on the "two stacks" implementation. --
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #80 D+ ADA N+++ | | http://www.helsinki.fi/~palaste W++ B OP+ | \----------------------------------------- Finland rules! ------------/ "A bicycle cannot stand up by itself because it's two-tyred." - Sky Text
|
Tue, 24 Dec 2002 03:00:00 GMT |
|
|
Regi #9 / 13
|
Anyone happen to know about truth table?
Quote:
> : The problem is that it is about the third time that guys here tell you > : that your question is not clearly asked, > : and you persist to ask it again exactly in the same form. > From what _I_ understand, FantasyZ wants a program that inputs an > expression like "A+B.C" and outputs a value that is either 1 or 0. > Kind of like so:
> How many variables? 3 > Value of "A"? 1 > Value of "B"? 1 > Value of "C"? 0 > Enter expression? A+B.C > The value of "A+B.C" is 1.
* He did not say whether A,B,C were immediate boolean constants or were symbolic propositional variable. * In the 2nd case, he did not say if the set and number of variables was fixed in advance (as you suggested). * He did not say if a variable name was necessarilily a single letter * He did not say if he wanted parentheses * What about priorities of operators ? * What are + and . + could be interpreted as 'logical or', 'logical xor'... * How does he negate a variable: Is there an unary operator ? etc, etc.
|
Tue, 24 Dec 2002 03:00:00 GMT |
|
|
Fantasy #10 / 13
|
Anyone happen to know about truth table?
Hmm.... How would i know.....? maybe... i show u guys this... Design a program that evaluates Boolean expressions, based on the following truth table. AND OR NOT XOR IMPLY A B A.B A+B ~A A#B A>B 1 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 0 1 1 1 1 0 0 0 0 1 0 1 The programming allows the user to enter a string containing the expression to be evaluated, e.g. A.B+C. The program will only terminate when the user enters an empty string. Once the expression is entered, it is checked for validity. If there are errors in the expression, error messages must be displayed. Possible errors include, but are not restricted to the following: 1. Unmatched brackets. E.g. A+(B.C 2. Missing operator. E.g. A+BC 3. Missing operand. E.g. A+.C Once it is determined that the expression is valid, prompt the user to enter the values for each operand. Operands can only have values of 0 for false and I for true. After the values of the operands have been established, the expression is evaluated. Note that the order of evaluation is left to right, unless the terms are enclosed in brackets. Terms in brackets have higher priority. The NOT operator is applied on the term on the right. All other operators require a term on the left and on the right. The following is a sample output screen: Enter expression: A+(BC. Parser reports the following error(s): - Unmatched bracket - Missing operator - Missing operand Enter expression: A. ((X.K)+A) Parser reports that the expression is valid. Enter value for A: I Enter value for X: 0 Enter value for K: I The expression has a value of 1 (true) Enter expression: Erm you understand what this question means? I don't.. -- - <-------------------FantasyZ----------------------->
ooO_(_)_Ooo_______________ __|_____|_____|_____|_____|__ _|_Born_|__to__|__be__|_Free__-|
Quote:
> > : The problem is that it is about the third time that guys here tell you > > : that your question is not clearly asked, > > : and you persist to ask it again exactly in the same form. > > From what _I_ understand, FantasyZ wants a program that inputs an > > expression like "A+B.C" and outputs a value that is either 1 or 0. > > Kind of like so:
> > How many variables? 3 > > Value of "A"? 1 > > Value of "B"? 1 > > Value of "C"? 0 > > Enter expression? A+B.C > > The value of "A+B.C" is 1. > * He did not say whether A,B,C were immediate boolean constants > or were symbolic propositional variable. > * In the 2nd case, he did not say if the set and number of variables > was fixed in advance (as you suggested). > * He did not say if a variable name was necessarilily a single letter > * He did not say if he wanted parentheses > * What about priorities of operators ? > * What are + and . > + could be interpreted as 'logical or', 'logical xor'... > * How does he negate a variable: Is there an unary operator ? > etc, etc.
|
Wed, 25 Dec 2002 03:00:00 GMT |
|
|
Joona I Palast #11 / 13
|
Anyone happen to know about truth table?
: Hmm.... How would i know.....? : maybe... i show u guys this... : Design a program that evaluates Boolean expressions, based on the following : truth table. : AND OR NOT XOR IMPLY : A B A.B A+B ~A A#B A>B : 1 1 1 1 0 0 1 : 1 0 0 1 0 1 0 : 0 1 0 1 1 1 1 : 0 0 0 0 1 0 1 : The programming allows the user to enter a string containing the expression : to be evaluated, e.g. A.B+C. The program will only terminate when the user : enters an empty string. : Once the expression is entered, it is checked for validity. If there are : errors in the expression, error messages must be displayed. Possible errors : include, but are not restricted to the following: : 1. Unmatched brackets. E.g. A+(B.C : 2. Missing operator. E.g. A+BC : 3. Missing operand. E.g. A+.C : Once it is determined that the expression is valid, prompt the user to enter : the values for each operand. Operands can only have values of 0 for false : and I for true. After the values of the operands have been established, the : expression is evaluated. Note that the order of evaluation is left to : right, unless the terms are enclosed in brackets. Terms in brackets have : higher priority. The NOT operator is applied on the term on the right. All : other operators require a term on the left and on the right. : The following is a sample output screen: : Enter expression: A+(BC. : Parser reports the following error(s): : - Unmatched bracket : - Missing operator : - Missing operand : Enter expression: A. ((X.K)+A) : Parser reports that the expression is valid. Enter value for A: I : Enter value for X: 0 : Enter value for K: I : The expression has a value of 1 (true) : Enter expression: : Erm you understand what this question means? : I don't.. Yes, I understand what the question means. There is nothing in your entire post that I wouldn't understand. However, I am myself unable to solve the whole problem, as I don't remember the exact algorithm to parse and evaluate an expression. But anyway, the general approach is: You have two stacks, one for operands and one for operators. Each time you encounter an operand (like A, X or K) you put it on the operand stack. Each time you encounter an operator (like + or .) you put it on the operator stack. When evaluating the expression, you take the topmost two operands and the topmost operator. Apply the operator to the operands and put the result back to the operand stack. When the operator stack is empty, the operand stack will contain the value of the expression. Implementing brackets is easiest if you use a recursive function. This means, when you encounter an opening bracket, call the evaluation function from inside the function itself, stopping at the closing bracket. The result is your operand. --
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #80 D+ ADA N+++ | | http://www.helsinki.fi/~palaste W++ B OP+ | \----------------------------------------- Finland rules! ------------/ "In my opinion one of the greatest mathematical breakthroughs would be to find an easy way of factoring large prime numbers." - Bill Gates
|
Wed, 25 Dec 2002 03:00:00 GMT |
|
|
Daniel Waite #12 / 13
|
Anyone happen to know about truth table?
Quote: > Yes, I understand what the question means. There is nothing in your > entire post that I wouldn't understand. However, I am myself unable to > solve the whole problem, as I don't remember the exact algorithm to > parse and evaluate an expression. > But anyway, the general approach is: > You have two stacks, one for operands and one for operators. Each time > you encounter an operand (like A, X or K) you put it on the operand > stack. Each time you encounter an operator (like + or .) you put it on > the operator stack. > When evaluating the expression, you take the topmost two operands and > the topmost operator. Apply the operator to the operands and put the > result back to the operand stack. When the operator stack is empty, the > operand stack will contain the value of the expression. > Implementing brackets is easiest if you use a recursive function. This > means, when you encounter an opening bracket, call the evaluation > function from inside the function itself, stopping at the closing > bracket. The result is your operand. > --
> | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #80 D+ ADA N+++ | > | http://www.helsinki.fi/~palaste W++ B OP+ | > \----------------------------------------- Finland rules! ------------/ > "In my opinion one of the greatest mathematical breakthroughs would be to > find an easy way of factoring large prime numbers." > - Bill Gates
You can also parse the symbols in the expression into a binary tree, also, though that would be harder to debug. -- Daniel Waites Novus Solutions LLC
|
Thu, 26 Dec 2002 03:00:00 GMT |
|
|
|