Method named eval that evaluates a non-empty expression tree

Assignment Help Basic Computer Science
Reference no: EM13819406

Programming Project: Expression Trees

This project is adapted from Project 1 of Chapter 9 of the textbook. It deals with a simple kind of expression trees, in which there are two kinds of nodes:

(a) Leaf nodes, which contain a real number as their clement; and

(b) Non-leaf nodes, which have exactly two children and contain one of these characters as their element: +, -, * and /. These characters represent arithmetic operations and have usual interpretations.

Implement a class for expression trees with these operations:

(a) A constructor that builds an expression tree. It accepts a String that represents a grammatically correct expression as its sole input. Hint: refer to a previous assignment on evaluating expressions.

(b) A recursive method named eval that evaluates a non-empty expression tree using these rules:

i. If the tree has only one node (which must be a leaf), then eval returns the real number that is the node's clement;

ii. If the tree has more than one node and the root contains op where op is one of +, -, * and /, then eval first evaluates the sub-trees of the root and returns the real number obtained by performing operation op on the results from evaluating the sub-trees.

(c) A recursive method named infix that output the expression represented by a non-empty expression tree to a String in infix format.

(d) A recursive method named postfix that outputs the expression represented by a non-empty expression tree in postfix format.

You also need to write another class that applies the operations of the above class.

Please submit

1. Analysis: test data;
2. Design:

  • A class invariant for each class;
  • Pre/Post conditions for required operations;
  • Algorithms for required operations.

3. Code;
4. Screen snapshots of test runs. 

Reference no: EM13819406

Questions Cloud

What purposes do visual aids serve : What purposes do visual aids serve? Why are they critical for both local and international audiences? How do you keep your audience engaged?
Estimated the amount of cash needed to start the business : Thoroughly suggested at least three (3) strategies to incentivize the founding management team. Thoroughly estimated the amount of cash needed to start the business. Provide a rationale to support your estimation
Plumbing to replace the bathtubs and ?xtures : Mechanic’s Lien. Grant is the owner of a relatively old home valued at $45,000. He notices that the bathtubs and ?xtures in both bathrooms are leaking and need to be replaced. He contracts with Jane’s Plumbing to replace the bathtubs and ?xtures. Jan..
Question regarding the various allocation methods : From your text and at least one scholarly source, describe how service center costs are allocated using the various allocation methods.
Method named eval that evaluates a non-empty expression tree : Implement a class for expression trees with these operations: (a) A constructor that builds an expression tree. It accepts a String that represents a grammatically correct expression as its sole input. Hint: refer to a previous assignment on evaluati..
Identify the business actors : Identify the business actors
Inventory management problem : Select an inventory management problem that applies to your work or personal life.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  What is the current size of q

Suppose an initially-empty queue Q has performed a total of 32 enqueue operations, 10 front operations, and 15 dequeue operations, 5 of which generated QueueEmptyExceptions, which were caught and ignored. What is the current size of Q?

  Understanding of storage classes and scope rules

It amounts to a "divide and conquer" approach to problem solving. This needs sound understanding of storage classes and scope rules. Response and or thoughts?

  Ethernet used for enterprise access

Ethernet used for Enterprise Access

  Discuss whether you accept demand from manager

Discuss whether you should accept this demand from your manager or whether you should persuade your team to give their time to the organization rather than to their families. What factors might be significant in your decision?

  Windows active directory

A research paper on Windows Active Directory and User Access Controls with some additional info about Group Policy Objects and Microsoft Baseline Security Analyzer.

  How many different committee choices are possible

A committee of 5 people must be chosen from a group of 7 men and 9 women. If the committee is required to have at least 1 woman, how many different committee choices are possible?

  Describe the purpose of a risk assessment risk scope and id

1. Describe the purpose of a risk assessment , risk scope and identify critical areas for an assessment. 2. Select risk assessment methodology and give your rationale behind the one you chose

  Use matlab to write a function function

The users input the function of their choice and fRotate plots the function within the given interval and its rotated version on the same figure window. Please attach graph.

  Ipv6-compliance mandates to help with the ipv4-to-ipv6

The U.S. government has put in place IPv6-compliance mandates to help with the IPv4-to-IPv6 transition. Such mandates require government agencies to have their websites, email and other services available over IPv6.

  Message exchange patterns in soap

Let two main types of message exchange patterns in SOAP (and operation types in WSDL): (1) request-response and (2) one-way.

  Process of preparing the truth table

After the fourth clock pulse, the machine has to be again in the reset state, ready for the next sequence. Minimize the number of states needed.

  Describe the disadvantages of any solution employed

ABC Institute of Research has sensitive information that needs to be protected from its rivals. The Institute has collaborated with XYZ Inc. to research genetics. The information must be kept top secret at any cost.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd