Calculadora

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Calculadora as PDF for free.

More details

  • Words: 656
  • Pages: 12
Logoapp.dpr

“Calculad ora”

Vista de la calculadora.

2

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; // 1 Button2: TButton; // 2 Button3: TButton; // 3 Button4: TButton; // 4 Button5: TButton; // 5 Button6: TButton; // 6 Button7: TButton; // 7 Button8: TButton; // 8 Button9: TButton; // 9 Button10: TButton; // 0 Button11: TButton; // C Button12: TButton; // = Button13: TButton; // + Button14: TButton; // Button15: TButton; // * Button16: TButton; // / Button17: TButton; // Salir Button18: TButton; // , Edit1: TEdit; procedure Button10Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button9Click(Sender: TObject); procedure Button13Click(Sender: TObject); procedure Button14Click(Sender: TObject); procedure Button15Click(Sender: TObject); procedure Button16Click(Sender: TObject); procedure Button11Click(Sender: TObject); procedure Button12Click(Sender: TObject); procedure Button17Click(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure Button18Click(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char);

3

procedure FormActivate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; R1,N1,N2:Real; Op:String; implementation uses StrUtils; {$R *.dfm}

procedure TForm1.Button10Click(Sender: TObject);

// 0

begin if Edit1.text='0' then Edit1.text:='0' Else Edit1.text:=Edit1.text+'0'; Edit1.setfocus; end;

procedure TForm1.Button1Click(Sender: TObject);

// 1

begin if Edit1.text='0' then Edit1.text:='1' Else Edit1.text:=Edit1.text+'1'; Edit1.setfocus; end;

4

procedure TForm1.Button2Click(Sender: TObject); begin if Edit1.text='0'

// 2

then Edit1.text:='2' Else Edit1.text:=Edit1.text+'2'; Edit1.setfocus;

end;

procedure TForm1.Button3Click(Sender: TObject); begin if Edit1.text='0'

// 3

then Edit1.text:='3' Else Edit1.text:=Edit1.text+'3'; Edit1.setfocus;

end;

procedure TForm1.Button4Click(Sender: TObject); begin if Edit1.text='0' then Edit1.text:='4' Else Edit1.text:=Edit1.text+'4'; Edit1.setfocus; end;

// 4

procedure TForm1.Button5Click(Sender: TObject);

// 5

begin if Edit1.text='0'

then Edit1.text:='5' Else Edit1.text:=Edit1.text+'5'; Edit1.setfocus;

end;

5

procedure TForm1.Button6Click(Sender: TObject); begin if Edit1.text='0'

// 6

then Edit1.text:='6' Else Edit1.text:=Edit1.text+'6'; Edit1.setfocus;

end;

procedure TForm1.Button7Click(Sender: TObject);

// 7

begin if Edit1.text='0' then Edit1.text:='7' Else Edit1.text:=Edit1.text+'7'; Edit1.setfocus; end;

procedure TForm1.Button8Click(Sender: TObject); begin if Edit1.text='0' then Edit1.text:='8' Else Edit1.text:=Edit1.text+'8'; Edit1.setfocus; end;

procedure TForm1.Button9Click(Sender: TObject);

// 8

// 9

begin if Edit1.text='0' then Edit1.text:='9' Else Edit1.text:=Edit1.text+'9'; Edit1.setfocus; end;

6

procedure TForm1.Button18Click(Sender: TObject); begin if edit1.text='0'

//

,

then edit1.Text:='0,' else edit1.Text:=edit1.Text+','; Edit1.setfocus;

end;

procedure TForm1.Button13Click(Sender: TObject);

// suma

begin N1:=strtofloat(Edit1.text); Op:='+'; Edit1.text:='0'; Edit1.setfocus; end;

procedure TForm1.Button14Click(Sender: TObject);

// resta

begin N1:=strtofloat(Edit1.text); Op:='-' ; Edit1.text:='0'; Edit1.setfocus; end;

7

procedure TForm1.Button15Click(Sender: TObject);

// multiplicacion

begin N1:=strtofloat(Edit1.text); Op:='*'; Edit1.text:='0'; Edit1.setfocus; end;

procedure TForm1.Button16Click(Sender: TObject);

// Division

begin N1:=strtofloat(Edit1.text); Op:='/'; Edit1.text:='0'; Edit1.setfocus; end;

procedure TForm1.Button11Click(Sender: TObject);

// borrar

begin Edit1.text:='0'; R1:=0; Edit1.setfocus; end;

8

procedure TForm1.Button12Click(Sender: TObject); begin if Op='+' then

// calcular

begin N2:=strtofloat(Edit1.text); R1:=N1+N2; Edit1.text:=floattostr(R1); End

Else if Op= '-'

then

begin N2:=strtofloat(Edit1.text); R1:=N1-N2; Edit1.text:=floattostr(R1); End

then

begin N2:=strtofloat(Edit1.text); R1:=N1 * N2; Edit1.text:=floattostr(R1); End

else if Op= '*'

else if

Op= '/' then if edit1.text='0'

then showmessage('Error')

else begin N2:=strtofloat(Edit1.text); R1:=N1/N2; Edit1.text:=floattostr(R1); Edit1.setfocus; end ;

end;

9

procedure TForm1.Button17Click(Sender: TObject);

// Salir

begin close; end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin if application.MessageBox('Desea cerrar la calculadora?','Cerrando programa',mb_yesno+mb_iconquestion)=id_yes then CanClose:=true else CanClose:=false;

el

end;

procedure TForm1.FormActivate(Sender: TObject);

// Focus de Windows

begin edit1.SetFocus; end;

10

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);

// Teclado

begin if not (key in ['0'..'9',#46, #8]) then if key = #43

then

// +

begin Op : = '+' ; key:=#0; N1:=strtofloat(edit1.Text); edit1.Text:= '' ; end ; if key = #45

then

// -

begin Op : = '-' ; Key : = #0 ; N1 : = strtofloat(edit1.Text); edit1.Text : = '' ; end ;

if key = #42

then

// *

begin Op : = '*' ; Key : = #0 ; N1 : = strtofloat(edit1.Text); edit1.Text : = '' ; end ;

if key = #47

then

// /

begin Op : = '/' ; Key : = #0 ; N1 : = strtofloat(edit1.Text); edit1.Text : = '' ; end;

11

if key = #46 then // Decimales Begin Key : = #0 ; Key : = #44 ; end;

if

key = #8 then

// Borrar

edit1.Text : = '' ; end ; end .

12

Related Documents

Calculadora
October 2019 56
Calculadora
November 2019 36
Calculadora
August 2019 49
Calculadora
November 2019 50
Calculadora
November 2019 28
Calculadora
November 2019 44