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

  Building project

This exercise begins with information for a building project. Working in Microsoft Project, you will create the task list, including summary tasks and their sub-tasks, create links between tasks and their predecessors, add resources, and make chan..

  Compute the cost of sorting the relation in seconds

Suppose a flash storage device is used instead of disk, and it has a seek time of 1 microsecond and a transfer rate of 40 MB per second. Recompute the cost of sorting the relation in seconds with.

  Define desk--physical considerations

The help desk is the point at which every frustration, every concern, and every mistake known to humanity is brought for resolution. Typically staffed by lower-level and often new personnel

  Write pseudocode for an iterative algorithm

Write pseudocode for an iterative algorithm that determines a DFS spanning tree for an undirected graph. Base your algorithm on the traversal algorithm dfs.

  Three major information security threats

Write a 1,000- to 1,500-word essay on at least three major information security threats that a specific organization you choose faces today.

  Paper on human-computer interaction

Write a paper which is called Human-computer interaction

  Every programming language have several commonalities

The basics of every programming language have several commonalities

  Designing a program before you create it is beneficial

Why do you think designing a program before you create it is beneficial?

  Given two variables is_empty which is associated with a bool

Given two variables is_empty which is associated with a bool

  Determine the expected number of empty bins

Assume that n balls are tossed into n bins, where each toss is independent and ball is equally likely to end up in any bin. Determine the expected number of empty bins?

  Create a presentation to outline case study requirements

Create a presentation to outline your proposal to meet the case study requirements. Identify the purpose and audience (the Director) for your presentation.

  Finding vertices of polygon stored in array-clockwise order

Assume that n ≥ 3 and the n vertices of P are stored in an array in clockwise order around P. Describe how to determine efficiently whether exactly one of the points q and r falls within P. Analyze the time for your algorithm.

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