Last active
May 8, 2017 05:39
-
-
Save snorkellingcactus/7bf1bf48a034bfc814f0ee5998b74539 to your computer and use it in GitHub Desktop.
Actividad 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Program CentroComercial; | |
type | |
str30= string[30]; | |
t_fecha = record | |
dia: 1..31; | |
mes: 1..12; | |
end; | |
t_targeta = record | |
numero: integer; | |
marca: str30; | |
end; | |
t_compra = record | |
fecha: t_fecha; | |
targeta: t_targeta; | |
monto: real; | |
cuotas: integer; | |
end; | |
t_cliente = record | |
dni: LongInt; | |
apellido: str30; | |
nombre: str30; | |
correo: str30; | |
end; | |
procedure leeCliente( var cliente: t_cliente ); | |
begin | |
writeln( 'Apellido:' ); | |
readln( cliente.apellido ); | |
writeln( 'Nombre:' ); | |
readln( cliente.nombre ); | |
writeln( 'Correo:' ); | |
readln( cliente.correo ); | |
end; | |
procedure leeFecha( var fecha: t_fecha ); | |
begin | |
writeln( 'Fecha:' ); | |
writeln( ' Mes:' ); | |
readln( fecha.mes ); | |
writeln( ' Dia:' ); | |
readln( fecha.dia ); | |
end; | |
procedure leeTargeta( var targeta: t_targeta ); | |
begin | |
writeln( 'Targeta:' ); | |
writeln( ' Numero:' ); | |
readln( targeta.numero ); | |
writeln( ' Marca:' ); | |
readln( targeta.marca ); | |
end; | |
procedure leeCompra( var compra: t_compra ); | |
begin | |
leeFecha( compra.fecha ); | |
leeTargeta( compra.targeta ); | |
writeln( ' Monto:' ); | |
readln( compra.monto ); | |
writeln( ' Cuotas:' ); | |
readln( compra.cuotas ); | |
end; | |
procedure leeDNICliente( var cliente:t_cliente; var num: integer ); | |
begin | |
writeln( 'Datos cliente ' , num ); | |
writeln( ' DNI:' ); | |
readln( cliente.dni ); | |
num:=num+1; | |
end; | |
function leeNumeroCompra( var num: integer ): integer; | |
begin | |
writeln( ' Datos compra ', num ); | |
writeln( ' Nùmero:' ); | |
readln( leeNumeroCompra ); | |
num:=num+1; | |
end; | |
function cumpleCorreo( compra: t_compra ): boolean; | |
begin | |
cumpleCorreo:=false; | |
if ( compra.fecha.mes = 1 ) AND ( compra.monto > 5000 ) AND ( compra.cuotas = 1 ) AND ( compra.targeta.marca = 'VISA' ) then | |
begin | |
cumpleCorreo:=true; | |
end | |
end; | |
function cumplePromo( prom_compras_por_mes: integer ): boolean; | |
begin | |
cumplePromo:=( prom_compras_por_mes >= 4 ); | |
end; | |
function cumpleDNI( dni: LongInt ): boolean; | |
var | |
digito: integer; | |
pares: integer; | |
par_a, par_b: integer; | |
iguales: boolean; | |
begin | |
cumpleDNI:=false; | |
pares:=0; | |
par_b:=0; | |
while( dni <> 0 ) AND ( pares <= 3 ) do | |
begin | |
digito:=dni mod 10; | |
{ dni/10 devuelve un Double, dni div 10 un integer } | |
dni:=dni div 10; | |
{ Funcionara igual si saco el parentesis? } | |
if ( digito mod 2 = 0 ) then | |
begin | |
iguales:=( pares = 2 ) AND ( ( digito = par_b ) OR ( digito = par_a ) ); | |
if( pares = 1 ) then | |
if( digito <> par_a ) then | |
begin | |
par_b:= digito; | |
end | |
else | |
begin | |
iguales:=true; | |
end; | |
if( pares = 0 ) then | |
par_a:=digito; | |
if( iguales ) then | |
pares:=3; {Provoca que el bucle termine} | |
pares:=pares+1; | |
end | |
end; | |
if( pares = 3 ) then | |
cumpleDNI:=true; | |
end; | |
function calculaPorcentaje( cantidad:real; total: real ): real; | |
begin | |
calculaPorcentaje:=( cantidad*(total/100) ); | |
end; | |
procedure procesaCompras( cliente: t_cliente; var cuenta_compras: integer; var cuenta_compras_mastercard: integer ); | |
var | |
num_compra: integer; | |
compra: t_compra; | |
cuenta: integer; | |
acum_monto_por_trimestre: real; | |
acum_compras_por_trimestre: integer; | |
prom_compras_por_mes: integer; | |
prom_monto_por_mes: integer; | |
begin | |
num_compra:=0; | |
cuenta:=0; | |
acum_compras_por_trimestre:=0; | |
acum_monto_por_trimestre:=0; | |
prom_compras_por_mes:=0; | |
prom_monto_por_mes:=0; | |
while( leeNumeroCompra( num_compra ) <> 0 ) do | |
begin | |
leeCompra( compra ); | |
if( cumpleCorreo( compra ) ) then | |
begin | |
writeln( 'Correo: ', cliente.correo ); | |
end; | |
if( compra.fecha.mes <=3 ) then | |
begin | |
acum_compras_por_trimestre:=acum_compras_por_trimestre+1; | |
acum_monto_por_trimestre:=acum_monto_por_trimestre+compra.monto; | |
end; | |
if( compra.targeta.marca = 'Mastercard' ) then | |
begin | |
cuenta_compras_mastercard:=cuenta_compras_mastercard+1; | |
end; | |
cuenta:=cuenta+1; | |
end; | |
prom_compras_por_mes:=acum_compras_por_trimestre div 3; | |
if( cumplePromo( prom_compras_por_mes ) ) then | |
begin | |
writeln( ' Cumple Promo: ' ); | |
writeln( ' Promedio compras por mes:', prom_compras_por_mes ); | |
writeln( ' Promedio monto por mes:', prom_monto_por_mes ); | |
writeln( ' DNI:', cliente.dni ); | |
end; | |
cuenta_compras:=cuenta_compras+cuenta; | |
{porcentaje_mastercard:=calculaPorcentaje( cuenta_compras, cuenta_compras_mastercard )} | |
end; | |
var | |
cliente: t_cliente; | |
num_cliente: integer; | |
cuenta_compras_mastercard: integer; | |
cuenta_compras: integer; | |
begin | |
num_cliente:=0; | |
leeDNICliente( cliente, num_cliente ); | |
while( cliente.dni <> 0 ) do | |
begin | |
leeCliente( cliente ); | |
procesaCompras( cliente, cuenta_compras, cuenta_compras_mastercard ); | |
if( cumpleDNI( cliente.dni ) ) then | |
begin | |
writeln( 'DNI con pares:' ); | |
writeln( ' Apellido:', cliente.apellido ); | |
writeln( ' Nombre:', cliente.nombre ); | |
end; | |
leeDNICliente( cliente, num_cliente ); | |
end; | |
writeln( ' Porcentaje mastercard: ', calculaPorcentaje( cuenta_compras_mastercard, cuenta_compras ) ); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment