1. Write a program in the EXE format. 2. The program should contain the followin
ID: 673483 • Letter: 1
Question
1. Write a program in the EXE format.
2. The program should contain the following procedures:
a. INPUT: Reads the arithmetic expression and checks for its validity.
b. OPERATE: This is not the actual name of the functions. You should write separate procedures for each possible operator, e.g. DO_ADDITION, DO_SUBTRACTION, etc. Each of these functions performs the desired operation.
c. OUTPUT: Converts the result to ASCII code and display it on the screen.
d. CONV_ASCII2HEX: Performs data type conversion from ASCII to hexadecimal. Refer to your textbook for more details on ASCII codes.
e. CONV_HEX2ASCII: Performs data type conversion from hexadecimal to ASCII. f. ERROR: Prints out different error messages for illegal operators and operands.
3. All the input operands must be handled as signed decimal numbers in the range [-32,768 to +32,767]. The results must be at least twice as long as the inputs (not twice the range). For the division, only the quotient should be displayed.
4. Extra credit: to make the program more user friendly, you may design a loop and ask the user if he/she wants to input another algebraic command.
Explanation / Answer
Enter an algebraic command line:
5 + 2 <enter>
Result: 7
Again? Y
Enter an algebraic command line:
2 + 2 <enter>
Result: 4
Again? Y <enter>
Enter an algebraic command line:
5 - 2 <enter>
Result: 3
Again? Y <enter>
Enter an algebraic command line:
2 - 4 <enter>
Result: -2
Again? Y <enter>
Enter an algebraic command line:
255 <enter>
Error!!
Input format: Operand1 Operator Operand2
Operand: decimal numbers
Operator: + -
Again? Y <enter>
Enter an algebraic command line:
255 / 9 + 1 <enter>
Error!!
Input format: Operand1 Operator Operand2
Operand: decimal numbers
Operator: + -
Again? Y <enter>
Enter an algebraic command line:
A / 9 <enter>
Error!!
Input format: Operand1 Operator Operand2
Operand: decimal numbers
Operator: + -
Again? N <enter>
C:>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.