PDF de programación - Parte I: Programación en Ada - 7. Entrada/salida con ficheros

Imágen de pdf Parte I: Programación en Ada - 7. Entrada/salida con ficheros

Parte I: Programación en Ada - 7. Entrada/salida con ficherosgráfica de visualizaciones

Publicado el 6 de Junio del 2017
1.010 visualizaciones desde el 6 de Junio del 2017
310,5 KB
26 paginas
Creado hace 15a (24/11/2008)
Parte I: Programación en Ada

UNIVERSIDAD DE CANTABRIA

1. Introducción a los computadores y su programación
2. Elementos básicos del lenguaje
3. Modularidad y programación orientada a objetos
4. Estructuras de datos dinámicas
5. Tratamiento de errores
6. Abstracción de tipos mediante unidades genéricas
7. Entrada/salida con ficheros
8. Herencia y polimorfismo
9. Programación concurrente y de tiempo real

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

4

© Javier Gutiérrez, Michael González

24/nov/08

1

1. Introducción

UNIVERSIDAD DE CANTABRIA

Hay dos tipos de entrada/salida según el tipo de información:
• de texto

- pensada para los “humanos”
- restringida a datos que se puedan convertir a texto

(strings, caracteres, números, enumerados)

- basada en líneas de caracteres

• binaria

- pensada para las “máquinas”
- para cualquier tipo de dato, excepto punteros
- las estructuras con punteros deben ser “serializadas”
- basadas en secuencias de “casillas” o de bytes

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

2

2. Ficheros

UNIVERSIDAD DE CANTABRIA

Representan una estructura de datos almacenada en memoria
secundaria o un dispositivo de entrada/salida
• Si es memoria secundaria, los datos son no volátiles

Se identifican en el sistema operativo mediante un nombre

Se representan en el programa mediante una estructura de
datos de un tipo File_Type

Disco

Fichero
datos.txt

Programa

f : File_Type

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

3

Uso de ficheros

UNIVERSIDAD DE CANTABRIA

El uso siempre es así:
• Abrir el fichero para establecer una asociación entre la

estructura de datos y el fichero

• Leer y/o escribir
• Cerrar el fichero para desvincular la asociación y dejar los

datos en un estado consistente

Hay unos ficheros de texto ya abiertos, para uso habitual
• entrada estándar (generalmente el teclado)
• salida estándar (generalmente la pantalla)
• salida de error (generalmente la pantalla)

Se pueden modificar haciendo que sean otros ficheros

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

4

Interfaz para los ficheros

UNIVERSIDAD DE CANTABRIA

Abrir
• 2 modalidades:

- Create: para crear un fichero nuevo (se borra el viejo)
- Open: para ficheros existentes (si no existe, falla)

• requiere indicar el modo (del tipo File_Mode)

- In_File (leer), Out_File (escribir), Append_file

(añadir al final), Inout_File (leer y escribir)

• también requiere la variable del tipo File_Type y el nombre

del fichero (string)

Cerrar: Close

Leer y escribir: depende del tipo de fichero

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

5

3. Entrada/salida de texto

UNIVERSIDAD DE CANTABRIA

Está en el paquete Ada.Text_IO

Ya la conocemos para entrada/salida estándar
• ej.: operaciones Get, Put, Get_Line, Put_Line

Existen versiones de estas operaciones para otros ficheros
• el primer parámetro es la variable File_Type

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

6

Resumen de la especificación
de Ada.Text_IO (1/14)

UNIVERSIDAD DE CANTABRIA

with Ada.IO_Exceptions;
package Ada.Text_IO is

type File_Type is limited private;

type File_Mode is (In_File, Out_File, Append_File);

type Count is range 0 .. System.Parameters.Count_Max;

subtype Positive_Count is Count range 1 .. Count'Last;

subtype Number_Base is Integer range 2 .. 16;

type Type_Set is (Lower_Case, Upper_Case);

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

7

Especificación de
Ada.Text_IO (2/14)

UNIVERSIDAD DE CANTABRIA

-- File Management
procedure Create (File : in out File_Type;
Mode : in File_Mode := Out_File;
Name : in String := "";
Form : in String := "");
procedure Open (File : in out File_Type;
Mode : in File_Mode;
Name : in String;
Form : in String := "");
procedure Close (File : in out File_Type);
procedure Delete (File : in out File_Type);
procedure Reset (File : in out File_Type; Mode : in File_Mode);
procedure Reset (File : in out File_Type);

function Mode (File : in File_Type) return File_Mode;
function Name (File : in File_Type) return String;

function Is_Open (File : in File_Type) return Boolean;

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

8

Especificación de
Ada.Text_IO (3/14)

UNIVERSIDAD DE CANTABRIA

-- Control of default input, output and error files

procedure Set_Input (File : in File_Type);
procedure Set_Output (File : in File_Type);
procedure Set_Error (File : in File_Type);

function Standard_Input return File_Type;
function Standard_Output return File_Type;
function Standard_Error return File_Type;

function Current_Input return File_Type;
function Current_Output return File_Type;
function Current_Error return File_Type;

-- Buffer control
procedure Flush (File : in File_Type);
procedure Flush;

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

9

Especificación de
Ada.Text_IO (4/14)

UNIVERSIDAD DE CANTABRIA

-- Column and Line Control
procedure New_Line (File : in File_Type;
Spacing : in Positive_Count := 1);
procedure New_Line (Spacing : in Positive_Count := 1);

procedure Skip_Line (File : in File_Type;
Spacing : in Positive_Count := 1);
procedure Skip_Line (Spacing : in Positive_Count := 1);

function End_Of_Line (File : in File_Type) return Boolean;
function End_Of_Line return Boolean;

function End_Of_File (File : in File_Type) return Boolean;
function End_Of_File return Boolean;

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

10

Especificación de
Ada.Text_IO (5/14)

UNIVERSIDAD DE CANTABRIA

procedure Set_Col (File : in File_Type;
To : in Positive_Count);
procedure Set_Col (To : in Positive_Count);

procedure Set_Line (File : in File_Type;
To : in Positive_Count);
procedure Set_Line (To : in Positive_Count);

function Col (File : in File_Type) return Positive_Count;
function Col return Positive_Count;

function Line (File : in File_Type) return Positive_Count;
function Line return Positive_Count;

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

11

Especificación de
Ada.Text_IO (6/14)

-- Characters Input-Output

UNIVERSIDAD DE CANTABRIA

procedure Get (File : in File_Type; Item : out Character);
procedure Get (Item : out Character);
procedure Put (File : in File_Type; Item : in Character);
procedure Put (Item : in Character);
procedure Look_Ahead (File : in File_Type;
Item : out Character;
End_Of_Line : out Boolean);
procedure Look_Ahead (Item : out Character;
End_Of_Line : out Boolean);
procedure Get_Immediate (File : in File_Type;
Item : out Character);
procedure Get_Immediate (Item : out Character);
procedure Get_Immediate (File : in File_Type;
Item : out Character;
Available: out Boolean);
procedure Get_Immediate (Item : out Character;
Available: out Boolean);

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

12

Especificación de
Ada.Text_IO (7/14)

-- Strings Input-Output

UNIVERSIDAD DE CANTABRIA

procedure Get (File : in File_Type; Item : out String);
procedure Get (Item : out String);
procedure Put (File : in File_Type; Item : in String);
procedure Put (Item : in String);

procedure Get_Line (File : in File_Type;
Item : out String;
Last : out Natural);

procedure Get_Line (Item : out String;
Last : out Natural);

procedure Put_Line (File : in File_Type;
Item : in String);

procedure Put_Line (Item : in String);

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

13

UNIVERSIDAD DE CANTABRIA

Especificación de
Ada.Text_IO (8/14)

generic
type Num is range <>;

package Integer_IO is

Default_Width : Field := Num'Width;
Default_Base : Number_Base := 10;

procedure Get (File : in File_Type;
Item : out Num;
Width : in Field := 0);

procedure Get (Item : out Num;
Width : in Field := 0);

procedure Put (File : in File_Type;
Item : in Num;
Width : in Field := Default_Width;
Base : in Number_Base := Default_Base);

GRUPO DE COMPUTADORES Y TIEMPO REAL
FACULTAD DE CIENCIAS

© Javier Gutiérrez, Michael González

24/nov/08

14

Especificación de
Ada.Text_IO (9/14)

UNIVERSIDAD DE CANTABRIA

procedure Put (Item : in Num;
Width : in Field := Default_Width;
Base : in Number_Base := Default_Base);

procedure Get (From : in String;
Item : out Num;
Last : out Positive);

procedure Put (To : out String;
Item : in Num;
Base : in Number_Base := Default_Base);

end Integer_IO;

GRUPO DE COMPUTADORES Y TIE
  • Links de descarga
http://lwp-l.com/pdf4328

Comentarios de: Parte I: Programación en Ada - 7. Entrada/salida con ficheros (0)


No hay comentarios
 

Comentar...

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad