Calculadoras 2023



Calculadora con multiples operaciones
En RPN  (Julio 2023)


00 { 364-Byte Prgm }
01▸LBL "Calcula"
02 CLMENU
03 "---------------"
04 AVIEW
05 CLST
06 CLRG
07 FIX 02
08▸LBL 20
09 MENU
10 "1 Nro? "
11 PROMPT
12 STO 01
13 PRX
14▸LBL 10
15 MENU
16 "+"
17 KEY 1 GTO 01
18 "-"
19 KEY 2 GTO 02
20 "*"
21 KEY 3 GTO 03
22 "/"
23 KEY 4 GTO 04
24 "M+"
25 KEY 5 GTO 05
26 "T="
27 KEY 6 GTO 06
28 STOP
29 GTO 10
30▸LBL 00
31 " Nro? "
32 PROMPT
33 STO 02
34 PRX
35 RTN
36▸LBL 01
37 XEQ 00
38 "       +  -----"
39 AVIEW
40 CLA
41 "            "
42 RCL 01
43 RCL 02
44 +
45 STO 01
46 ARCL ST X
47 AVIEW
48 STOP
49 GTO 10
50▸LBL 02
51 XEQ 00
52 "       -  -----"
53 AVIEW
54 CLA
55 "            "
56 RCL 01
57 RCL 02
58 -
59 STO 01
60 ARCL ST X
61 AVIEW
62 STOP
63 GTO 10
64▸LBL 03
65 XEQ 00
66 "       *  -----"
67 AVIEW
68 CLA
69 "            "
70 RCL 01
71 RCL 02
72 ×
73 STO 01
74 ARCL ST X
75 AVIEW
76 STOP
77 GTO 10
78▸LBL 04
79 XEQ 00
80 "       /  -----"
81 AVIEW
82 CLA
83 "            "
84 RCL 01
85 RCL 02
86 ÷
87 STO 01
88 ARCL ST X
89 AVIEW
90 STOP
91 GTO 10
92▸LBL 05
93 "          -----"
94 AVIEW
95 "Parcial="
96 RCL 01
97 STO+ 05
98 ARCL 01
99 AVIEW
100 STOP
101 GTO 20
102▸LBL 06
103 "---------------"
104 AVIEW
105 "Total=  "
106 ARCL 05
107 AVIEW
108 STOP
109 GTO "Calcula"
110 END


El mismo programa en Quick Basic (QB64)  (Agosto 2023)


Usando el archivo calculadora.txt como una impresora digital, al igual que en la HP42S, guardando las operaciones realizadas.
Se ha implementado los decimales redondeados a 2 dígitos y el separador de miles al formato de los números mediante funciones y subrutinas , ya que el Quick Basic no lo trae de origen.

Dim total As Double

Dim number As Double

Dim secondNumber As Double

Dim more As String

Dim moreNumbers As String

Dim operation As String

total = 0

more = "y"


Open "calculadora.txt" For Output As #1 Rem "Abro archivo nuevo  calculadora.txt"
Rem Open calculofile$ For Append As #1 Rem "Abro archivo  calculadora.txt para anadir"


Cls
Screen 12

