You are on page 1of 15

UNIVERSIDAD

Ao de la
Diversificacin

NACIONAL

DEL SANTA
FACULTAD DE INGENIERIA
E.A.P. INGENIERA DE SISTEMAS E INFORMTICA

ALUMNA:
Sandoval Ramirez Jennifer
CODIGO:
0201314052
TEMA:
Funciones en Power Builder
CURSO:
Computacin II
PROFESOR:
Briones Pereyra Lizbeth

Nuevo Chimbote, 29 de Setiembre del 2015

EJERCICIOS CON FUNCIONES DEFINIDOS POR EL USUARIO EN POWER


BUILDER

Ejemplo 1.
Escribir una funcin llamado max3 que reciba tres nmeros enteros
(A, B y C) y devuelva el mayor de ellos. (VER PAG. 40 DE SU SESION
04.)

PROCEDIMIENTO:
Primero se tiene que crear una funcin dentro del
Windows es decir de (w_funciones), nos vamos a
functions
y damos click en la opcin
classname() returns string nos va abrir un

cuadro como esta imagen:

y comenzamos la funcin su nombre ser maximo3 luego en


argumentos de nombre podremos A, B, C. luego en el script se
codifica lo siguiente:
integer max1, mximo

max1=max(a,b)
maximo= max(max1, c)
return maximo
Luego compilamos y guardamos. Listo esta creada la funcin.
Posteriormente pasamos a codificar:

Numero1: sle_1.text
Numero2: sle_2.text
Numero3: sle_3.text
Numero mximo: sle_4.text, aqu saldr el resultado
cb_1 lo cual sabemos es un botn en la que hemos codificado
lo siguiente:
integer a,b,c
dec max
string mensaje
a= integer(sle_1.text)
b= integer(sle_2.text)
c= integer(sle_4.text)
// Llamamos a la funcin que habamos creado y los
datos con la cual ejecutar ser con los cuadro de texto
es decir los datos ingresados en numero1, numero2,
numero3.
max = maximo3(a,b,c)
sle_3.text = string (max)

Ejemplo 2.Disear una funcin que permita obtener el promedio de


las dos mejores notas de tres ingresados. Adems debe devolver la
condicin (aprobado o desaprobado). (VER PAG. 44 DE SU SESION 04.)

Primero
creamos las funciones:

Funcin condicin:
string nCar
if nProm<=10 then
nCar = "desaprobado"
else
if nProm>=11 then
nCar = "Aprobado"
else
nCar = "asistencia"
end if
end if
return (nCar)
Funcin promedio:
dec nvar1, nvar2, nMin, nProm
nvar1=Min(nota1,nota2)
nvar2=Min(nota3,nota4)
nMin=Min(nota1,nota2)

nProm=((nota1+nota2+nota3+nota4)-nMin)/3
return (nProm)

Luego codificamos:
En el botn correcto:
integer nNota1, nNota2, nNota3, nNota4, nExa
dec nPromedioP, nPromedioG
string cMensaje
Evento Open
nNota1 = integer(sle_5.text)
nNota2 = integer(sle_6.text)
Sle_3.text = string(today())
nNota3 = integer(sle_7.text)
nNota4 = integer(sle_8.text)
nExa = integer(sle_9.text)

//Se invoca a la funcion promedio


nPromedioP = promedio(nNota1,nNota2,nNota3,nNota4)
nPromedioG = (nPromedioP+nExa)/2
nPromedioG = round(npromedioG,0)
//Se invoca a la funcion condicion
cMensaje=condicion(nPromedioG)
sle_10.text = string (nPromedioG)
sle_11.text = cMensaje

En el botn nuevo:
sle_1.text=""
sle_2.text=""
sle_4.text=""
sle_5.text=""
sle_6.text=""

sle_7.text=""
sle_8.text=""
sle_9.text=""
sle_10.text=""
sle_11.text=""

En el botn salir:
close(w_promedio)

EJERCICIOS USANDO FUNCIONES ESTNDARES DE POWER


BUILDER
Ejemplo 3.
Crear una calculadora usando funciones como: valor absoluto, raz
cuadrada, funciones trigonomtricas, y todas las que se encuentran
en la pgina 35 a la pagina 40.

Primero creamos las funciones:

Funcin Coseno:
real resul4
resul4 = cos(t)
return resul4

Funcin factorial:
integer resul
resul = Fact(l)
return resul

Funcin pi:
dec resulte
resulte = Pi(r)
return resulte

Funcin logaritmo natural:


integer loga
loga = log(p)
return loga

Funcin potencia:

dec wu

wu = Exp(e)

return wu

Funcin raz cuadrada:

dec qe

qe = Sqrt
(w)

return qe

Funcin seno:

decimal
resut2

resut2 =
sin(k)

return
resut2

Funcin tangente:

dec po

po = tan (i)

return po

Funcin valor absoluto:

real resul2
resul2 = Abs (p)
return resul2

Luego codificamos:
Declaramos una variable global a
Botn tangente

a= integer (sle_1.text)

dec re

re =tangente(a)

sle_2.text = string (re)

Botn seno
a = dec(sle_1.text)
dec result
result =seno(a)
sle_2.text = String
(result)
Botn raz cuadrada
a= dec (sle_1.text)
dec resu
resu = raizcuadrada(a)
sle_2.text = string
(resu)

Botn coseno
a = integer (sle_1.text)
real resul5
resul5 = coseno(a)
sle_2.text = string
(resul5)

Botn valor absoluto


a = real (sle_1.text)
real resul3
resul3 =
valorabsoluto(a)
sle_2.text = string
(resul3)
Botn pi
a = integer (sle_1.text)
decimal result1
result1 = funpi(a)
sle_2.text = String
(result1)

Botn logaritmo
a = integer (sle_1.text)
string mensaje
dec result
result = logaritmo(a)
sle_2.text = string (result)
Botn potencia
a= integer (sle_1.text)
dec wo
wo = potencia(a)
sle_2.text = string (wo)
Botn factorial
a = integer(sle_1.text)
integer resul1
resul1 =factorial(a)
sle_2.text = string (resul1)

Ejemplo 4.

Codificamos:

En el botn apply:

int dia,mes,ao,szodiaco
string z
date fec

dia=integer(sle_1.text)
mes=integer(sle_2.text)
ao=integer(sle_3.text)
fec=today()
szodiaco=integer(right(string(fec),4))
if dia>=21 and mes=3 or dia<=20 and mes=4 then
z="Aries"
pb_1.picturename="C:\Users\JENNIFER\Download
s\aries_1.gif"
end if
if dia>=21 and mes=4 or dia<=21 and mes=5 then
z="Tauro"
pb_1.picturename="C:\Users\JENNIFER\Download
s\tauro_1.gif"
end if
if dia>=22 and mes=5 or dia<=22 and mes=6 then
z="Gemenis"
pb_1.picturename="C:\Users\JENNIFER\Download
s\geminis_1.gif"
end if
if dia>=23 and mes=6 or dia<=22 and mes=7 then
z="Cancer"
pb_1.picturename="C:\Users\JENNIFER\Download
s\cancer_1.gif"
end if
if dia>=23 and mes=7 or dia<=22 and mes=8 then

