Electrical & Computer Engineering Department, University of Maryland, College Park
Spring 2010
ENEE140
Dr. Gang Qu
Project 2: Integer Arithmetic Expression Evaluator
Posted: Sunday, April 4
Due: Wednesday 11:59 pm, April 21 (no extension)
Project Objective:
1.
get familiar with the process of completing a programming project.
2.
learn to use and manipulate arrays.
3.
understand precedence and associative rules.
4.
use program selection:
if
,
ifelse
,
switch
statements.
5.
use basic loops (
while
,
dowhile
,
for
) for repetition.
6.
command line argument
7.
read from and write into a file
Project Description
:
In this project, you will design and implement a program to evaluate an arithmetic
expression. The arithmetic expression will contain only integers, both positive and negative, and
the five basic binary operators (+, , %, /, *).
Your program should read in the expression from an input file. The input file has a
specific format, which is described below. After reading the expression, you are first going to
evaluate all the unary signs in the expression, next you will evaluate the *, /, % operators, and
finally the binary + and – operators. You will output the initial expression, intermediate steps,
and the final solution to an output file as well as the monitor. A master program, in the format of
executable file, and a sample input file will be provided.
Input
Your program will read in input from a file of multiple lines. Each line represents exactly
one arithmetic expression. The first number of a line is the number of operands in the expression
n
(
2
n
10
). It is followed by
n
operands of integer values, and then
n1
characters (+,,*,/,%)
that represent the operators of the expression. All the numbers and characters are separated by a
single space, and there are no superfluous spaces at the end of each line. Each operator will be
placed between 2 consecutive operands to form the arithmetic operation. As an example, the
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 staff
 Algebra, Addition, Negative and nonnegative numbers, Unary operation, Arity, Dr. Gang Qu

Click to edit the document details