Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a program in the EXE format. 2. The program should contain the followin

ID: 3760978 • 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.

SAMPE EXECUTION: Assume the executable filename is CALC.EXE

Enter an algebraic command line: -255 / 2

Result: -127

Again? Y <enter>

Enter an algebraic command line: 255 Error!!

Input format: Operand1 Operator Operand2

Operand: decimal numbers

Operator: + - * / %

Again? N <enter>

Explanation / Answer

#include #include void main() { float n1, n2; int ch; clrscr(); printf("Enter the first number : ") ; scanf("%f", &n1) ; printf(" Enter the second number : ") ; scanf("%f", &n2) ; printf(" [1] -> Addition ") ; printf(" [2] -> Subtraction ") ; printf(" [3] -> Multiplication ") ; printf(" [4] -> Division ") ; printf(" Enter your choice : ") ; scanf("%d", &ch) ; switch(ch) { case 1 : printf(" %f + %f = %f", n1, n2, n1 + n2) ; break ; case 2 : printf(" %f - %f = %f", n1, n2, n1 - n2) ; break ; case 3 : printf(" %f * %f = %f", n1, n2, n1 * n2); break ; case 4 : printf(" %f / %f = %.2f", n1, n2, (float)n1 / n2); break ; default : printf(" Invalid choice"); break ; } getch(); }