-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalculatorExample.f90
More file actions
57 lines (50 loc) · 1.63 KB
/
CalculatorExample.f90
File metadata and controls
57 lines (50 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
!
!////////////////////////////////////////////////////////////////////////
!
! CalculatorExample.f90
! Created: August 4, 2014 at 10:36 AM
! By: David Kopriva
!
!////////////////////////////////////////////////////////////////////////
!
SUBROUTINE demonstrateCalculator
USE CalculatorClass
IMPLICIT NONE
TYPE(Calculator) :: calc
CALL calc % init()
!
! ------------------------------
! compute a series of operations
! ------------------------------
!
CALL calc % enter(1.0d0)
CALL calc % enter(2.0d0)
CALL calc % enter("+")
PRINT *, "1 + 2 = ", calc % readDisplay()
CALL calc % enter(2.0d0)
CALL calc % enter("*")
PRINT *, "3 * 2 = ",calc % readDisplay()
CALL calc % enter(2.0d0)
CALL calc % enter("-")
PRINT *, "6 - 2 = ",calc % readDisplay()
CALL calc % enter(4.0d0)
CALL calc % enter("-")
PRINT *, "4 - 4 = ",calc % readDisplay()
!
! ------------------------
! compute 3*(4+2*3)-5 = 25
! ------------------------
!
CALL calc % clear()
CALL calc % enter(2.0d0)
CALL calc % enter(3.0d0)
CALL calc % enter("*")
CALL calc % enter(4.0d0)
CALL calc % enter("+")
CALL calc % enter(3.0d0)
CALL calc % enter("*")
CALL calc % enter(5.0d0)
CALL calc % enter("-")
PRINT *, "3*(4+2*3)-5 = ",calc % readDisplay()
CALL calc % destruct()
END SUBROUTINE demonstrateCalculator