CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2010

    Question Manipulation of Logic clauses using C++

    i need help in evaluation of logical clauses(DNF and CNF) using c++.
    wat i wan is :
    user input a logical clauses as in DNF, then i have to convert it to CNF. and the truth table for both dnf n cnf has to be evaluated.
    input is !(A&&!B) , then i will get !A||B as the conversion result, and a truth table evaluating all the true n false with regard to A and B.
    A B !(A&&!B) !A||B
    1 1 1 1
    1 0 0 0
    0 1 1 1
    0 0 1 1

    i was thinking of getting user input as a line of string but then i do not know wat to do next.perhaps further dissecting the string into smallest component and then evaluate one by one and join them ?
    such as !(A&&!B) , i break it down into evaluate A first, then !B, and then (A AND !B), finaly evaluate !(A AND B)?
    this works for simple clauses. to deal with complicated clauses, a lot of conditions which might seem tedious to do.

    i do not require reply of whole programming code,but a reference would be great. Pls suggest any functions n syntaxes which u think are relavent.
    thx for ur help.

  2. #2
    Join Date
    Apr 2009

    Re: Manipulation of Logic clauses using C++

    1. Get line in memory
    2. Read characters until a space or an operator
    3. If you have found a variable (operand), store its name
    4. If you have found an operator, call a function handling that operation

    You have unary operations (! not) and binary operations (&& and, || or). You can also have parentheses.
    You can build a stack and use a Reverse Polish algorithm.
    Or you can have a recursive approach.

    Good luck to you.

  3. #3
    Join Date
    Jan 2010

    Re: Manipulation of Logic clauses using C++

    hmm a stack, i got another suggestion from other forum on using flex n bison which works similar to stacks.
    ill try to work it out, tq

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.