While more = "y"

    Color 6

    GoSub rectangulo
    GoSub operadores


    Color 7
    Locate 3, 21: Input "N1"; num#
    Cls
    total = round(num#)

    Print #1, "   ";
    a = total
    GoSub formatF

    While operation$ <> "t"
        Color 6
        Locate 1, 5: Print "     "; Chr$(6); " Calculadora "; Chr$(6)

        GoSub rectangulo

        Color 14

        Locate 3, 23: GoSub formato

        GoSub operadores

        Color 7

        Locate 4, 22: Input ""; operation$

        operation$ = LCase$(operation$)





        If operation$ = "+" Then

            Rem sumar

            Color 7
            Locate 5, 20: Input "N2"; secondNumber#
            num = secondNumber#
            secondNumber = round(num)

            Print #1, "+   ";
            a = secondNumber#
            GoSub formatF


            total = total + secondNumber
            num = total#
            total = round(num)


            Color 14
            a = total

            Locate 4, 40: GoSub formato

            Print #1, "  ----"

            a = total
            Print #1, " # ";
            GoSub formatF
            Print #1, ""

            Color 7



        Else

            If operation$ = "-" Then

                Rem Resta


                Color 7
                Locate 5, 20: Input "N2"; secondNumber#
                num = secondNumber#
                secondNumber = round(num)

                Print #1, "-   ";
                a = secondNumber#
                GoSub formatF


                total = total - secondNumber
                num = total#
                total = round(num)


                Color 14
                a = total

                Locate 4, 40: GoSub formato

                Print #1, "  ----"

                a = total
                Print #1, " # ";
                GoSub formatF
                Print #1, ""

                Color 7

            Else

                If operation$ = "*" Then

                    Rem multiplicacion


                    Color 7
                    Locate 5, 20: Input "N2"; secondNumber#

                    num = secondNumber#
                    secondNumber = round(num)

                    Print #1, "*   ";
                    a = secondNumber#
                    GoSub formatF


                    total# = secondNumber * total
                    num = total#
                    If num > 10000000 Then total = 0
                    If num < 10000000 Then total = round(num)
                    If total = 0 Then Locate 4, 40: Print "limite"

                    Rem * multiplicacion

                    Color 14

                    a = total
                    Locate 4, 40: GoSub formato

                    If total = 0 Then Locate 4, 40: Print "limite Exc"

                    Print #1, "  ----"

                    a = total
                    Print #1, " # ";
                    GoSub formatF
                    Print #1, ""

                    Color 7

                Else

                    If operation$ = "/" Then

                        Rem division


                        Color 7
                        Locate 5, 20: Input "N2"; secondNumber#

                        num = secondNumber#
                        secondNumber = round(num)

                        Print #1, "/   ";
                        a = secondNumber#
                        GoSub formatF


                        If secondNumber = 0 Then

                            Color 4

                            Locate 7, 5: Print "No se puede dividir por 0"

                            Color 7

                        Else

                            total# = total / secondNumber
                            num = total#
                            total = round(num)



                            Rem / division

                        End If
                        a = total
                        Color 14
                        If secondNumber = 0 Then Locate 4, 40: Print "  "; 0
                        If secondNumber > 0 Then Locate 4, 40: GoSub formato


                        Print #1, "  ----"

                        a = total
                        Print #1, " # ";
                        GoSub formatF
                        Print #1, ""



                        Color 7

                    Else

                        5
                        If operation$ <> "t" Then Locate 7, 5: Print "debes seleccionar una operacion"

                    End If

                End If

            End If

        End If



        Sleep 1

        Cls

    Wend

    Color 6


    GoSub rectangulo
    GoSub operadores


    Color 12

    Locate 3, 40: Print "Total= "
    Locate 4, 40: GoSub formato

    Print #1, "  -----------"

    a = total
    Print #1, " Total= ";
    GoSub formatF
    Print #1, "  -----------"


    Color 7

    Locate 7, 6: Input "Nueva operacion (y - n)"; more
    Cls
    operation$ = ""
    moreNumbers = ""


    total = 0

    Rem Si no resteamos el total a 0

    Rem seguiremos sumadolo

Wend


Close #1


End

operadores:
Color 12
Locate 1, 5: Print "     "; Chr$(6); " Calculadora "; Chr$(6)
Color 7
Locate 4, 6: Print "(T)"
Color 12
Locate 4, 9: Print "(+)"

Locate 4, 12: Print "(-)"
Locate 4, 15: Print "(*)"
Locate 4, 18: Print "(/)"
Return



rectangulo:
Rem dibuja rectangulo
p1 = 20
p2 = 30
p3 = 90
p4 = 300
Line (p2, p1)-(p4, p1), 7
Line (p2, p3)-(p4, p3), 7
Line (p2, p1)-(p2, p3), 7
Line (p4, p1)-(p4, p3), 7


p1 = 20
p2 = 300
p3 = 90
p4 = 430
Line (p2, p1)-(p4, p1), 7
Line (p2, p3)-(p4, p3), 7
Line (p2, p1)-(p2, p3), 7
Line (p4, p1)-(p4, p3), 7

Return

formato: Rem subrutina que implementa los separadores de miles


If a <= 9999 Then GoTo fin1
If a <= 99999 Then GoTo fin2
If a <= 999999 Then GoTo fin3
If a <= 9999999 Then GoTo fin4
If a <= 99999999 Then GoTo fin5

fin1:
Print Using "#,###.##"; a
Return

fin2:
Print Using "##,###.##"; a
Return

fin3:
Print Using "###,###.##"; a
Return

fin4:
Print Using "#,###,###.##"; a
Return

fin5:
Print Using "##,###,###.##"; a
Return

formatF: Rem subrutina que implementa los separadores de miles en un archivo


If a <= 999 Then GoTo fn0
If a <= 9999 Then GoTo fn1
If a <= 99999 Then GoTo fn2
If a <= 999999 Then GoTo fn3
If a <= 9999999 Then GoTo fn4
If a <= 99999999 Then GoTo fn5

fn0:
Print #1, Using "###.##"; a
Return


fn1:
Print #1, Using "#,###.##"; a
Return

fn2:
Print #1, Using "##,###.##"; a
Return

fn3:
Print #1, Using "###,###.##"; a
Return

fn4:
Print #1, Using "#,###,###.##"; a
Return

fn5:
Print #1, Using "##,###,###.##"; a
Return


Function round# (num As Double) Rem funcion que  redondea a 2 los decimales
    'WARNING: USE "#" at the end of constant values,
    'or else you will get rounding errors:
    ' "num = .45"  >> "num = .449999988079071
    ' "num = .45#" >> "num = .45"
    dp = 2
    Dim exp1 As Long, num2 As Long
    exp1 = 10 ^ dp: num2 = num * exp1: round# = num2 / exp1

End Function

La función round redondea a dos los decimales de un número. (dp=2)



 
Calculadora Simple  (2021)

00 { 217-Byte Prgm }

01▸LBL "OPERA"

02 CLMENU

03 CLST

04 MENU

05 "1 Nro?"

06 PROMPT

07 STO 01

08 PRX

09 "2 Nro?"

10 PROMPT

11 STO 02

12 PRX

13 "+"

14 KEY 1 GTO 01

15 "-"

16 KEY 2 GTO 02

17 "*"

18 KEY 3 GTO 03

19 "/"

20 KEY 4 GTO 04

21 STOP

22 GTO "OPERA"

23▸LBL 01

24 "         +   "

25 RCL 01

26 RCL 02

27 +

28 ARCL ST X

29 ├"    ***"

30 AVIEW

31 STOP

32 GTO "OPERA"

33▸LBL 02

34 "         -   "

35 RCL 01

36 RCL 02

37 -

38 ARCL ST X

39 ├"    ***"

40 AVIEW

41 STOP

42 GTO "OPERA"

43▸LBL 03

44 "         *  "

45 RCL 01

46 RCL 02

47 ×

48 ARCL ST X

49 ├"   ***"

50 AVIEW

51 STOP

52 GTO "OPERA"

53▸LBL 04

54 "         /   "

55 RCL 01

56 RCL 02

57 ÷

58 ARCL ST X

59 ├"   ***"

60 AVIEW

61 STOP

62 GTO "OPERA"

63 END


El mismo programa en Quick Basic (QB64) (2022)




Cls Dim X As Double Dim O As String Dim Y As Double ENTER: Input "1 Numero"; X Input "Operacion (+, -, *, /)"; O Input "2 Numero"; Y If O = "+" Then Print X; "+"; Y; "=", X + Y ElseIf O = "-" Then Print X; "-"; Y; "=", X - Y ElseIf O = "*" Then Print X; "*"; Y; "=", X * Y ElseIf O = "/" Then Print X; "/"; Y; "=", X / Y Else Print "Incorrecto" End If GoTo ENTER




Otro Ejemplo de calculadora (2022)

Dim A, B, RESULT As Single, OP As String

ENTER:
Input "Nro:", A
Input "Nro:", B
Input "+ - *  / : ", OP

Select Case OP
    Case Is = "+"
        Print " SUMA "
        RESULT = A + B
        Print "RESULT = "; RESULT
    Case Is = "-"
        Print " RESTA "
        RESULT = A - B
        Print "RESULT = "; RESULT

    Case Is = "*"

        Print " MULTIPLICACION "
        RESULT = A * B
        Print "RESULT = "; RESULT

    Case Is = "/"

        Print " DIVISION "
        RESULT = A / B
        Print "RESULT = "; RESULT

    Case Else

        Print "INVALID OPERATOR "

End Select
GoTo ENTER
End




Calculadora simple usando las Funciones (2022)

Cls

Dim a As Double

Dim O As String

Dim b As Double

ENTER:

Input "1 Numero"; a

Input "Operacion (+, -, *, /)"; O

Input "2 Numero"; b



If O = "+" Then
    Print a; "+"; b; "=", suma(a, b)

ElseIf O = "-" Then
    Print a; "-"; b; "=", resta(a, b)

ElseIf O = "*" Then
    Print a; "*"; b; "=", multi(a, b)

ElseIf O = "/" Then
    Print a; "/"; b; "=", divide(a, b)

Else

    Print "Incorrecto"

End If

GoTo ENTER


Function suma (a, b)
    suma = a + b
End Function

Function multi (a, b)
    multi = a * b
End Function

Function resta (a, b)
    resta = a - b
End Function

Function divide (a, b)
    divide = a / b
End Function