Programación Científica: Delphi.
Miércoles 26-3-03
Mauricio Brunet
Paradigmas de la Programación
1º) Ensamblador
2º) Lenguajes de alto nivel. Paradigma procedimental, c, pascal, cobol, pl1.
3º) Orientación a objetos.
Hola mundo en Delphi:
Unit unit1;
procedure tform1.button1click (sender: tobjetct);
begin
showmessage('Hola mundo')
end;
end.
/////////////////
Sumar dos números en delphi.
{+}
begin
edit3.text := IntToStr(StrToInt(edit1.text)+StrToInt(edit2.text))
end;
//////////////////
{Otra forma}
var x, y, z: integer;
begin
x:= StrToInt (edit1.text);
y:= StrToInt (edit2.text);
z:= x+y;
edit3.text := IntToStr(z);
end;
//////////////////////////
boolean pueden ser true o false;
operadores binarios DIV y MOD.
div devuelve el divisor y mod el resto.
por ejemplo: 17 |_3
2 5
17 div 3 = 5
17 mod 3 = 2
x:= x div 5
trunc(); round();
ingresar un número de hasta 3 dígitos, separar unidad decena y centena.
{+}
Var NEntrada, NSalida: integer;
begin
NEntrada := StrToInt (edit1.text);
NSalida := StrToInt (edit2.text);
c:= NEntrada div 100;
modulo:= Nentrada mod 100;
d:= modulo div 10;
u:= modulo mod 10
edit2.text := IntToStr(c) + IntToStr(d) + IntToStr(u);
//////////////////////////
edit2.clear --> para limpiar
ingresar un número entero, efectuar su desglose mediante los valores 100, 50, 25 y 1.
cien:= numero div 100
cincuenta:= (numero-cien) div 50
//////////////////////
Ingresar un importe, aplicarle el iva al 21%
var importe: float
importe := importe * 1,21
Nimporte:= StrToFloat
Salida.text := floatToStr
si multiplico un real * integer que como real o sea float.
0 <> 0,0 --> OJO
///////////////////////
Casillas de verificación:
check box.
checkbox1.checked --> puede ser true o false.
if opcion1.checked then inc(tot);
/////////////
var x: integer;
begin
x:=0;
if ch1.checked then x:= x+1;
if ch2.checked then x:= x+1;
if ch3.checked then x:= x+1;
sal.text:= IntToStr(x)
end;
Proposición compuesta
begin
...
end;
if a > 0 then
begin
..
..
..
end --> Ojo sin ;
else
..
////////////////
RadioButton (selecciono solo uno)
radioButton1.checked (puede ser true o false)
RadioGroup:
Nota: para agregar los botones de opción se debe modificar la propiedad items.
Los items son de tipo TString (es una lista de strings)
ItemIndex --> otra propiedad.
está en -1 si no hay ningún botón seleccionado. 0 es el primero y así siguiendo.
1) Ingresar dos números y una operación elemental, mostrar el resultado.
2) Ingresar un importe, seleccionar forma de pago, informar el descuento según se indica a continuación.
tarjeta 3%
cheque 0%
Efectivo 10%
/////////////////////
1)
{calcular}
begin
case radioGroup1.itemIndex of
0: Es.text:= IntToStr(StrToInt (e1.text) + StrToInt(e2.text));
1: .. -
2: .. *
3: .. div
end
end;
/////////////////
case x of
1,2,5:
8..40:
etc.
para caracteres
succ('A')-> 'B'
pred('B')-> 'A'
ord('A') -> 65
////////////////////
{calcular}
begin
case ri.itemindex of
0: desc.text:=floatToStr(strToFloat(i.text)*0.03;
1: .. * 0;
2: .. 0 0,1;
end
end;
////
a) ingresar 3 números, mostrar el mayor.
for x := 1 to 100 do
begin
..
end;
while x<=20 do
begin
..
end;
repeat
..
until x>3;
b) ingresar N a continuación mostrar los N primeros números de la sucesión de fibonacci.
1,1,2,3,5,8,13,21,34,55,..
c) ingresar un entero calcular su factorial.
c)
{factorial}
nro:= StrToInt(n.text);
tot:=1;
for i :=1 to nro do
begin
tot:= tot*i
end;
total.text:= IntToStr(tot);
a)
{fibonacci}
if n> 2