Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Clase 5
Clase 5
Algoritmos
Datos y Programas
Clase 5
CADP – Temas de la clase de hoy
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS
COMPUESTO: pueden
SIMPLE: aquellos que
toman un único valor,
TIPO DE DATO tomar varios valores a la
vez que guardan alguna
en un momento relación lógica entre
determinado, de todos ellos, bajo un único
los permitidos para ese nombre.
tipo.
SIMPLE COMPUESTO
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS
Tipo propiedad
Cantidad de habitaciones
Cantidad de baños
Precio Alquiler
Localidad
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS
Tipo propiedad
Cantidad de habitaciones
Cantidad de baños
Precio Alquiler
Localidad
Tipo propiedad
Cantidad de habitaciones
Cantidad de baños INMUEBLE
Precio Alquiler
Localidad
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS
ESTRUCTURA DE DATOS
Permite al programador definir un tipo al que se asocian
diferentes datos que tienen valores lógicamente relacionados
y asociados bajo un nombre único.
Tipo propiedad
Cantidad de habitaciones
Cantidad de baños INMUEBLE
Precio Alquiler
Localidad
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS CLASIFICACION
ESTRUCTURA DE DATOS
Permite al programador definir un tipo al que se asocian
diferentes datos que tienen valores lógicamente relacionados
y asociados bajo un nombre único.
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS CLASIFICACION
ELEMENTOS
Depende si los elementos son del mismo tipo o no.
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS CLASIFICACION
TAMAÑO
Hace referencia a si la estructura puede variar su tamaño
durante la ejecución del programa.
ACCESO
Hace referencia a como se pueden acceder a los elementos que
la componen.
Para acceder a un elemento particular se debe respetar un orden
SECUENCIAL predeterminado, por ejemplo, pasando por todos los elementos
que le preceden, por ese orden.
LINEALIDAD
Hace referencia a como se encuentran almacenados los
elementos que la componen.
Está formada por ninguno, uno o varios elementos que guardan una
LINEAL relación de adyacencia ordenada donde a cada elemento le sigue uno
y le precede uno, solamente.
Var
Clase 5 inmu1, inmu2: inmueble;
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Program uno;
Const Begin
….
Type ….
inmu2:= inmu1;
inmueble = record
CON LA tipo: string;
…
End.
VARIABLE cantHab: integer;
cantBaños:integer;
REGISTRO precio: real;
localidad: string;
end;
La única operación
permitida es la asignación
Var entre dos variables del
inmu1, inmu2: inmueble;
mismo tipo
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Program uno;
Const Begin
…. ….
Type Puedo realizar las
operaciones permitidas
inmueble = record
CON LOS tipo: string;
según el tipo de campo
del registro
CAMPOS cantHab: integer; …
cantBaños:integer;
DEL precio: real;
End.
t e cantHab: integer;
el con istro?
read(i.cantHab); cantBaños:integer;
read(i.cantBaños);
un r e g precio: real;
localidad: string;
read(i.precio);
end;
read(i.localidad); Procedure leer (var i:inmueble);
end; begin
….
Debo asignarlos en Qué ocurre si no le end;
el orden en que se doy valor a todos los
campos? Var
declararon? inmu1, inmu2: inmueble;
Puede ser una Begin
leer (inmu1);
función en vez de un inmu2:= inmu1;
Clase 5 procedimiento? End.
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Program uno;
Const
Begin
…. leer (inmu1);
Type No se puede hacer
write (inmu1.tipo);
write(inmu1.cantHab);
write (inmu1)
inmueble = record write(inmu1.cantBaños);
tipo: string; write(inmu1.precio);
cantHab: integer; write(inmu1.localidad);
cantBaños:integer; End.
precio: real;
localidad: string; Qué ocurre si no le
end; imprimo todos los MOD
Var
campos? UL ARIZ
inmu1, inmu2: inmueble; A R?
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Program uno;
Const
Procedure imprimir (i:inmueble);
….
Type
Begin m p a r o
o c o inmueble = record
write(i.tipo); Cóm n id o d e tipo: string;
nt e cantHab: integer;
write(i.cantHab);
el co i s tr o s ? cantBaños:integer;
write(i.cantBaños); r eg precio: real;
write(i.precio); dos localidad: string;
end;
write(i.localidad); Procedure imprimir (i:inmueble);
end; begin
….
Debo imprimir en el Qué ocurre si no end;
orden en que se imprimo todos los
declararon? campos? Var
inmu1, inmu2: inmueble;
Puede ser una Begin
leer (inmu1);
función en vez de un imprimir(inmu1);
Clase 5 procedimiento? End.
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Program uno;
Const No se puede hacer
Begin
…. leer (inmu1); inmu1 = inmu2
Type leer (inmu2),
MOD
Var
ULAR
inmu1, inmu2: inmueble; IZAR?
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
function iguales (i1,i2:inmueble):boolean;
Var
ok:boolean;
Begin
if ((i1.tipo = i2.tipo)and
(i1.cantHab = i2.cantHab) and
(i1.cantBaños = i2.cantBaños) and
(i1.precio = i2.precio) and
(i1.localidad = i2.localidad))
then ok:= true function iguales (i1,i2:inmueble):boolean;
else ok:= false; Begin
iguales:= ok; iguales:= ((i1.tipo = i2.tipo)and
end; (i1.cantHab = i2.cantHab) and
(i1.cantBaños = i2.cantBaños) and
(i1.precio = i2.precio) and
(i1.localidad = i2.localidad));
end;
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Program uno;
Const
…. Begin
Type leer (inmu1);
inmueble = record leer (inmu2);
tipo: string; if (iguales (inmu1,inmu2) = true) then
cantHab: integer;
write (`Los registros son iguales`)
cantBaños:integer;
precio: real; else write (`Los registros no son
localidad: string; iguales`);
end; End.
function iguales (i1,i2:inmueble): boolean;
begin
…. Begin
end; leer (inmu1);
leer (inmu2);
Var if (iguales (inmu1,inmu2)) then
inmu1, inmu2: inmueble; write (`Los registros son iguales`)
else write (`Los registros no son
iguales`);
Clase 5 End.
CADP – REGISTRO EJERCITACION
Escriba un programa que lea inmuebles hasta leer un
inmueble cuya localidad es `XXX` Al finalizar informe de
los inmuebles en la localidad de `La Plata` cuantos
tienen al menos 2 habitaciones
Tipo `Casa`
cantHab:4
cantBaños 1 2
precio 10.000
Localidad XXX
Clase 5
CADP – REGISTRO EJERCITACION
Escriba un programa que lea inmuebles hasta leer un inmueble cuya localidad es `XXX` Al finalizar
informe de los inmuebles en la localidad de `La Plata` cuantos tienen al menos 2 habitaciones
Clase 5
CADP – REGISTROS EJERCITACION
procedure leer (var i:inmueble);
Begin
read(i.tipo); procedure leer (var i:inmueble);
read(i.cantHab);
read(i.cantBaños); Begin
read(i.precio); read(i.localidad);
read(i.localidad); if (i.localidad <> `XXX`) then
end; Qué begin
e rn a tiv a read(i.cantHab);
alt read(i.cantBaños);
co n v ie n e? read(i.precio);
read(i.tipo);
end;
Clase 5
end;
CADP – REGISTROS EJERCITACION
function esLaPlata (i:inmueble): boolean;
var
ok:boolean;
begin
if (i.localidad = `La Plata`) then
ok:= true
else
ok:= false;
esLaPlata:= ok;
Otra opción
end; function esLaPlata (i:inmueble): boolean;
begin
esLaPlata:= (i.localidad = `La Plata`);
end;
Clase 5
CADP – REGISTROS EJERCITACION
function cantHab (i:inmueble): boolean;
var
ok:boolean;
begin
if (i.cantHab >= 2) then
ok:= true
else
ok:= false;
cantHab:= ok;
Otra opción
end; function cantHab (i:inmueble): boolean;
begin
cantHab:= (i.cantHab >= 2);
end;
Clase 5
CADP – REGISTROS EJERCITACION
Program uno;
Type
inmueble = record Es ne
tipo: string;
Var cesar
cantHab: integer; todo io p a
cantBaños:integer; inmu:inmueble; e l reg sar
cant:integer; las fu istro
precio: real;
localidad: string; Begin ncion a
end; cant:= 0; es ?
Procedure leer (var i:inmueble); leer (inmu);
begin while (inmu.localidad <> `XXX`) do
end; begin
function esLaPlata (i:inmueble): boolean; if (eslapLata (inmu)) then
begin
if (cantHab (inmu)) then
….
end; cant:= cant + 1;
leer (inmu);
function cantHab (i:inmueble): boolean; end;
begin write (`La cantidad es`, cant);
…. End.
end;
Clase 5
CADP – REGISTROS Begin
EJERCITACION
…
function esLaPlata (i:inmueble): boolean; while (inmu.localidad <> `XXX`) do
begin
begin if (eslapLata (inmu) then
esLaPlata:= (i.localidad = `La Plata`); …
end; end;
..
End.
Otra opción
…
function esLaPlata (loc:string): boolean;
while (inmu.localidad <> `XXX`) do
begin
begin
if (eslapLata (inmu.localidad) then
esLaPlata:= (loc = `La Plata`);
…
end;
end;
..
End.
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Program uno;
Const
….
Type Qué cam
biamos
si ahora
inmueble = record
quiere ag s e
tipo: string;
regar la
cantHab: integer; fecha de
cantBaños:integer; sde que
precio: real; el inmue
localidad: string;
ble está
disponib
end; le?
Var
Clase 5 inmu1: inmueble;
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Program uno;
Type
Opción 1 inmueble = record
tipo: string;
cantHab: integer;
cantBaños:integer;
precio: real;
localidad: string;
dia:integer;
mes:integer; Otra
año:integer;
opció
end; n?
Var
inmu1: inmueble;
Clase 5
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Program uno;
Type
Opción 2 fecha = record Cómo
dia: integer; hacem
mes:integer; ahora o s
el pro
año:integer;
de l e c c es o
end; tura?
inmueble = record
tipo: string;
cantHab: integer;
cantBaños:integer;
precio: real;
localidad: string;
fechaPub:fecha;
Clase 5 end;
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
procedure leer (var i:inmueble);
Begin
read(i.tipo); NO SE PUEDE ya que i.fechaPub es
read(i.cantHab); un registro y no se puede hacer
read(i.cantBaños); read directamente
read(i.precio);
read(i.localidad); procedure leer (var i:inmueble);
read (i.fechaPub);
end; Begin
read(i.tipo); Otra
read(i.cantHab);
altern
read(i.cantBaños); ativa?
read(i.precio);
read(i.localidad);
read (i.fechaPub.dia);
read (i.fechaPub.mes);
read (i.fechaPub.año);
Clase 5 end;
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
procedure leerFecha (var f:fecha);
Begin
read(f.dia);
read(f.mes);
read(f.año);
end;
procedure leer (var i:inmueble);
var Otra opción
fec:fecha; procedure leer (var i:inmueble);
Begin begin
read(i.tipo); read(i.tipo);
read(i.cantHab); read(i.cantHab);
read(i.cantBaños); read(i.cantBaños);
read(i.precio); read(i.precio);
read(i.localidad); read(i.localidad);
leerFecha (fec); leerFecha (i.fechaPub);
i.fechaPub:= fec; end;
Clase 5 end;
CADP – REGISTRO EJERCITACION
Escriba un programa que lea inmuebles hasta leer un
inmueble cuya localidad es `XXX` Al finalizar informe de
los inmuebles en la localidad de `La Plata` y cuantos
inmuebles se publicaron en el verano del 2021.
Tipo `Casa`
cantHab:4
3
cantBaños 1
2
precio 10.000
Localidad XXX
Clase 5
CADP – REGISTRO EJERCITACION
Escriba un programa que lea inmuebles hasta leer un inmueble cuya localidad es `XXX`
Al finalizar informe de los inmuebles en la localidad de `La Plata` y cuantos inmuebles
se publicaron en el verano del 2020.
Var Otra
cumple:boolean; form
Begin a?
if ( ((i.fechaPub.dia>= 21) and (i.fechaPub.mes = 12)
and (i.fechaPub.año = 2020 then cumple:= true
verano:= cumple;
Clase 5 end;
CADP – TIPOS DE DATOS ESTRUCTURADOS REGISTRO
Clase 5