[Solved] CSc20: Programming Concepts and Methodology II Lab 05

$25

File Name: CSc20:_Programming_Concepts_and_Methodology_II_Lab_05.zip
File Size: 499.26 KB

SKU: [Solved] CSc20: Programming Concepts and Methodology II Lab 05 Category: Tag:
5/5 - (1 vote)

Objective:

The objective of this lab is to get you some experience in using stacks, queues, class packages and UML.

The programming assignment:

In this lab, you are to write an infix evaluator. Given an input string of characters like

12+34*(56-7)-18/9, first print the postfix equivalent 12 34 56 7 * + 18 9 / – and then print the value of the expression.

Notes: In this lab,

  1. You must use the algorithms given in class to convert infix expressions to postfix expressions and to evaluate postfix expressions.
  2. You must use the instructors stack and queue package.
  3. You must use the instructors frame work depicted by the following class diagrams.
  4. Copy directory lab05 from ~wang/sample20.
  5. Complete methods infixToPostfix and evaluatePostfix.

Some programming Hints:

  1. To create a stack:

Stack theStack = new Stack();

  1. To push # into the stack:

theStack.push(new Operator(#));

  1. To create a Tokenizer from a string s:

Tokenizer T = new Tokenizer(s);

  1. Repeat until no more tokens:

While (T.moreTokens()) { ..}

  1. To get the next token:

Token Tkn = T.nextToken();

  1. To pop a token into a variable of the type Token:

Token Current = (Token) theStack.pop();

  1. To cast a Token into an Operator:

Opr = (Operator)Tkn;

  1. To check if a Token variable Tkn contains an Operand:

if (Tkn instanceof Operand)

  1. To check if an operator is a (:

if (Opr.operator==()

  1. To perform an operation:

switch(Opr.operator) { case +: result = opnd1 + opnd2; break;

}

  1. To check the operator on the top of the stack:

((Operator)theStack.top()).operator

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSc20: Programming Concepts and Methodology II Lab 05
$25