z="Leo"
pb_1.picturename="C:\Users\JENNIFER\Download
s\leo_1.gif"
end if
if dia>=23 and mes=8 or dia<=22 and mes=9 then
z="Virgo"
pb_1.picturename="C:\Users\JENNIFER\Download
s\virgo_1.gif"
end if
if dia>=23 and mes=9 or dia<=22 and mes=10 then
z="Libra"
pb_1.picturename="C:\Users\JENNIFER\Download
s\libra_1.gif"
end if
if dia>=23 and mes=10 or dia<=21 and mes=11 then
z="Escorpio"
pb_1.picturename="C:\Users\JENNIFER\Download
s\escorpio_1.gif"
end if
if dia>=22 and mes=11 or dia<=21 and mes=12 then
z="Sagitario"
pb_1.picturename="C:\Users\JENNIFER\Download
s\sagitario_1.gif"
end if
if dia>=22 and mes=12 or dia<=20 and mes=1 then
z="Capricornio"
pb_1.picturename="C:\Users\JENNIFER\Download
s\capricornio_1.gif"
end if
if dia>=20 and mes=1 or dia<=18 and mes =2 then
z="Acuario"
pb_1.picturename="C:\Users\JENNIFER\Download
s\acuario_1.gif"
end if
if dia>=19 and mes=2 or dia<=20 and mes=3 then
z="Picis"
pb_1.picturename="C:\Users\JENNIFER\Download
s\picis_1.gif"
end if
st_4.text="Usted Tiene" +""+ string (szodiaco - ao)
+"Aos y su Signo es:" + string(z)

Ejemplo 5.

Codificamos el botn new:


int hijo,rest,mesa,total,cantidad
double estacio,gturista,tot
cantidad=integer(sle_3.text)
if cbx_1.checked=true then hijo=3.50*cantidad
if cbx_2.checked=true then rest=8
if cbx_3.checked=true then
mesa=15
total=hijo+rest+mesa
st_13.text=string(total)
if cbx_4.checked=true then estacio=total*0.0676

if cbx_5.checked=true then gturista=total * 0.085


tot=estacio+gturista
st_14.text=string(tot)
end if

st_15.text=string(total
-tot)

Codificamos el botn
exit:

close(w_centroturistico)

Ejemplo 6.

Primero codificamos el botn agregar:

// validamos que se a ingresado un pais


if sle_1.text <> "" then
lb_1.additem(sle_1.text)
//contar la cantidad de elementos de la lista
sle_2.text = string (lb_1.totalitems())
sle_1.text = ""
else
messagebox("error","ingresar un pais")
end if
Despues codificamos el botn >>:
integer i
//bucle para agregar todos los datos
for i=1 to lb_1.totalitems()
lb_1.selectitem(i)
lb_2.additem(lb_1.selecteditem())
next
//limpiamos la lista 01
lb_1.reset()
//total de elementos de la lista 01
sle_2.text=string (lb_1.totalitems())
sle_3.text=string (lb_2.totalitems())
Despues codificamos el botn >
//valimos que se seleccione un pais
if lb_1.selectedindex()<0 then
messagebox("error", "seleccione un pais")
else
//pasamos los datos a la lista 02
lb_2.additem(lb_1.selecteditem())
//borramos los datos de la lista 01
lb_1.deleteitem(lb_1.selectedindex())
end if
//total de elementos de la lista
sle_2.text = string (lb_1.totalitems())
sle_3.text=string (lb_2.totalitems())
Luego codificamos el botn <
//valimos que se seleccione un pais

if lb_2.selectedindex()<0 then
messagebox("error", "seleccione un pais")
else
//pasamos los datos a la lista 01
lb_1.additem(lb_2.selecteditem())
//borramos los datos de la lista 02
lb_2.deleteitem(lb_2.selectedindex())
end if
//total de elementos de la lista
sle_2.text = string (lb_1.totalitems())
sle_3.text=string (lb_2.totalitems())
Luego codificamos el botn <<:
integer i
//bucle para agregar todos los datos
for i=1 to lb_2.totalitems()
lb_2.selectitem(i)
lb_1.additem(lb_2.selecteditem())
next
//limpiamos la lista 01
lb_2.reset()
//total de elementos de la lista 01
sle_2.text=string (lb_1.totalitems())
sle_3.text=string(lb_2.totalitems())
Luego codificamos el botn delete
integer a,b
a = integer (lb_1.selectedindex())
b = integer (lb_2.selectedindex())
lb_1.deleteitem(a)
lb_2.deleteitem(b)

You might also like