CSCE 2050: Infix to Postfix & Evaluating Arithmetic, Assignments of Computer Science

The requirements for programming assignment 3 of csce 2050, a university-level course in computer science. Students are tasked with creating a program that translates infix arithmetic expressions to postfix notation, prints the postfix form, evaluates the expression using the postfix form, and prints the evaluation. The expressions consist of non-negative integers, parentheses, and arithmetic operators. Specifications for the input format, output format, error handling, and testing. Students are expected to use a c++ class to maintain stacks and another class to maintain lists, and they must submit their source code and a makefile or script file for compilation and testing.

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-20q
koofers-user-20q 🇺🇸

5

(1)

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCE 2050
Programming Assignment 3
Fall 2006
Due Date: Friday, Nov. 10
Requirements [Lists and Stacks.]
Read from the input stream an (infix) arithmetic expression composed of
Nonnegative integers: 0, 1, 2, etc.
Parentheses: ( and )
Arithmetic operators: +, -, *, /, ^, and = (albeit, the token = will not appear in any test cases
here)
A semicolon will be used to denote the end of the expression. Expressions are the same as in the last
assignment except operands will only be positive integers (no variables) and thus no assignments (use
of =).
Translate the expression to an internal code, construct the postfix, print the postfix, evaluate the
expression using the postfix, then print the evaluation.
Specifications The input should appear as follows:
Please enter an arithmetic expression
15*(3+2)-10;
The output should appear as follows:
The expression you entered was
15*(3+2)-10
The postfix form is
1532+*10-
Its evaluation is
65
If the expression does not have balanced parentheses, an error message should be printed, the stack(s)
should be made empty, and the program proceed to the next expression.
AC+ + class must be used to maintain stacks. Appropriate member operators must be provided so
the stacks can be manipulated. It is recommended but not required that yet another class be used to
maintain lists.
The signal to stop and exit will be the empty expression (an expression consisting only of a semi-colon).
Design and Testing Use the following test cases. You may use additional ones.
15 * (3 + 2) - 10;
(3 + 2)^2/5;
((3 + 2)^2/5;
(3 + 2))^2/5;
(120 - 110 / 10 * 10 - 9)^(2*3 - 6);
Error Handling Error checking must at least include assuring the next input symbol is a legitimate token
and that the parentheses of the expression are in balance.
pf2

Partial preview of the text

Download CSCE 2050: Infix to Postfix & Evaluating Arithmetic and more Assignments Computer Science in PDF only on Docsity!

CSCE 2050

Programming Assignment 3

Fall 2006

Due Date: Friday, Nov. 10

Requirements [Lists and Stacks.]

Read from the input stream an (infix) arithmetic expression composed of

  • Nonnegative integers: 0, 1, 2, etc.
  • Parentheses: ( and )
  • Arithmetic operators: +, -, *, /, ^, and = (albeit, the token = will not appear in any test cases here)

A semicolon will be used to denote the end of the expression. Expressions are the same as in the last assignment except operands will only be positive integers (no variables) and thus no assignments (use of =). Translate the expression to an internal code, construct the postfix, print the postfix, evaluate the expression using the postfix, then print the evaluation.

Specifications The input should appear as follows:

Please enter an arithmetic expression 15 * (3 + 2) - 10;

The output should appear as follows:

The expression you entered was 15 * (3 + 2) - 10 The postfix form is 15 3 2 + * 10 - Its evaluation is 65

If the expression does not have balanced parentheses, an error message should be printed, the stack(s) should be made empty, and the program proceed to the next expression. A C + + class must be used to maintain stacks. Appropriate member operators must be provided so the stacks can be manipulated. It is recommended but not required that yet another class be used to maintain lists. The signal to stop and exit will be the empty expression (an expression consisting only of a semi-colon).

Design and Testing Use the following test cases. You may use additional ones.

15 * (3 + 2) - 10; (3 + 2)^2/5; ((3 + 2)^2/5; (3 + 2))^2/5; (120 - 110 / 10 * 10 - 9)^(2*3 - 6);

Error Handling Error checking must at least include assuring the next input symbol is a legitimate token and that the parentheses of the expression are in balance.

Implementation Due Date Friday, 10 November. Submit the following using the project command. Select the correct section of the class, 2050s001. The project id is phw2.

  • The source code (i.e., the *.h and *.cpp files)
  • Either of the following
    • A makefile that compiles the code and executes the test cases
    • A text file created using the “script” command that shows execution of the test cases