• Olá Visitante, se gosta do forum e pretende contribuir com um donativo para auxiliar nos encargos financeiros inerentes ao alojamento desta plataforma, pode encontrar mais informações sobre os várias formas disponíveis para o fazer no seguinte tópico: leia mais... O seu contributo é importante! Obrigado.

Calculadora

helldanger1

GForum VIP
Entrou
Ago 1, 2007
Mensagens
29,631
Gostos Recebidos
1
Agora nós faremos um programa um pouco mais elaborado. Criaremos uma calculadora com várias funções. No final você perceberá que estarão faltando alguns poucos códigos que ficaram a título de execício para que você os complete. Acreditamos que você já possui condições para tal. Também restaram alguns bugs, cujos consertos deixamos para você. Propositalmente, também deixamos umas poucas linhas de código (na forma de comentários) de algumas tentativas frustradas. Essas também servirão para que você as avalie e descubra onde se encontravam os erros de lógica.



Inicie uma nova aplicação. No diretório de sua preferência salve o Projeto.



Coloque cinco GroupBox, vinte e oito SpeedButton, seis RadioButton, um Label e um ListBox observado a seqüência das propriedades de cada componente e da figura abaixo.
 

helldanger1

GForum VIP
Entrou
Ago 1, 2007
Mensagens
29,631
Gostos Recebidos
1
object Form1: TForm1
Left = 224
Top = 124
Width = 475
Height = 409
Caption = 'Calculadora Básica'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 8
Top = 16
Width = 305
Height = 25
Alignment = taRightJustify
AutoSize = False
Color = clYellow
Font.Charset = ANSI_CHARSET
Font.Color = clRed
Font.Height = -19
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentColor = False
ParentFont = False
end
object GroupBox1: TGroupBox
Left = 8
Top = 96
Width = 137
Height = 201
Caption = 'Valores'
Font.Charset = ANSI_CHARSET
Font.Color = clBlue
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 0
object SpeedButton1: TSpeedButton
Left = 8
Top = 104
Width = 41
Height = 41
Caption = '1'
OnClick = SpeedButton1Click
OnMouseUp = SpeedButton1MouseUp
end
object SpeedButton2: TSpeedButton
Left = 48
Top = 104
Width = 41
Height = 41
Caption = '2'
OnClick = SpeedButton2Click
OnMouseUp = SpeedButton2MouseUp
end
object SpeedButton3: TSpeedButton
Left = 88
Top = 104
Width = 41
Height = 41
Caption = '3'
OnClick = SpeedButton3Click
OnMouseUp = SpeedButton3MouseUp
end
object SpeedButton4: TSpeedButton
Left = 8
Top = 64
Width = 41
Height = 41
Caption = '4'
OnClick = SpeedButton4Click
OnMouseUp = SpeedButton4MouseUp
end
object SpeedButton5: TSpeedButton
Left = 48
Top = 64
Width = 41
Height = 41
Caption = '5'
OnClick = SpeedButton5Click
OnMouseUp = SpeedButton5MouseUp
end
object SpeedButton6: TSpeedButton
Left = 88
Top = 64
Width = 41
Height = 41
Caption = '6'
OnClick = SpeedButton6Click
OnMouseUp = SpeedButton6MouseUp
end
object SpeedButton7: TSpeedButton
Left = 8
Top = 24
Width = 41
Height = 41
Caption = '7'
OnClick = SpeedButton7Click
OnMouseUp = SpeedButton7MouseUp
end
object SpeedButton8: TSpeedButton
Left = 48
Top = 24
Width = 41
Height = 41
Caption = '8'
OnClick = SpeedButton8Click
OnMouseUp = SpeedButton8MouseUp
end
object SpeedButton9: TSpeedButton
Left = 88
Top = 24
Width = 41
Height = 41
Caption = '9'
OnClick = SpeedButton9Click
OnMouseUp = SpeedButton9MouseUp
end
object SpeedButton10: TSpeedButton
Left = 8
Top = 144
Width = 41
Height = 41
Caption = '0'
OnClick = SpeedButton10Click
OnMouseUp = SpeedButton10MouseUp
end
object SpeedButton11: TSpeedButton
Left = 48
Top = 144
Width = 41
Height = 41
Caption = '+/-'
OnClick = SpeedButton11Click
end
object SpeedButton12: TSpeedButton
Left = 88
Top = 144
Width = 41
Height = 41
Caption = ','
OnClick = SpeedButton12Click
end
end
object GroupBox2: TGroupBox
Left = 152
Top = 96
Width = 97
Height = 201
Caption = 'Operação'
Font.Charset = ANSI_CHARSET
Font.Color = clBlue
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 1
object SpeedButton13: TSpeedButton
Left = 8
Top = 24
Width = 41
Height = 41
Caption = '+'
OnClick = SpeedButton13Click
end
object SpeedButton14: TSpeedButton
Left = 8
Top = 64
Width = 41
Height = 41
Caption = '-'
OnClick = SpeedButton14Click
end
object SpeedButton15: TSpeedButton
Left = 8
Top = 104
Width = 41
Height = 41
Caption = 'x'
OnClick = SpeedButton15Click
end
object SpeedButton16: TSpeedButton
Left = 8
Top = 144
Width = 41
Height = 41
Caption = ':'
OnClick = SpeedButton16Click
end
object SpeedButton17: TSpeedButton
Left = 48
Top = 24
Width = 41
Height = 41
Caption = 'raiz'
OnClick = SpeedButton17Click
end
object SpeedButton18: TSpeedButton
Left = 48
Top = 64
Width = 41
Height = 41
Caption = '%'
OnClick = SpeedButton18Click
end
object SpeedButton19: TSpeedButton
Left = 48
Top = 104
Width = 41
Height = 41
Caption = '1/n'
OnClick = SpeedButton19Click
end
object SpeedButton20: TSpeedButton
Left = 48
Top = 144
Width = 41
Height = 41
Caption = '='
OnClick = SpeedButton20Click
end
end
object GroupBox3: TGroupBox
Left = 256
Top = 96
Width = 57
Height = 201
Caption = 'Memória'
Font.Charset = ANSI_CHARSET
Font.Color = clBlue
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 2
object SpeedButton21: TSpeedButton
Left = 8
Top = 24
Width = 41
Height = 41
Caption = 'M clr'
OnClick = SpeedButton21Click
end
object SpeedButton22: TSpeedButton
Left = 8
Top = 64
Width = 41
Height = 41
Caption = 'M rcl'
OnClick = SpeedButton22Click
end
object SpeedButton23: TSpeedButton
Left = 8
Top = 104
Width = 41
Height = 41
Caption = 'M -'
OnClick = SpeedButton23Click
end
object SpeedButton24: TSpeedButton
Left = 8
Top = 144
Width = 41
Height = 41
Caption = 'M +'
OnClick = SpeedButton24Click
end
end
object GroupBox4: TGroupBox
Left = 8
Top = 48
Width = 305
Height = 41
Caption = 'Casas decimais'
Font.Charset = ANSI_CHARSET
Font.Color = clBlue
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 3
object RadioButton1: TRadioButton
Left = 24
Top = 16
Width = 33
Height = 17
Caption = 'A'
TabOrder = 0
end
object RadioButton2: TRadioButton
Left = 64
Top = 16
Width = 33
Height = 17
Caption = 'F'
TabOrder = 1
end
object RadioButton3: TRadioButton
Left = 112
Top = 16
Width = 33
Height = 17
Caption = '2'
TabOrder = 2
OnClick = RadioButton3Click
end
object RadioButton4: TRadioButton
Left = 160
Top = 16
Width = 33
Height = 17
Caption = '4'
TabOrder = 3
OnClick = RadioButton4Click
end
object RadioButton5: TRadioButton
Left = 208
Top = 16
Width = 33
Height = 17
Caption = '6'
TabOrder = 4
OnClick = RadioButton5Click
end
object RadioButton6: TRadioButton
Left = 256
Top = 16
Width = 33
Height = 17
Caption = '8'
TabOrder = 5
end
end
object GroupBox5: TGroupBox
Left = 8
Top = 304
Width = 305
Height = 65
Caption = 'Altera'
Font.Charset = ANSI_CHARSET
Font.Color = clBlue
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 4
object SpeedButton25: TSpeedButton
Left = 8
Top = 16
Width = 65
Height = 41
Caption = 'Novo'
OnClick = SpeedButton25Click
end
object SpeedButton26: TSpeedButton
Left = 80
Top = 16
Width = 65
Height = 41
Caption = 'C'
OnClick = SpeedButton26Click
end
object SpeedButton27: TSpeedButton
Left = 152
Top = 16
Width = 65
Height = 41
Caption = 'CE'
OnClick = SpeedButton27Click
end
object SpeedButton28: TSpeedButton
Left = 224
Top = 16
Width = 73
Height = 41
Caption = '<'
OnClick = SpeedButton28Click
end
end
object ListBox1: TListBox
Left = 328
Top = 16
Width = 129
Height = 353
ItemHeight = 13
TabOrder = 5
end
end
 

helldanger1

GForum VIP
Entrou
Ago 1, 2007
Mensagens
29,631
Gostos Recebidos
1
Calculadora_htm_1e7176bc.gif


Neste exemplo mudamos um pouco o método. Ou seja, não o instruiremos passo a passo. Todavia o código se encontra suficientemente comentado.
 
Topo