Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rad sa Stringovima, poredjenje, unos i visestruki upisi i ispisi iz fajlova;
- MODULE StringFajl;
- FROM InOut IMPORT WriteString, WriteLn, ReadInt, WriteInt, ReadString;
- FROM Str IMPORT Compare, Length;
- FROM FIO IMPORT Open, Create, RdStr, WrStr, WrLn, EOF, File, Close;
- CONST duzinaStringa = 20;
- TYPE
- STRING = ARRAY[1..duzinaStringa] OF CHAR;
- VAR
- str1, str2 : STRING;
- veci, int1, k : INTEGER;
- f1, f2 : File;
- PROCEDURE poredi2(str1, str2: STRING): INTEGER; FORWARD;
- PROCEDURE unosZabranaPrazan(VAR str1: STRING; t: INTEGER);
- VAR
- str2: STRING;
- broj : INTEGER;
- ponovo : BOOLEAN;
- BEGIN
- str2 := "";
- ponovo := FALSE;
- REPEAT
- IF (ponovo) THEN
- WriteString("Ponovni unos ");
- WriteInt(t,0);
- WriteString(". stringa u fajl: ");
- ELSE
- WriteString("Unos ");
- WriteInt(t,0);
- WriteString(". stringa u fajl: ");
- END;
- ponovo := TRUE;
- ReadString(str1); WriteLn;
- broj := poredi2(str1,str2);
- UNTIL(broj # 0);
- END unosZabranaPrazan;
- (*poredi leksikografski stra < strb*)
- PROCEDURE poredi1(str1, str2 : STRING): INTEGER;
- BEGIN
- IF (Compare(str1,str2) = 0) THEN
- RETURN 0
- ELSIF (Compare(str1,str2) > 0) THEN
- RETURN 1
- ELSIF (Compare(str1,str2) < 0) THEN
- RETURN -1
- END;
- END poredi1;
- (*Poredi po duzini stra = strb*)
- PROCEDURE poredi2(str1, str2 : STRING): INTEGER;
- VAR
- duz1, duz2 : INTEGER;
- BEGIN
- duz1 := Length(str1);
- duz2 := Length(str2);
- IF (duz1 = duz2) THEN
- RETURN 0
- ELSIF (duz1 > duz2) THEN
- RETURN 1
- ELSIF (duz1 < duz2) THEN
- RETURN -1
- END;
- END poredi2;
- (*Odabir poredjenja (poredi1 V poredi2)*)
- PROCEDURE poredi0(str1,str2 : STRING; broj: INTEGER): INTEGER;
- BEGIN
- IF broj = 1 THEN
- RETURN poredi1(str1,str2)
- ELSE
- RETURN poredi2(str1,str2)
- END
- END poredi0;
- PROCEDURE ispis(broj: INTEGER);
- BEGIN
- IF (broj = 0) THEN
- WriteString(str1); WriteString(" je jednak sa ");
- WriteString(str2);
- WriteLn
- ELSIF (broj > 0) THEN
- WriteString(str1); WriteString(" je veci od ");
- WriteString(str2);
- WriteLn
- ELSE
- WriteString(str1); WriteString(" je manji od");
- WriteString(str2);
- WriteLn
- END
- END ispis;
- PROCEDURE kojePoredjenje(VAR br: INTEGER);
- BEGIN
- WriteString("Da li zelite poredjenje 1 ili 2: ");
- ReadInt(br); WriteLn;
- END kojePoredjenje;
- PROCEDURE upisFajlBezPraznog(VAR f: File; VAR n: INTEGER);
- VAR
- str : STRING;
- i : INTEGER;
- BEGIN
- WriteString("Unesite broj redova: ");
- ReadInt(n); WriteLn;
- FOR i := 1 TO n DO
- unosZabranaPrazan(str, i);
- WrStr(f,str);
- WrLn(f);
- WriteLn;
- WriteLn
- END
- END upisFajlBezPraznog;
- PROCEDURE citajFajl1(f: File; n : INTEGER);
- VAR
- str : STRING;
- i : INTEGER;
- BEGIN
- WriteString("Ispis iz fajla "); WriteLn;
- EOF := FALSE;
- FOR i := 1 TO n DO
- RdStr(f,str);
- WriteString("String u ");
- WriteInt(i,0);
- WriteString(". redu iz fajla je: ");
- WriteString(str);
- WriteLn
- END
- END citajFajl1;
- PROCEDURE citajFajl2(f: File;k: INTEGER);
- VAR
- str1, str2 : STRING;
- i, broj : INTEGER;
- BEGIN
- WriteString("Ispis iz fajla "); WriteLn;
- EOF := FALSE;
- str2 := "";
- i := 0;
- WHILE (NOT EOF) DO
- RdStr(f,str1);
- INC(i);
- broj := poredi2(str1, str2);
- IF ((broj # 0) AND (i # (k+1))) THEN
- WriteString("String u ");
- WriteInt(i,0);
- WriteString(". redu iz fajla je: ");
- WriteString(str1);
- WriteLn
- END
- END
- END citajFajl2;
- BEGIN
- f1 := Create("fajlZaModulu7.txt");
- upisFajlBezPraznog(f1,k);
- Close(f1);
- f2 := Open("fajlZaModulu7.txt");
- citajFajl1(f2,k);
- Close(f2);
- (*Ubaciti zeljene procedure*)
- END stringFajl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement