Advertisement
ridjis

zadatak 3.11b

Jun 4th, 2014
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MODULE zad311b;
  2.  
  3. FROM InOut IMPORT WriteLn,WriteString,ReadString,WriteInt;
  4. FROM FIO IMPORT File,Close,Open,Create,RdCard,WrCard,EOF,WrLn;
  5. FROM Stek IMPORT StekTip,Top,Pop,Push,Empty,MakeNull;
  6.  
  7. CONST br2 = "br2.txt";
  8.  
  9. VAR str : ARRAY [1..256] OF CHAR;
  10.     s1,s2:StekTip;
  11.     ok:BOOLEAN;
  12.  
  13. PROCEDURE Ucitaj(imeF:ARRAY OF CHAR; VAR s1,s2:StekTip; VAR ok:BOOLEAN);
  14. VAR f:File;
  15.     m:CARDINAL;
  16. BEGIN
  17.   MakeNull(s1);
  18.   MakeNull(s2);
  19.   EOF:=FALSE;
  20.   f:=Open(imeF);
  21.   WHILE NOT EOF DO
  22.     m:=RdCard(f);
  23.     Push(s1,m,ok);
  24.     m:=RdCard(f);
  25.     Push(s2,m,ok);
  26.   END;
  27.   Close(f);
  28. END Ucitaj;
  29.  
  30. PROCEDURE Ispis(stek:StekTip;VAR ok:BOOLEAN);
  31. VAR n:CARDINAL;
  32. BEGIN
  33.   WHILE NOT Empty(stek) DO
  34.     Top(stek,n,ok);
  35.     Pop(stek,ok);
  36.     WriteInt(n,1);
  37.     WriteLn;
  38.   END;
  39. END Ispis;
  40.  
  41. PROCEDURE Deli4(VAR stek:StekTip; VAR ok:BOOLEAN);
  42. VAR n:CARDINAL;
  43.     m:BOOLEAN;
  44. BEGIN
  45.   m:=TRUE;
  46.   WHILE m AND NOT Empty(stek) DO
  47.     Top(stek,n,ok);
  48.     IF (n MOD 4 = 0) THEN
  49.       Pop(stek,ok);
  50.     ELSE
  51.       m:=FALSE;
  52.     END;
  53.   END;
  54. END Deli4;
  55.  
  56. PROCEDURE UkloniAko(VAR stek:StekTip;VAR ok:BOOLEAN);
  57.   PROCEDURE Zbir(n:CARDINAL):CARDINAL;
  58.   VAR temp,suma:CARDINAL;
  59.   BEGIN
  60.     suma:=0;
  61.     REPEAT
  62.       temp:=n MOD 10;
  63.       suma:=temp + suma;
  64.       n:= n DIV 10;
  65.     UNTIL n=0;
  66.     RETURN suma;
  67.   END Zbir;
  68.  
  69. VAR x,y:CARDINAL;
  70.     m:BOOLEAN;
  71. BEGIN
  72.   m:=TRUE;
  73.   WHILE m AND NOT Empty(stek) DO
  74.     Top(stek,x,ok);
  75.     Pop(stek,ok);
  76.     Top(stek,y,ok);
  77.     IF (Zbir(x) < y) OR Empty(stek) THEN
  78.       Push(stek,x,ok);
  79.       m:=FALSE;
  80.     END;
  81.   END;
  82. END UkloniAko;
  83.  
  84. PROCEDURE Snimi(imeF:ARRAY OF CHAR; VAR stek:StekTip; VAR ok:BOOLEAN);
  85. VAR f:File;
  86.     n:CARDINAL;
  87. BEGIN
  88.   EOF:=FALSE;
  89.   f:=Create(imeF);
  90.   WHILE NOT Empty(stek) DO
  91.     Top(stek,n,ok);
  92.     Pop(stek,ok);
  93.     WrCard(f,n,0);
  94.     WrLn(f);
  95.   END;
  96.   Close(f);
  97. END Snimi;
  98.  
  99. BEGIN
  100.  
  101.   Ucitaj(br2,s1,s2,ok);
  102.  
  103.   WriteString('Uklanja brojeve iz prvog steka, ako su deljivi sa 4: ');
  104.   WriteLn;
  105.   Deli4(s1,ok);
  106.  
  107.   Ispis(s1,ok);
  108.   WriteLn;
  109.  
  110.   WriteString('Uklanja brojeve iz drugog steka, ako je zbir cif > sledbenika: ');
  111.   WriteLn;
  112.   UkloniAko(s2,ok);
  113.  
  114.   Ispis(s2,ok);
  115.   WriteLn;
  116.  
  117.   WriteString('Unesite ime 1. fajla: ');
  118.   ReadString(str);
  119.   Snimi(str,s1,ok);
  120.  
  121.   WriteString('Unesite ime 2. fajla: ');
  122.   ReadString(str);
  123.   Snimi(str,s2,ok);
  124.  
  125. END zad311b.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement