Advertisement
ridjis

zadatak 3.10b

Jun 4th, 2014
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MODULE zad310b;
  2.  
  3. FROM InOut IMPORT WriteLn,WriteString,ReadString;
  4. FROM RealInOut IMPORT WriteReal;
  5. FROM FIO IMPORT File,Close,Open,Create,RdReal,WrReal,EOF,WrLn;
  6. FROM RedOpsl IMPORT RedOpslTip,First,PopFirst,AddRear,Empty,MakeNull;
  7.  
  8. CONST r1 = "re1.txt";
  9.       r2 = "re2.txt";
  10.  
  11. VAR str : ARRAY [1..256] OF CHAR;
  12.     red1,red2:RedOpslTip;
  13.     ok:BOOLEAN;
  14.     suma:REAL;
  15.  
  16. PROCEDURE UcitajRed(imeF:ARRAY OF CHAR;VAR red:RedOpslTip; VAR ok:BOOLEAN);
  17. VAR f:File;
  18.     n:REAL;
  19. BEGIN
  20.   MakeNull(red);
  21.   f:=Open(imeF);
  22.   EOF:=FALSE;
  23.   WHILE NOT EOF DO
  24.     n:=RdReal(f);
  25.     AddRear(red,n,ok);
  26.   END;
  27.   Close(f);
  28. END UcitajRed;
  29.  
  30. PROCEDURE BezDecimala(VAR red:RedOpslTip; VAR ok:BOOLEAN; VAR suma:REAL);
  31. VAR n:REAL;
  32.     m:BOOLEAN;
  33. BEGIN
  34.   m:=TRUE;
  35.   suma:=0.;
  36.   WHILE m AND NOT Empty(red) DO
  37.     First(red,n,ok);
  38.     IF n = FLOAT(TRUNC(n)) THEN
  39.       suma:=suma+n;
  40.       PopFirst(red,ok);
  41.     ELSE
  42.       m:=FALSE;
  43.     END;
  44.   END;
  45. END BezDecimala;
  46.  
  47. PROCEDURE DodajNaKraj(VAR red:RedOpslTip; VAR ok:BOOLEAN; VAR suma:REAL);
  48. BEGIN
  49.   AddRear(red,suma,ok);
  50. END DodajNaKraj;
  51.  
  52. PROCEDURE Ispis(red:RedOpslTip;VAR ok:BOOLEAN);
  53. VAR n:REAL;
  54. BEGIN
  55.   WHILE NOT Empty(red) DO
  56.     First(red,n,ok);
  57.     WriteReal(n,1);
  58.     WriteLn;
  59.     PopFirst(red,ok);
  60.   END;
  61. END Ispis;
  62.  
  63. PROCEDURE Sacuvaj(imeF:ARRAY OF CHAR; VAR red:RedOpslTip;VAR ok:BOOLEAN);
  64. VAR f:File;
  65.     n:REAL;
  66. BEGIN
  67.   f:=Create(imeF);
  68.   WHILE NOT Empty(red) DO
  69.     First(red,n,ok);
  70.     PopFirst(red,ok);
  71.     WrReal(f,n,3,1);
  72.     WrLn(f);
  73.   END;
  74.   Close(f);
  75. END Sacuvaj;
  76.  
  77. BEGIN
  78.   UcitajRed(r1,red1,ok);
  79.   UcitajRed(r2,red2,ok);
  80.  
  81.   BezDecimala(red1,ok,suma);
  82.   Ispis(red1,ok);
  83.   WriteLn;
  84.  
  85.   DodajNaKraj(red2,ok,suma);
  86.   Ispis(red2,ok);
  87.   WriteLn;
  88.  
  89.   WriteString('Unesite ime fajla: '); //izlaz1.txt
  90.   ReadString(str);
  91.   Sacuvaj(str,red1,ok);
  92.  
  93.   WriteString('Unesite ime fajla 2: '); //izlaz2.txt
  94.   ReadString(str);
  95.   Sacuvaj(str,red2,ok);
  96.  
  97. END zad310b.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement