Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8805581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:54:12+00:00 2026-06-14T01:54:12+00:00

I am doing my assignment in which I have to modify my previous task

  • 0

I am doing my assignment in which I have to modify my previous task (which is prefix expression tree which takes expression and give result)

+ OR
* AND
- NOT

Now I have to make it Logic expression tree which will perform AND OR and NOT operations

char input;
    cin.get(input);

    if((input == '+')||(input == '-')||(input == '*'))
        {
        p = new ExprTreeNode(input,NULL,NULL);
         buildSub(p->left);
         buildSub(p->right);
      }
      else if(isdigit(input))
        {     //create a new node
            p = new ExprTreeNode(input,NULL,NULL);
        }
        else
      {
        cout <<" invalid expression exiting..." <<endl;
         exit (1);
       }

above code reads expression and makes tree using recursion…

I am confused how I can add unary operator that is NOT…
after that I have to evaluate expression

int answer;
    switch (p->dataItem){

        case '*':
            // AND
        case'+':
            // OR

        case '-':
            // Reverse

        default:
            answer = (p->dataItem-'0');
            break;
    }
    return answer;

p is ExprTreeNode

// Data members
        char dataItem;          // Expression tree data item
        ExprTreeNode *left,     // Pointer to the left child
                     *right;    // Pointer to the right child
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:54:14+00:00Added an answer on June 14, 2026 at 1:54 am

    I’d say you want to do the following:

    if ((input == '+') || (input == '*'))
    {
      p = new ExprTreeNode(input,NULL,NULL);
      buildSub(p->left);
      buildSub(p->right);
    }
    else if (input == '-')
    {
      p = new ExprTreeNode(input, NULL, NULL);
      buildSub(p->left);
    }
    else if(isdigit(input))
    {     //create a new node
      p = new ExprTreeNode(input,NULL,NULL);
    }
    else
    {
      cout <<" invalid expression exiting..." <<endl;
      exit (1);
    }
    

    Edit:
    Then, the evaluation routine could work like this:

    bool ExprTreeNode::evaluate() {
      switch (dataItem) {
        case '+':
          return left->evaluate() || right->evaluate();
        case '*':
          return left->evaluate() && right->evaluate();
        case '-':
          return !left->evaluate();
        case '0':
          return false;
        default:
          return true;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing my javascript assignment in which I have a form and there
I'm doing an assignment for automata theory, which I have to determine whether a
I have an MSP430 Assignment which I'm doing in assembly, and the final part
I have to modify a simple shell I wrote for a previous homework assignment
I'm doing an assignment in which I have to move a simulated robot across
so we're doing this assignment at Uni and i have a serious craving to
So i have an assignment in which i have to make a guessing game
So I am being taught assembly and we have an assignment which is to
A recent homework assignment I have received asks us to take expressions which could
I am doing a little homework assignment in which we are making a very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.