elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


  Mostrar Temas
Páginas: [1]
1  Programación / Programación General / AYUDA.PROCEDIMIENTO PARA DAR DE ALTA. PASCAL en: 25 Abril 2011, 11:46 am
hola de nuevo y gracias por leer este mensaje y por la ayuda que me podais dar.

Tengo que hacer un procedimiento para dar de alta libros, sobre una tabla de 50 libros o más. Las altas se tienen que hacer de una en una. NO todas de golpe.

Con esto el algoritmo sería:

Todas las posiciones de la tabla en las que el campo ALTA sea TRUE, es que estan ocupadas.

Todas en las que ALTA sea FALSE estan libre.

buscar una posición libre.

ALGORITMO:

encontrado=false (cuando sea true es que he encontrado la posicion)
posicionlibre=1 (empiezo a buscar por la uno)
indice=1 (para ir recorriendo la tabla)
fin=false (he llegado al final de la tabla)
mientras encontrado sea false y fin sea false hacer (salgo del bucle si
encuentro una posición libre o llego al final de la tabla)
   si tabla[indice].alta es false
en caso de que la posicion indice esté libre (el campo alta es false)
      encontrado=true y posicionlibre=indice
   else
      if(indice es distinto de tamcoleccion) es decir si todavía no he
llegado al final
         indice=indice+1
      else
          fin=true (he llegado al final y lo indico con fin)
fin mientras
salgo del bucle si he llegado al final sin encontrar posicion libre, en
ese caso fin vale true o si he encontrado una posicion libre, en ese caso
encontrado vale true
entonces ya se lo que tengo que hacer en cada caso:
si fin=true
  mostrar mensaje "No hay sitio en la tabla para más libros"
si encontrado=true
  leer datos del libro y meterlos en la posición posicionlibre

hasta dónde yo comprendo he realizado el siguiente código:

Código
  1. Procedure alta_libro(biblioteca: Tbiblioteca; longitud: integer);
  2.  
  3. var
  4.  
  5. i : integer;
  6. encontrado: boolean;
  7. posicionlibre : real;
  8. indice: real;
  9. fin : boolean;
  10.  
  11. begin
  12.  
  13. While(encontrado = false ) AND (fin = false) do
  14.  
  15.   Begin
  16.  
  17.     while (encontrado = false) and (fin = false) do
  18.  
  19.        begin
  20.  
  21.           if bilbioteca[i].alta = false then
  22.           encontrado = true;
  23.           posicionlibre = indice;
  24.  
  25.           else
  26.  
  27.           if indice <> TAMBIBLIOTECA THEN
  28.           indice = indice +1;
  29.  
  30.           else
  31.  
  32.             fin = true;
  33.           end;
  34.  
  35.     end;
  36.  
  37.     begin
  38.  
  39.       if fin = true then
  40.       writel('No hay sitio en la tabla para los libros');
  41.       if encontrado = true then
  42.  
  43. leer datos del libro y meterlos en la posición libre.
  44.  
  45.  

Necesito saber si el código esta bien interpretado y cual me falta es lo último que me queda y la primera vez que hago un procedimiento igual.

un saludo y muchísimas gracias en lo que me podais ayudar.
2  Programación / Programación General / Ayuda procedimiento Pascal en: 20 Abril 2011, 12:46 pm
Vereis tengo una constante cuyo número de libro en la biblioteca es de 50.

Al utilizar este procedimineto que os pongo me salen para introducir datos de libros los 50.

qué código tengo que agregar para que únicamente me salga un libro a introducir y no los 50?

saludos y gracias por anticipado.


Código
  1. PROCEDURE lee_biblioteca(var biblioteca: Tbiblioteca; longitud: integer);
  2.  
  3. var
  4.  
  5. i: integer;
  6.  
  7. begin
  8.  
  9. for i:= 1 to longitud do
  10.  
  11. begin
  12.  
  13. writeln('Introduzca los datos del libro: ' , i);
  14. lee_libro(biblioteca[i]);
  15.  
  16. end;
  17.  
  18. end;
3  Programación / Programación General / procedimiento para dar de baja un registro en Pascal en: 16 Abril 2011, 13:54 pm
Hola de nuevo,
Estoy acabando el programa final de curso. Tengo por último que hacer un procedimiento para dar de baja y modificar un registro.  Me dais pistas de como hacerlo?

saludos
4  Programación / Programación General / Problema con menu de Pascal en: 14 Abril 2011, 13:58 pm
Código
  1.  

Hola de nuevo amigo, al compilar el programa me da dos errores en el menú. Os cuento... tengo un menu para un programa y un submenu que quiero enlazar si es que se puede. He puesto donde me da error cual sería la solución?

gracias y saludos

BEGIN

   repeat
   
      opc:= Menu;
      
      case opc of
      
         1: lee_libro(libro);
         2: busca_datos(biblioteca, TAMBIBLIOTECA, buscado);
         3: lee_prestamos(prestado);
         4: busca_datos(biblioteca, TAMBIBLIOTECA, buscado);
         5: begin
            writeln('Introduzca el nombre del fichero de datos: ');
            readln(nombre);
            graba_fichero(nombre, biblioteca, TAMBIBLIOTECA); 
            end;
         6: begin
            writeln('Introduzca el nombre del fichero: ');
            readln(nombre);
            lee_fichero(nombre, biblioteca, TAMBIBLIOTECA);
            end;
         7: opc1;    (* ME DA ERROR *)
      end;
   until(opc=8);
   
   repeat
      opc1:= Submenu;
      
      case opc1 of
      
         9: imprime_libros(biblioteca, TAMBIBLIOTECA);
         10: imprime_prestados(prestado, TAMBIBLIOTECA);
         11: begin
            writeln('--------------------------------------------------------------');
            writeln('LISTADO DE PRECIOS MAXIMOS, MINIMOS, LA MEDIA Y EL VALOR TOTAL');
            writeln('--------------------------------------------------------------');
            writeln('Valor máximo: ');
            maximo(biblioteca, TAMBIBLIOTECA);
            writeln('Valor mínimo: ');
            minimo(biblioteca, TAMBIBLIOTECA);
            writeln('Valor medio: ');
            media(biblioteca, TAMBIBLIOTECA);
            writeln('Valor total Biblioteca');
            suma_coleccion(biblioteca, TAMBIBLIOTECA);
            end;
         12: opc;   (* ME DA ERROR *)
       end;
   until(opc1=12);
END.
5  Programación / Programación General / pascal que se ha cortedo ejercicio en: 14 Abril 2011, 13:06 pm
Código
  1.  

Necesito me ayudeis a ver que código esta mal preincipalmente el menu. no estoy muy  seguro si es correcto lo que he codificado

PROGRAM Bibliotecas;

(* Tamaño de cada registro que se pide *)

CONST

   TAMMAXI            = 40;
   TAMBIBLIOTECA     = 25;
   
TYPE

(* registro anidado que define las características de cada libro *)

   
   Tprestado = record
      
      nom_apellidos : string [TAMMAXI];
      email         : string [TAMMAXI];
      fecha        : char;
      end;
   
   
   Tlibro = record
         datos  : Tprestado;
         titulo : string [TAMMAXI];
         autor  : string [TAMMAXI];
         tema   : string [TAMMAXI];
         precio : integer;
         alta   : boolean;
      
         end;

   
   
(* -- TABLA SOBRE LA QUE VAMOS A TRABAJAR EN EL PROYECTO BIBLIOTECA --*)

   Tbiblioteca = array[1..TAMBIBLIOTECA] of Tlibro;
      Tfichero = file of Tlibro;

(*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)   
(*!!!!!!!!!!!!!!!!    VARIABLES GLOBALES           !!!!!!!!!!!!!!!!!!!!!!!!*)
(*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)   

VAR

libro     : Tlibro;
prestado  : Tprestado;
biblioteca: Tbiblioteca;
libro_prestado : Boolean;
alta      : Boolean;
fichero   : char;
opc        : integer;
opc1      : integer;
nombre    : string;



(*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)   
(*!!!!!!!!!!!!!!!! FUNCIONES Y PROCEDIMIENTOS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
(*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)   

 (* -- LEE DEL TECLADO TODA LA INFORMACIÓN DE UN LIBRO QUE SE LE PASA--*)

 PROCEDURE lee_libro( var libro: Tlibro);
 
 begin
 
   writeln;
   writeln('Alta o baja (true, false): ');
   readln(libro.alta);
   writeln('Titulo: ');
   readln(libro.titulo);
   writeln('Autor: ');
   readln(libro.autor);
   writeln('Tema: ');
   readln(libro.tema);
   writeln('Precio: ');
   readln(libro.precio);
   writeln;
   
end;

(* PRESENTAR LISTADOS DE LA BIBLIOTECA *)


PROCEDURE imprime_libro(libro: Tlibro); 

begin
                                         
      writeln('--------------------------------------');
      writeln('LISTADO POR LIBRO');
      writeln('--------------------------------------');
      
      writeln('Alta o baja (true o false)',libro.alta);
      writeln('Titulo : ', libro.titulo);
      writeln('Autor : ' , libro.autor);
      writeln('Tema : ', libro.tema);
      writeln('Precio : ',libro.precio);
        writeln;
      writeln('--------------------------------------');
   
end;

PROCEDURE lee_prestamos(var prestado: Tprestado);

begin

   writeln;
   writeln('------------------------------------');
   writeln('INTRODUCIR DATOS PRESTAMO BIBLIOTECA');
   writeln('------------------------------------');
   writeln('Introducir Nombre y Apellidos: ');
   readln(prestado.nom_apellidos);
   writeln('Email: ');
   readln(prestado.email);
   writeln('Fecha del Prestamo: ');
   readln(prestado.fecha);
   writeln;
   
end;

PROCEDURE imprime_prestados(prestado:Tprestado; longitud: integer);

var

   i:  integer;
   
begin

for i:= 1 to longitud do;

   begin
   
      writeln('----------------------------------------');
      writeln('-----LISTADO DE LIBROS PRESTADOS--------');
      writeln('----------------------------------------');
      
lee_prestamos(prestado);
      
   end;
   
end;

(* -- CON ESTE PROCEDIMIENTO PRETENDO BUSCAR Y MODIFICAR SU ESTADO DE ALTA, BAJA O MODIFICAR --*)

PROCEDURE busca_datos( biblioteca: Tbiblioteca; longitud: integer; buscado: char);

var

       i  : integer;
encontrado: Boolean;

begin

encontrado:= false;

for i:= 1 to longitud do

   begin
   
      if biblioteca .titulo = buscado then begin
      imprime_libro(biblioteca);
      encontrado:= true;
      end;
   
   end;
      
   begin
   
      if encontrado = false then begin
      lee_libro(biblioteca);
      end;
      
   end;


end;

(* -- PENDIENTE DE REALIZAR --*)

(* PROCEDURE baja_libro( var libro: Tlibro; longintud: integer);

begin


end; *)

(* -- PENDIENTE DE REALIZAR --*)

(*procedure modificar_datos(var prestado: Tprestado; longitud:integer);

begin



end;*)



(* lISTADOS DE TODOS LOS LIBROS *)

PROCEDURE imprime_libros(biblioteca: Tbiblioteca; longitud: integer);

var

i: integer;

begin

for i:= 1 to longitud do

   begin

      writeln('--------------------------------------');
      writeln('LISTADO DE TODOS LOS LIBROS BIBLIOTECA');
      writeln('--------------------------------------');
      
      imprime_libro(biblioteca);
   
   end;
   
end;



(* FUNCION QUE DEVUELVE EL VALOR TOTAL DE LA COLECCION DE LA BIBLIOTECA *)

FUNCTION suma_coleccion(biblioteca: Tbiblioteca; longitud: integer): real;

var

i: integer;
suma: integer;

begin

suma:= 0;

for i:= 1 to longitud do

   begin
   
      suma:= suma + biblioteca.precio;
      
   end;
   
end;

(* FUNCIÓN QUE DEVUELVE VALOR MÁXIMO DE LA COLECCION DE LA BIBLIOTECA *)

FUNCTION Maximo(bibliooteca: Tbiblioteca; longitud: integer): integer;

var

i: integer;
max: integer;

begin

max:= 0;

for i:= 1 to longitud do

   begin
   
      if max < biblioteca.precio then
         
         max:= biblioteca.precio;
      
         Maximo:= max;
   
   end;
   
end;

(* FUNCION QUE DEVUELVE VALOR MÍNIMO DE LA COLECCION DE LA BIBLIOTECA *)

FUNCTION Minimo(biblioteca: Tbiblioteca; longitud: integer): real;

var

i: integer;
min: integer;

begin

min:= 0;

for i:= 1 to longitud do

   begin
   
      if min > biblioteca.precio then
      
      min:= biblioteca.precio;
      
      Minimo:= min;
   
   end;
   
end;

(* FUNCION QUE DEVUELVE EL VALOR MEDIO DE LA COLECCION DE LA BIBLIOTECA *)

FUNCTION Media(biblioteca: Tbiblioteca; longitud: integer): real;

var

i: integer;
suma_coleccion: integer;

begin

suma_coleccion:= 0;
   
for i:=  1 to longitud do
   
      begin
      
         suma_coleccion:= suma_coleccion + biblioteca.precio;
         Media:= suma_coleccion/1.0+longitud;
      
      end;
      
end;

(*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)   
(*!!!!!!!!!!!!!!!!    Funciones de ficheros   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
(*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)   

(*-- ALMACENA DATOS LEIDOS DE UN FICHERO --*)
 
PROCEDURE graba_fichero(nombre: string; biblioteca: Tbiblioteca; longitud: integer);
Var
  i : integer;
  fichero : Tfichero;
Begin   
  assign(fichero, nombre);
   rewrite(fichero);

for i:= 1 to longitud do
      write(fichero, biblioteca);
      
   close(fichero);
End;

(*-- LEE DATOS DEL FICHERO --*)

PROCEDURE lee_fichero(nombre: string; var biblioteca: Tbiblioteca; longitud: integer);

Var
     i : integer;
fichero : Tfichero;

Begin   
  i := 0;
   
   assign(fichero, nombre);
   reset(fichero);
   
    while ( not(eof(fichero)) AND (i<TAMBIBLIOTECA) ) do begin
    i := i+1;      
    read(fichero, biblioteca);
   
   end;
      
   close(fichero);

   
End;

(*-- FUNCIÓN QUE PRESENTA MENÚ Y DEVUELVE OPCIÓN ELEGIDA --*)

FUNCTION Menu: INTEGER;

VAR

opc: integer;

BEGIN

   repeat
   
      writeln('-----------------------------');
      writeln('MENÚ DE GESTIÓN DE BIBLIOTECA');
      writeln('-----------------------------');
      writeln;
      writeln('1. ALTA DE LIBRO');
      writeln('2. BAJA DE LIBRO');
      writeln('3. DATOS DE PRÉSTAMO');
      writeln('4. MODIFICACIÓN DE DATOS');
      writeln('5. GUARDAR DATOS EN FICHEROS');
      writeln('6. LECTURA DE DATOS DE FICHERO');
      writeln('7. PRESENTACIÓN DE LISTADO DE BIBLIOTECA');
            
      writeln;
      writeln('8. SALIR');
      writeln('OPCION:  ');
      readln(opc);
       until ( (opc>=1) and (opc <=7) or (opc=8)    );

 Menu := opc;
End;   

(*--  FUNCIÓN QUE PRESENTA UN SUBMENU DE LA OPCION 6 DEL MENÚ PRINCIPAL Y DEVUELVE LA OPCION ELEGIDA --*)

FUNCTION submenu: INTEGER;

VAR

opc1: integer;

BEGIN

   repeat
   
      writeln('------------------------------------------');
      writeln('MENÚ PRESENTACIÓN DE LISTADO DE BIBLIOTECA');
      writeln('------------------------------------------');
      writeln;
      writeln('9. LISTADO DE TODOS LOS LIBROS DE LA BIBLIOTECA');
      writeln('10. LISTADO DE LIBROS PRESTADOS');
      writeln('11. LISTADO DE PRECIOS MÁXIMOS, MÍNIMOS, LA MEDIA Y EL VALOR TOTAL DE LA COLECCIÓN');
      writeln;
      writeln('12. VOLVER MENU PRINCIPAL');
      writeln('OPCION: ');
      readln(opc1);
      until ( (opc1>=9) and (opc<=11) or (opc1=12) );

submenu:= opc1;

END;
      
      
   
(*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)   
(*!!!!!!!!!!!!!!!!    PROGRAMA PRINCIPAL          !!!!!!!!!!!!!!!!!!!!!!!!!!!*)
(*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)   

BEGIN

   repeat
   
      opc:= Menu;
      
      case opc of
      
         1: lee_libro(libro);
         2: busca_datos(biblioteca, TAMBIBLIOTECA, buscado);
         3: lee_prestamos(biblioteca);
         4: busca_datos(biblioteca, TAMBIBLIOTECA, buscado);
         5: begin
            writeln('Introduzca el nombre del fichero de datos: ');
            readln(nombre);
            graba_fichero(nombre, biblioteca, TAMBIBLIOTECA);
            end;
         6: begin
            writeln('Introduzca el nombre del fichero: ');
            readln(nombre);
            lee_fichero(nombre, biblioteca, TAMBIBLIOTECA);
            end;
         7: opc1;
      end;
   until(opc=8);
   
   repeat
      opc1:= Submenu;
      
      case opc1 of
      
         9: imprime_libros(biblioteca, TAMBIBLIOTECA);
         10: imprime_prestados(prestado, TAMBIBLIOTECA);
         11: begin
            writeln('--------------------------------------------------------------');
            writeln('LISTADO DE PRECIOS MAXIMOS, MINIMOS, LA MEDIA Y EL VALOR TOTAL');
            writeln('--------------------------------------------------------------');
            writeln('Valor máximo: ');
            maximo(biblioteca, TAMBIBLIOTECA);
            writeln('Valor mínimo: ');
            minimo(biblioteca, TAMBIBLIOTECA);
            writeln('Valor medio: ');
            media(biblioteca, TAMBIBLIOTECA);
            writeln('Valor total Biblioteca');
            suma_coleccion(biblioteca, TAMBIBLIOTECA);
            end;
         12: opc;
       end;
   until(opc1=12);
END.
6  Programación / Programación General / Como cambiar registro Pascal en: 6 Abril 2011, 14:18 pm
Una pregunta , si introduzco un precio por ejemplo en una tabla, (lenguaje Pascal) y quiero borrarlo o modificarlo, como lo hago?

saludos gracias
7  Programación / Programación General / Paso lógico de Pascal a.....cual sería el lenguaje más actual al que se debería en: 5 Abril 2011, 14:20 pm
Si has terminado de estudiar un curso sobre Pascal y te das cuenta de que este no se esta utilizando y tampoco hay mcha gente que digamos a la que preguntar sobre el tema, pues ha dejado de ser utilizado, qué lenguaje de programación sería el más recomendable en nuestros días para continuar estudiando con la base que nos ha dado Pascal. Y sobre todo que sea más utilizado y haya más gente con la que compartir.
8  Programación / Programación General / ejercicio Pascal, ayuda para terminarlo en: 1 Abril 2011, 14:32 pm
NO veo por qué no sumas las líneas de este programa, me podeís ayudar.

Program contar;



var

c: char;
fichero: text;
url_archivo: string;
lineas: integer;
caracteres: integer;



begin
url_archivo:='C:\contar.txt';
assign(fichero, url_archivo);
reset(fichero);
caracteres:=0;
lineas:=0;



begin
   
    while not eof(fichero) do begin
     
         readln(fichero,c);
       caracteres:=caracteres+1;
   
     
     if not eof(fichero) then
   
       lineas:=lineas+1;
         readln(fichero);
     end;

end;
     
writeln('El nombre del fichero es ', url_archivo);
writeln('El numero de lineas es ',lineas);
Writeln('El numero de letras es ',caracteres);


END.
9  Programación / Programación General / Ayuda ejercicio de Pascal, cuando uno no lo ve claro pide ayuda en: 31 Marzo 2011, 14:32 pm
Hola, estoy haciendo un curso de Pascal y como no tengo a quién preguntar pues utilizar otros lenguajes... pues haber si alguno de vosotros me puede ayudar. El ejercicio es este:

Realizar un programa que abra un fichero para lectura, y lo vaya leyendo línea a línea. Deberá presentar como resultado final el nombre del fichero, el número de líneas y el número de caracteres.

ejecutando el archivo contar.exe se tiene que ver así:

Nombre fichero origen: contar.txt
Fichero: contar. txt 
3
30

Gracias de antemano
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines