Sei sulla pagina 1di 4

INFORMATICA II- AO 2014 (2do semestre) Docentes: Reynares y Morelli

PRACTICA N 1 : EJERCICIOS RESUELTOS


Ejercicio N 1: Creacin, carga y procesamiento interactivo de una tabla.
a) Para crear una tabla nueva:
* 1 opcin:
tipear el comando CREATE en la Ventana de Comandos
* 2 opcin:
elegir Archivo>>Nuevo>>Tabla>>NuevoArchivo de la Barra de Menes
Una vez creada la estructura cabecera con los campos correspondientes, ingresar datos en algunos
registros. Tambin puede usarse el comando APPEND (desde la Ventana de Comandos).
Para visualizar los datos ingresados, usar los comandos DISPLAY LIST y para editarlos usar
BROWSE EDIT (desde la Ventana de Comandos)
b) Para crear un ndice:
* 1 opcin:
En la Ventana de Comandos tipear: INDEX onNROFAC tag inf
Mostrar la tabla
*2 opcin:
En la Ventana de Comandos tipear: MODIFY STRUCTURE
Al aparecer el Diseador de Tablas, optar por la pestaa Indices. En Tipo elegir Candidato.
Aceptar y mostrar la tabla.
c) Para editar slo algunos campos y slo los registros que cumplen una determinada condicin,
en la Ventana de Comandos tipear: EDIT fieldsNROFAC, IMPORTE for IMPORTE >2000
d) Para completar o modificar valores en un campo:
REPLACE VENCIM with FECHA +15 for IMPORTE <1000
e) Para calcular el valor mximo de un campo:
CALCULATE MAX(IMPORTE) to m
Para mostrar los datos de las facturas que tuvieron un importe igual al mximo:
DISPLAY FOR IMPORTE =m
Ejercicio N 2: Creacin, carga, procesamiento e importacin de datos.
c) * Para agregar datos desde una planilla Excel de nombre EJ1P1.xls :
teniendo abierta (en uso) la tabla ALUMNOS , tipear en la Ventana de Comandos:
APPENDFROM z:\inf2\ej1p1.xls typeXLS

APPENDFROM z:\inf2\ej1p1.xls typeXL8sheet xxx


donde z:\inf2\ej1p1.xls es el path o camino (unidad\carpeta\archivo) para ubicar al archivo de
Excel y xxx es el nombre dado a la Hoja1 del archivo de Excel.
*Para importar datos (se crea una tabla de igual nombre):
Habiendo cerrado la tabla ALUMNOS (tipeando CLOSE ALL en la Ventana de Comandos), elegir
Archivo>>Importar >>AsistenteparaImportar de la Barra de Menes
d) Para agregar datos desde un archivo de texto de nombre EJ1P1.txt :
teniendo abierta (en uso) la tabla ALUMNOS , tipear en la Ventana de Comandos:
APPENDFROM z:\inf2\ej1p1.txt typedelimited

APPENDFROM z:\practica2\ej1p1.txt delimitedwithblank


segn sean comas o blancos los delimitadores del texto.
e) En la Ventana de Comandos tipear:
INDEX onLEGAJ O tag ileg
Mostrar la tabla
INDEX onLEGAJ O+NOMBRE tag ilegnom
Mostrar la tabla
f) Para desactivar los ndices:
* 1 opcin: Tipear en la ventana de comandos:
SET ORDER TO
Mostrar la tabla
Para activar el ndice ileg tipear:
SET ORDER toileg
Mostrar la tabla
Para activar el ndice ilegnom tipear:
SET ORDER toilegnom
Mostrar la tabla
* 2 opcin: Cerrar la tabla y sus ndices tipeando:
USE
CLOSE ALL
Abrir la tabla activando el ndice ileg simultneamente:
USE ALUMNOSORDER ileg
Mostrar la tabla
Para activar el ndice ilegnom tipear:
SET ORDER toilegnom
Mostrar la tabla
g) Cantidad de alumnos del curso: CALCULATE CNT() to n
h) &&si quedaron columnas con null y vacas
CALCULATE CNT() for !isnull(nota1) and !empty(nota1)
CALCULATE CNT() for !isnull(nota2) and !empty(nota2)
&&si quedaron slo columnas con null
1 opcin: CALCULATE CNT() for !isnull(nota1)
CALCULATE CNT() for !isnull(nota2)
2 opcin: CALCULATE CNT(nota1)
CALCULATE CNT(nota2)
Observacin: Al agregar datos de otros tipos de archivos, los campos creados para que acepten
.null. (Nota1, Nota2 y Condicion) pueden quedar con valores, vacos o con .null. En el caso en que
se desconoce el dato del alumno, conviene uniformar con .null.
REPLACE NOTA1 with .NULL. for empty(NOTA1), NOTA2 with .NULL. for empty(NOTA2)
i) CALCULATE CNT() for nota1 >=6
CALCULATE CNT() for nota2 >=6
j) REPLACE condicion with "P" for nota1>=6 and nota2 >=6
REPLACE condicionwith "L" for (nota1<6 and nota2 <6) OR;
(isnull(nota1) and isnull(nota2))
k) CALCULATE CNT() for condicion =P
CALCULATE CNT() for condicion=L
CALCULATE CNT()for (nota1>=6 and nota2 <6) OR (nota1 <6 and nota2 >=6) OR ;
(!isnull(nota1) and isnull(nota2)) OR (isnull(nota1) and !isnull(nota2))
l) CALCULATE AVG ((nota1+nota2)/2)
m) LIST fields legajo,rtrim(nombre),apellido for ((nota1+nota2)/2)>=9
&&pero falta el ordenamiento, lo correcto es:
set default to z:\inf2
use alumnos
browse
SORT to alumord on apellido /C, nombre for ;
((nota1+nota2)/2) >=9 fields legajo, nombre, apellido
use
use alumord
browse
Ejercicio N 3: Resolucin mediante programacin:
* En Ventana de Comandos escribir:
use ventas
modify structure &&para agregarle dos campos: nro N(2,0) y total N (10,2)
*Para crear un programa:
1 opcin:
Elegir File>>New>>Program>>Newfile de la Barra de Menes

2 opcin:
modifycommand en la Ventana de Comandos
Solucin a):
close all
clear
set default to z:\inf2
set date dmy
set century on
num =0
nsuma=0
dias =0
@5,5 SAY "Ingrese das de prrroga: " GET dias VALID dias>=0 and dias<=7
READ
USE ventas
DO WHILE !EOF( )
num=num+1
nsuma=nsuma+importe
replace nro with num
replace total with nsuma
replace vencim with vencim +dias
SKIP
ENDDO
browse
Solucin b):
close all
clear
set default to z:\inf2
set date dmy
set century on
dias =0
@5,5 SAY "Ingrese das de prorroga: " GET dias RANGE 0,7
READ
USE ventas
num =RECNO() &&nmero de registro activo
nsuma=0
SCAN
nsuma=nsuma+importe
replace nro with num
replace total with nsuma
replace vencim with vencim +dias
num=num+1
ENDSCAN
browse
Ejercicio N 5:
*Crear la tabla CONSUMOS:
create table consumos (fechaini d,lecturaini N(7,0),fechafin d, lecturafin N(7,0), consumo N(7,0))
*Crear un programa nuevo con modify command:
clear
set default to "z:\inf2"
set date dmy
set century on
USE consumos
scatter memvar blank
&&se leen los datos del primer registro
@1,1 say "ingrese fecha inicial" get m.fechaini
@2,1 say "ingrese fecha final" get m.fechafin valid m.fechafin >m.fechaini
@3,1 say "ingrese lectura inicial" get m.lecturaini
@4,1 say "ingrese lectura final" get m.lecturafin valid m.lecturafin >m.lecturaini
READ
do while lastkey()!=27
m.consumo=m.lecturafin-m.lecturaini
append blank
gather memvar &&se completa el primer registro
m.lecturaini=m.lecturafin
m.fechaini=m.fechafin
clear
&& se leen los datos del resto de los registros
@1,1 say "ingrese fecha" get m.fechafin valid m.fechafin >m.fechaini
@2,1 say "ingrese lectura" get m.lecturafin valid m.lecturafin >m.lecturaini
READ
enddo
browse
wait "Presione una tecla para continuar" windows timeout 10
clear
close all
Observacin: Produce error el uso de DO WHILE LASTKEY() !=27 en este ejercicio?

Potrebbero piacerti anche