Advertisement
Guest User

LL

a guest
Oct 18th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.25 KB | None | 0 0
  1. program Project1;
  2.  
  3. uses
  4.    crt;
  5. type
  6.   REmpleado=record
  7.     nombre:String[50];
  8.     sueldo:real;
  9.     categoria:string;
  10.   end;
  11. TVector=array[1..100] of REmpleado;
  12. var
  13.   Fichero:text;
  14.   opc:Integer;
  15.   empleados:TVector;
  16.   linea:string;
  17.   procedure CargarFichero(var Fichero:text);
  18.   var
  19.     cadena,nombre,strsueldo,categoria:string;
  20.     resp:string;
  21.     begin
  22.             rewrite(fichero);
  23.             writeln(Fichero,('Nombre Sueldo Categoria'));
  24.             resp:='s';
  25.             while (resp='s') do
  26.                   begin
  27.                   clrscr;
  28.                   writeln('Ingrese Nombre');
  29.                   readln(nombre);
  30.                   writeln('Ingrese Sueldo');
  31.                   readln(strsueldo);
  32.                   writeln('Ingrese Categoria (A/B)');
  33.                   readln(categoria);
  34.                   cadena:=nombre+chr(9)+strsueldo+chr(9)+categoria;
  35.                    writeln(Fichero,cadena)  ;
  36.                   writeln('Desea seguir ingresando? s/n');
  37.                   readln(resp);
  38.                   end;
  39.             close(Fichero);
  40.     end;
  41.  
  42.   procedure mostrarFichero(var Fichero:text)  ;
  43.   var
  44.     nombre:String[50];
  45.     categoria:string;
  46.     sueldo:String;
  47.     p:integer;
  48.     begin
  49.             clrscr;
  50.             {$I-}
  51.             reset(Fichero);
  52.             {$I-}
  53.             if (IOResult<>0)then
  54.                begin
  55.                     writeln('No se pudo acceder al fichero');
  56.                     readkey;
  57.                end
  58.             else
  59.             begin
  60.               readln(Fichero,linea);
  61.               writeln(linea);
  62.               writeln('*---------------------*');
  63.               while (not eof(Fichero)) do
  64.                     begin
  65.                        readln(Fichero,linea);
  66.                        //Nombre---------------------
  67.                        p:=pos(chr(9),linea);
  68.                        nombre:= copy(linea,1,p-1);
  69.                        delete(linea,1,p);
  70.                        //Sueldo---------------------
  71.                        p:=pos(chr(9),linea);
  72.                        sueldo:= copy(linea,1,p-1);
  73.                        delete(linea,1,p);
  74.                        //Categoria------------------
  75.                        categoria:=linea;
  76.                        Writeln(nombre,'   ',sueldo,'    ',categoria);
  77.                     end;
  78.             close(Fichero);
  79.             readkey;
  80.             end;
  81.     end;
  82.  procedure SumarCatB(var Fichero:text)  ;
  83.   var
  84.     categoria:string;
  85.     sueldo:String;
  86.     p,ct,a,x,codigo:integer;
  87.     begin
  88.             clrscr;
  89.             {$I-}
  90.             reset(Fichero);
  91.             {$I-}
  92.             if (IOResult<>0)then
  93.                begin
  94.                     writeln('No se pudo acceder al fichero');
  95.                     readkey;
  96.                end
  97.             else
  98.             begin
  99.               readln(Fichero,linea);
  100.               ct:=0;
  101.               x:=0;
  102.               while (not eof(Fichero)) do
  103.                     begin
  104.                        readln(Fichero,linea);
  105.                        p:=pos(chr(9),linea);
  106.                        delete(linea,1,p);
  107.                        p:=pos(chr(9),linea);
  108.                        sueldo:= copy(linea,1,p-1);
  109.                        delete(linea,1,p);
  110.                        //Categoria------------------
  111.                        categoria:=linea;
  112.                        if categoria='b'then
  113.                           begin
  114.                           Val(sueldo,x,codigo) ;
  115.                        ct:=ct+x ;
  116.                       end;
  117.                     end;
  118.               Writeln('La suma de sueldos de categoria B es: ',ct);
  119.             close(Fichero);
  120.             readkey;
  121.             end;
  122.     end;
  123. Procedure menu(var opc:integer);
  124. begin
  125.        clrscr;
  126.        writeln('1.- Cargar Archivo');
  127.        writeln('2.- Mostras Lista');
  128.        writeln('3.- Sumatoria de Sueldos de Categoria B');
  129.        writeln('0.- Salir');
  130.        readln(opc)    ;
  131.         end;
  132. begin
  133.       assign (Fichero,'C:\Fichero.txt');
  134.       repeat
  135.         menu(opc);
  136.        case opc of
  137.       0:writeln('Fin');
  138.       1:CargarFichero(Fichero);
  139.       2:mostrarFichero(Fichero) ;
  140.       3:SumarCatB(Fichero) ;
  141.       else
  142.         writeln('Opcion invalida');
  143.        end;
  144.       until opc=0;
  145. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement