popelka

Pascal Bank

Mar 27th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.07 KB | None | 0 0
  1. JEDNOTKA:
  2. unit unit_bank;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.   type ZAZNAM = record CISLO: word;
  8.                        JMENO: string[100];
  9.                        STAV: integer;
  10.                 end;
  11.        SOUBOR = file of ZAZNAM;
  12.        UCET = packed object
  13.             PRIVATE
  14.              HELP:ZAZNAM;
  15.             PUBLIC
  16.              S:SOUBOR;
  17.              procedure NOVY;
  18.              procedure VLOZ;
  19.              procedure VYBER;
  20.              function ZRUSIT: boolean;
  21.              procedure VYBRATUCET;
  22.              function NABIDKA:boolean;
  23.              procedure ZAPSAT;
  24.                       end;
  25.   function vicjaknula(x: integer): boolean;
  26.  
  27. implementation
  28.   procedure UCET.NOVY;
  29.    begin
  30.      write('Jmeno majitele: '); readln(HELP.JMENO);
  31.      write('Cislo uctu: '); readln(HELP.CISLO);
  32.      write('Pocatecni castka: '); readln(HELP.STAV);
  33.      seek(S,filesize(S));
  34.      write(S,HELP);
  35.      help.cislo:=high(word); help.STAV:=low(integer); help.JMENO:=' ';
  36.      write(S,HELP);
  37.    end;
  38.  
  39.   function vicjaknula(x: integer): boolean;
  40.          begin
  41.            if x>0 then result:=true
  42.             else result:=false
  43.          end;
  44.  
  45.   procedure UCET.VYBRATUCET;
  46.    var A: word; C: ZAZNAM; ok: boolean;
  47.    begin
  48.      write('Napiste cislo uctu: '); readln(A);
  49.      ok:=false;
  50.      while (filepos(S)<>(filesize(S)-1)) or OK do
  51.        begin
  52.          read(S, C);
  53.          if C.CISLO = A then OK:=true
  54.        end;
  55.      if not(OK) then write('Ucet nebyl nalezen.')
  56.       else
  57.         begin
  58.           seek(S,filepos(S)-1);
  59.           read(S,HELP);
  60.           seek(S,filepos(S)-1);
  61.         end
  62.    end;
  63.  
  64.   procedure UCET.VLOZ;
  65.    var kolik:word;
  66.   begin
  67.     write('Vkladana hodnota: '); read(kolik); writeln('Kc');
  68.   end;
  69.  
  70.   function UCET.ZRUSIT: boolean;
  71.   var H:ZAZNAM;
  72.   begin
  73.     H.CISLO:=0; H.JMENO:=' '; H.STAV:=0;
  74.     write(S,H);
  75.     result:=true
  76.   end;
  77.  
  78.   procedure UCET.VYBER;
  79.    var kolik:word;
  80.   begin
  81.     if vicjaknula(help.stav) then
  82.       begin
  83.         repeat
  84.           write('Vybrat castku: '); read(kolik); writeln('Kc');
  85.           if (kolik>=HELP.STAV) or (kolik<0) then
  86.             writeln('Spatne zapsana hodnota.');
  87.         until (kolik>0) and (kolik<=HELP.STAV);
  88.         HELP.STAV:=HELP.STAV-kolik
  89.       end;
  90.   end;
  91.  
  92.   function UCET.NABIDKA: boolean;
  93.    var VOLBA:byte;
  94.   begin
  95.     NABIDKA:=false;
  96.     writeln('Cislo uctu: ',HELP.CISLO);
  97.     writeln('Jmeno vlastnika: ',HELP.JMENO);
  98.     writeln('Zustatek: ',HELP.STAV);
  99.     writeln('Nabidka moznosti:');
  100.     writeln('  0. nic');
  101.     writeln('  1. Vklad');
  102.     writeln('  2. Vyber');
  103.     writeln('  3. Zrusit ucet');
  104.     write('Vase volba: '); readln(VOLBA); writeln;
  105.     case volba of
  106.      1:UCET.VLOZ;
  107.      2:UCET.VYBER;
  108.      3:UCET.ZRUSIT;
  109.      else result:=true
  110.     end;
  111.   end;
  112.  
  113.   procedure UCET.ZAPSAT;
  114.    begin
  115.     if not(ZRUSIT) then write(S,HELP);
  116.    end;
  117. end.
  118.  
  119. /////////////////////////////////////////////////////////////////
  120.  
  121. PROGRAM:
  122. program bank;
  123.  
  124. {$mode objfpc}{$H+}
  125.  
  126. uses
  127.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  128.   cthreads,
  129.   {$ENDIF}{$ENDIF}
  130.   Classes, unit_bank, sysutils
  131.   { you can add units after this };
  132.  
  133. var CO: string; B: UCET;
  134.  
  135. function nabidka: boolean;
  136.  begin
  137.   nabidka:=true;
  138.   writeln('Novy ucet, nebo vybrat existujici ucet?');
  139.   write('Napiste: ''vybrat'', nebo ''novy'': '); readln(CO);
  140.    if (CO = 'vybrat') or (CO = 'VYBRAT') or (CO = 'Vybrat') then
  141.                          begin
  142.                            B.VYBRATUCET;
  143.                            repeat B.NABIDKA
  144.                            until B.NABIDKA
  145.                          end
  146.    else if (CO = 'novy') or (CO = 'NOVY') or (CO = 'Novy') then
  147.                             begin
  148.                              B.NOVY
  149.                             end
  150.    else nabidka:=false
  151.  end;
  152.  
  153. begin
  154.   assign(B.S,'banksoubor');
  155.   if not(fileexists('banksoubor')) then rewrite(B.S)
  156.                                    else reset(B.S);
  157.   while nabidka do nabidka;
  158.  
  159.  
  160.  
  161.  writeln; writeln;
  162.  writeln('Konec programu.');
  163.  write('Pro ukonceni programu stisknete ''ENTER''');
  164.  readln
  165. end.
Add Comment
Please, Sign In to add comment