Pascal/Turbo Pascal - Ayuda para corregir el programa de inventario

 
Vista:

Ayuda para corregir el programa de inventario

Publicado por Braulio (1 intervención) el 04/05/2016 00:10:54
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
PROGRAM Ej501 (input, output, inventario);
{Gestion de inventario de farmacia}
CONST
    MAX_NOMBRE_PROD = 20;
    MAX_NOMBRE_LAB = 30;
TYPE
    tipoNombreMedicina = PACKED ARRAY[1..MAX_NOMBRE_PROD] OF char;
    tipoNombreLab = PACKED ARRAY[1..MAX_NOMBRE_LAB] OF char;
    tipoFecha = RECORD
                    dia : 1..31;
                    mes : 1..12;
                    anyo: 2000..2999;
                END{tipoFecha};
    tipoID = integer;
    tipoStock = integer;
    tipoPrecio = real;
    tipoMedicina =  RECORD
                        nombre  : tipoNombreMedicina;
                        lab     : tipoNombreLab;
                        ident   : tipoID;
                        precio  : tipoPrecio;
                        caducidad: tipoFecha;
                        stock   : tipoStock;
                    END{tipoMedicina};
    tipoFicheroFarmacia = FILE OF tipoMedicina;
VAR
    medicina     : tipoMedicina;
    ficheroDatos : tipoFicheroFarmacia;
    Num_Medicamentos: integer;{Numero de productos diferentes anyadidos al fichero de datos.}
    seleccion : 0..3;
 
PROCEDURE Menu();
    {Muestra menu de opciones del programa
    Acepta: Nada.
    Devuelve: Muestra las opciones por pantalla.
    }
    BEGIN
        WRITELN('_____________MENU______________');
        WRITELN('1 Introducir medicamento.');
        WRITELN('2 Mostrar numero de medicamentos introducidos.');
        WRITELN('3 Calcular total productos en stock.');
        WRITELN('Nota: Solo creacion del fichero (no modificacion)');
        WRITELN('0 Salir');
    END;
 
PROCEDURE IntroducirMedicina (VAR medicina: tipoMedicina; VAR ficheroDatos:tipoFicheroFarmacia ; VAR Num_Medicamentos: integer);
    {Introduce un registro tipoMedicina en el fichero e incrementa el registro de productos introducidos.
    Acepta: medicamento a introducir en el fichero y fichero
    Devuelve: Numero de medicamentos introducidos y fichero modificado.
    }
    VAR
        i: 1..MAX_NOMBRE_PROD;
    BEGIN
        WRITE('Nombre producto? ');
        i:= 1;
        REPEAT
            READ(medicina.nombre[i]);
            i:=i+1;
        UNTIL(i>=MAX_NOMBRE_PROD) OR (eoln()=TRUE);
        READLN;
 
        WRITE('Nombre laboratorio? ');
        i:= 1;
        REPEAT
            READ(medicina.lab[i]);
            i:=i+1;
        UNTIL(i>=MAX_NOMBRE_LAB) OR (eoln()=TRUE);
        READLN;
 
        WRITE('Identificador del producto? ');
        READ(medicina.ident);
 
        WRITE('Precio unitario? ');
        READ(medicina.precio);
 
        WRITELN('Fecha de caducidad:');
        REPEAT
            WRITE('    - Dia (1..31)? ');
            READLN(medicina.caducidad.dia);
        UNTIL (medicina.caducidad.dia >=1) AND (medicina.caducidad.dia <=31);
        REPEAT
            WRITE('    - Mes (1..12)? ');
            READLN(medicina.caducidad.mes);
        UNTIL (medicina.caducidad.mes >= 1 ) AND (medicina.caducidad.mes <= 12);
        WRITE('    - Anyo? ');
        READLN(medicina.caducidad.anyo);
 
        WRITE('Cantidad en stock? ');
        READ(medicina.stock);
 
        WRITE(ficheroDatos, medicina);
        Num_Medicamentos:= Num_Medicamentos +1;
        WRITELN(Num_Medicamentos, ' introducidos.');
    END;
 
FUNCTION CalcularStock(VAR ficheroDatos: tipoFicheroFarmacia ; num_med: integer): integer;
    {Lee todos los registros del fichero y calcula el stock total de productos almacenados.
    Acepta: Fichero de registros y una variable tipoMedicina.
    Devuelve: El registro en la variable tipoMedicina.
    }
    VAR
        med: tipoMedicina;
        i: integer;
    BEGIN
        CalcularStock:=0;
        RESET(ficheroDatos);
        FOR i:=1 TO num_med DO
        BEGIN
            READ(ficheroDatos, med);
            CalcularStock:=CalcularStock + med.stock;
        END;
    END;
 
BEGIN
    ASSIGN (ficheroDatos, 'c:\datos_ej501-pascal.data');{Instruccion no standard de PASCAL}
    REWRITE(ficheroDatos);  {Solo podemos crear el fichero, no modificarlo!!}
                            {El fichero de datos se destruira si ya existe!!}
    Num_medicamentos := 0;
    REPEAT
        Menu();
        READLN(seleccion);
        CASE seleccion OF
            1:  IntroducirMedicina(medicina, ficheroDatos, Num_Medicamentos);
            2:  WRITELN('Numero total de productos introducidos hasta el momento: ', Num_Medicamentos);
            3:  BEGIN
                    WRITELN('________________Stock________________');
                    WRITELN('Num. Medicamentos disponibles: ', Num_medicamentos);
                    WRITELN('Stock total: ', CalcularStock(ficheroDatos, Num_medicamentos));
                END;
        END{CASE};
    UNTIL (seleccion=0);
    CLOSE(ficheroDatos);
END.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
-1
Responder
Imágen de perfil de xve

Ayuda para corregir el programa de inventario

Publicado por xve (25 intervenciones) el 04/05/2016 07:24:55
Hola Braulio, que problema tienes, o que error te da??
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda para corregir el programa de inventario

Publicado por Braulio (1 intervención) el 05/05/2016 15:26:51
al compilar me sale source.pas(110,42) error:incompatible types: got "CalcularStock(va tipo ficheroFarmacia. Small
y source.pas(133,4) fatal: there were 1 errors compiling module, stopping
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda para corregir el programa de inventario

Publicado por ramon (2158 intervenciones) el 05/05/2016 18:16:18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
{Mira Fijate en esto tus datos son registros no texto}
 
PROGRAM Ej501;
uses
  crt;
{Gestion de inventario de farmacia}
CONST
    MAX_NOMBRE_PROD = 20;
    MAX_NOMBRE_LAB = 30;
    nombrefichero = 'c:\dato_501.dat';
TYPE
    tipoNombreMedicina = PACKED ARRAY[1..MAX_NOMBRE_PROD] OF char;
    tipoNombreLab = PACKED ARRAY[1..MAX_NOMBRE_LAB] OF char;
    tipoFecha = RECORD
                    dia : 1..31;
                    mes : 1..12;
                    anyo: 2000..2999;
                END{tipoFecha};
    tipoID = integer;
    tipoStock = integer;
    tipoPrecio = real;
    tipoMedicina =  RECORD
                        nombre  : tipoNombreMedicina;
                        lab     : tipoNombreLab;
                        ident   : tipoID;
                        precio  : tipoPrecio;
                        caducidad: tipoFecha;
                        stock   : tipoStock;
                    END{tipoMedicina};
    tipoFicheroFarmacia = FILE OF tipoMedicina;
  VAR
    medicina     : tipoMedicina;
    ficheroDatos : tipoFicheroFarmacia;
    Num_Medicamentos: integer;{Numero de productos diferentes anyadidos al fichero de datos.}
    seleccion : 0..3;
    archi : boolean;
 
 
  procedure guardaregistro(fdet : tipoMedicina);
  begin
     assign(ficheroDatos,nombrefichero);
   {$I-} reset(ficheroDatos); {$I+}
        if ioresult <> 0 then
        begin
          rewrite(ficheroDatos);
          seek(ficheroDatos,0);
          write(ficheroDatos,fdet);
          close(ficheroDatos);
        end
    else
       begin
          seek(ficheroDatos,filesize(ficheroDatos));
          write(ficheroDatos,fdet);
          close(ficheroDatos);
       end;
  end;
 
  PROCEDURE IntroducirMedicina (VAR medicina: tipoMedicina; VAR ficheroDatos:tipoFicheroFarmacia ;
                              VAR Num_Medicamentos: integer);
    {Introduce un registro tipoMedicina en el fichero e incrementa el registro de productos introducidos.
    Acepta: medicamento a introducir en el fichero y fichero
    Devuelve: Numero de medicamentos introducidos y fichero modificado.
    }
    VAR
        i : integer;
        tel : char;
    BEGIN
      i := 1;
      repeat
        clrscr;
        writeln('  Finaliza Entradas Tecla ESC O ',MAX_NOMBRE_PROD);
        WRITE('Nombre producto? ');
        READln(medicina.nombre[i]);
        WRITE('Nombre laboratorio? ');
        READln(medicina.lab[i]);
        WRITE('Identificador del producto? ');
        READln(medicina.ident);
        WRITE('Precio unitario? ');
        READln(medicina.precio);
        WRITELN('Fecha de caducidad:');
        WRITE('    - Dia (1..31)? ');
        READLN(medicina.caducidad.dia);
        WRITE('    - Mes (1..12)? ');
        READLN(medicina.caducidad.mes);
        WRITE('    - Anyo? ');
        READLN(medicina.caducidad.anyo);
        WRITE('Cantidad en stock? ');
        READln(medicina.stock);
        Num_Medicamentos := Num_Medicamentos + 1;
        guardaregistro(medicina);
        WRITELN(Num_Medicamentos, ' introducidos.');
        archi := true;
        i := i + 1;
        tel := readkey;
      until (i > MAX_NOMBRE_PROD) or (tel = #27);
    END;
 
   FUNCTION CalcularStock(VAR ficheroDatos: tipoFicheroFarmacia ; num_med: integer): integer;
    {Lee todos los registros del fichero y calcula el stock total de productos almacenados.
    Acepta: Fichero de registros y una variable tipoMedicina.
    Devuelve: El registro en la variable tipoMedicina.
    }
    VAR
        med: tipoMedicina;
        it : longint;
        stop : integer;
    BEGIN
            assign(ficheroDatos,nombrefichero);
      {$I-} reset(ficheroDatos); {$I+}
        if ioresult <> 0 then
        begin
           writeln('   Error De Archivo O No Existe Pulse Una Tecla');
           readkey;
        end
      else
          begin
            stop := 0;
            for it := 0 to filesize(ficheroDatos) - 1 do
            begin
            seek(ficheroDatos,it);
            READ(ficheroDatos, med);
            stop := stop + med.stock;
            end;
            CalcularStock := stop;
            close(ficheroDatos);
        end;
    END;
 
  PROCEDURE Menu;
  var
    tecla : char;
    {Muestra menu de opciones del programa
    Acepta: Nada.
    Devuelve: Muestra las opciones por pantalla.
    }
    BEGIN
      repeat
        clrscr;
        WRITELN('_____________MENU______________');
        WRITELN('1 = Introducir medicamento.');
        WRITELN('2 = Mostrar numero de medicamentos introducidos.');
        WRITELN('3 = Calcular total productos en stock.');
        WRITELN('    Nota: Solo creacion del fichero (no modificacion)');
        WRITELN('0 = Salir');
        repeat
           tecla := readkey;
        until tecla in['1','2','3','0'];
        clrscr;
    CASE tecla OF
 '1' :  IntroducirMedicina(medicina, ficheroDatos, Num_Medicamentos);
 '2' :  WRITELN('Numero total de productos introducidos hasta el momento: ',
             Num_Medicamentos);
 '3' :  BEGIN
          WRITELN('________________Stock________________');
          WRITELN('Num. Medicamentos disponibles: ', Num_medicamentos);
          WRITELN('Stock total: ', CalcularStock(ficheroDatos,
          Num_medicamentos));
          END;
    END{CASE};
    until tecla = '0';
    if archi = true then
    erase(ficheroDatos);
 END;
 
 
BEGIN
    archi := false;
    Num_medicamentos := 0;
    menu;
END.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar