Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE proceduraltype;
- //Procedural data type, basic exercise with 2 operations
- FROM InOut IMPORT WriteString, WriteLn, Read;
- FROM RealInOut IMPORT WriteReal, ReadReal;
- VAR
- operation: PROCEDURE(REAL, REAL): REAL;
- nm1, nm2, result : REAL;
- smb : CHAR;
- again : BOOLEAN;
- PROCEDURE addition(nmb1, nmb2: REAL): REAL;
- VAR
- result : REAL;
- BEGIN
- result := nmb1 + nmb2;
- RETURN result
- END addition;
- PROCEDURE subtraction(nmb1, nmb2: REAL): REAL;
- VAR
- result : REAL;
- BEGIN
- result := nmb1 - nmb2;
- RETURN result
- END subtraction;
- BEGIN
- WriteString('Enter first number: ');
- ReadReal(nm1);
- WriteLn;
- WriteString('Enter second number: ');
- ReadReal(nm2);
- WriteLn;
- WriteString('Enter the operation(+ OR -) :');
- again := FALSE;
- REPEAT
- IF again THEN
- WriteString('Enter again, the operation must be + OR -! : ');
- WriteLn;
- END;
- Read(smb);
- WriteLn;
- again := TRUE;
- UNTIL (smb = '+') OR (smb = '-');
- CASE smb OF
- '+' : operation := addition|
- '-' : operation := subtraction
- END;
- result := operation(nm1,nm2);
- WriteLn;
- WriteString('Result is: ');
- WriteReal(result,0);
- WriteLn;
- END proceduraltype.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement