Calculator Assignment 3 Programming Language Spring 2003 Specification
- Slides: 8
Calculator Assignment #3 Programming Language, Spring 2003
Specification (1) • Calculator Application. – – Only integer arithmetic The operations are addition, subtraction and multiplication Use an arbitrary number of variables whose names are A, B, C, D, E. Main way of doing calculations • To type in a few formulas and to assign them to variables • Some formulas are complicated expressions, which can refer to yet undefined variables, while other formulas consist of a single number • Then asks for the value of some variables – Redefine some variables and then to reevaluate formulas that depend on these variables
Specification (2) • Arithmetic – Assignment • var : = expression – Print • PRINT var – Reset • RESET
Assignment • Objectives – Implement calculator • Input a few formulas and etc. • Then answer the value of some variables asked for • For each ``PRINT'' statement found in the input file – Output a line containing the numerical value of the specified variable – Or the word ``UNDEF'' if the variable is undefined
Input Convention • Input file – Contain a few formulas and etc. – Example • • • A : = B + C B : = 3 C : = 5 PRINT D PRINT A B : = 8 PRINT A RESET A : = 1 + ( 2 + ( 3 + ( 4 + 5 * 6 ) * 7 ) * 8 ) PRINT B
Output Convention • Output file – For each ``PRINT'' statement found in the input file • Output a line containing the numerical value of the specified variable • Or the word ``UNDEF'' if the variable is undefined – Example • • UNDEF 8 13 UNDEF
Source Code • calculator. scm – Input formulas and etc. • calculator. in – Output value of the specified variable • calculator. out
Spec. • Assignment Spec. – System • Unix – Language • Scheme (MIT Scheme)