Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Unos, ispis Studenata
- MODULE vf;
- FROM InOut IMPORT WriteString, WriteLn, ReadInt, WriteInt, ReadString, Write;
- FROM Str IMPORT Compare, Length;
- FROM FIO IMPORT Open, Create, RdStr, WrStr, WrLn, EOF, File, Close, WrInt, RdInt;
- CONST
- MaxString = 20;
- Maxstud = 100;
- fajl = "nekifajl7.txt";
- TYPE
- STRING = ARRAY[0..MaxString] OF CHAR;
- STUDENT = RECORD
- ime : STRING;
- prezime : STRING;
- godiste : INTEGER
- END;
- STUDENTI = ARRAY[0..Maxstud] OF STUDENT;
- VAR
- studenti : STUDENTI;
- f1, f2 : File;
- brStudenata, brUnosa : INTEGER;
- str1, str2 : STRING;
- mesto1 : INTEGER;
- PROCEDURE init(VAR student: STUDENTI);
- VAR
- i : INTEGER;
- BEGIN
- FOR i := 0 TO Maxstud DO
- student[i].ime := "";
- student[i].prezime := "";
- student[i].godiste := 0
- END
- END init;
- PROCEDURE poredi(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 poredi;
- 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;
- PROCEDURE proveri(student: STUDENTI;str1, str2: STRING; god, t: INTEGER):BOOLEAN;
- VAR
- i : INTEGER;
- p1, p2 : INTEGER;
- BEGIN
- FOR i := 0 TO t DO
- p1 := poredi1(str1,student[i].ime);
- p2 := poredi1(str2,student[i].prezime);
- IF ((p1 = 0) AND (p2 = 0) AND (god = student[i].godiste)) THEN
- RETURN FALSE;
- ELSE
- RETURN TRUE;
- END;
- END;
- END proveri;
- PROCEDURE unosStdIme(VAR str1: STRING; t: INTEGER);
- VAR
- str2: STRING;
- broj : INTEGER;
- opet : BOOLEAN;
- BEGIN
- str2 := "";
- opet := FALSE;
- REPEAT
- IF opet THEN
- WriteString("Ponovite unos za ");
- WriteInt(t,0);
- WriteString(". ime u fajlu: ");
- ReadString(str1); WriteLn;
- broj := poredi(str1,str2)
- ELSE
- WriteString("Unos ");
- WriteInt(t,0);
- WriteString(". imena u fajl: ");
- ReadString(str1); WriteLn;
- broj := poredi(str1,str2);
- opet := TRUE
- END;
- UNTIL(broj # 0);
- END unosStdIme;
- PROCEDURE unosStdPrezime(VAR str1: STRING; t: INTEGER);
- VAR
- str2: STRING;
- broj : INTEGER;
- opet : BOOLEAN;
- BEGIN
- str2 := "";
- opet := FALSE;
- REPEAT
- IF opet THEN
- WriteString("Ponovite unos za ");
- WriteInt(t,0);
- WriteString(". prezime u fajlu: ");
- ReadString(str1); WriteLn;
- broj := poredi(str1,str2)
- ELSE
- WriteString("Unos ");
- WriteInt(t,0);
- WriteString(". prezimena u fajl: ");
- ReadString(str1); WriteLn;
- broj := poredi(str1,str2);
- opet := TRUE
- END;
- UNTIL(broj # 0);
- END unosStdPrezime;
- PROCEDURE unosStdGodiste(VAR godiste: INTEGER; t: INTEGER);
- VAR
- ok, opet : BOOLEAN;
- BEGIN
- opet := FALSE;
- ok := FALSE;
- REPEAT
- IF opet THEN
- WriteString("Ponovite unos za ");
- WriteInt(t,0);
- WriteString(". godiste u fajlu: ");
- ReadInt(godiste); WriteLn;
- IF ((godiste > 1000) AND (godiste < 2500)) THEN
- ok := TRUE
- END;
- ELSE
- WriteString("Unos ");
- WriteInt(t,0);
- WriteString(". godista u fajl: ");
- ReadInt(godiste); WriteLn;
- IF ((godiste > 1000) AND (godiste < 2500)) THEN
- ok := TRUE
- END;
- opet := TRUE;
- END;
- UNTIL(ok);
- END unosStdGodiste;
- PROCEDURE unosImenaPrezimenaGodista(VAR f: File; VAR student: STUDENTI; VAR t: INTEGER);
- VAR
- str1, str2 : STRING;
- broj, i : INTEGER;
- strZarez, strTacka : STRING;
- ok : BOOLEAN;
- BEGIN
- f := Create(fajl);
- strZarez := ",";
- strTacka := ".";
- WriteString("Unesite zeljeni broj studenata za unos: ");
- ReadInt(t); WriteLn;
- FOR i := 0 TO t-1 DO
- ok := FALSE;
- WHILE (NOT ok) DO
- str1 := "";
- unosStdIme(str1,i+1);
- str2 := "";
- unosStdPrezime(str2,i+1);
- broj := 0;
- unosStdGodiste(broj,i+1);
- ok := proveri(student,str1,str2,broj,t-1);
- IF (ok) THEN
- student[i].ime := str1;
- WrStr(f,str1); WrStr(f,strZarez);
- student[i].prezime := str2;
- WrStr(f,str2); WrStr(f,strZarez);
- student[i].godiste := broj;
- WrInt(f,broj,0); WrStr(f,strTacka);
- WrLn(f);
- ELSE
- WriteString("Uneti student je vec postojeci, Molimo Vas da ponovite unos "); WriteLn;
- END;
- END
- END;
- Close(f);
- END unosImenaPrezimenaGodista;
- PROCEDURE ucitajIspisiIzStudenti(VAR student: STUDENTI;t: INTEGER);
- VAR
- i : INTEGER;
- str : STRING;
- BEGIN
- WriteLn;
- WriteString("Sledi ispis studenata iz strukture");
- WriteLn;
- FOR i := 0 TO t-1 DO
- WriteString("Ispis ");
- WriteInt(i+1,0);
- WriteString(". imena iz strukture: ");
- str := student[i].ime;
- WriteString(str); WriteLn;
- WriteString("Ispis ");
- WriteInt(i+1,0);
- WriteString(". prezimena iz strukture: ");
- str := student[i].prezime;
- WriteString(str); WriteLn;
- WriteString("Ispis ");
- WriteInt(i+1,0);
- WriteString(". godista iz strukture: ");
- WriteInt(student[i].godiste,0); WriteLn
- END
- END ucitajIspisiIzStudenti;
- PROCEDURE krajStringa(str: STRING;VAR kraj: INTEGER); FORWARD;
- PROCEDURE prviZarez(str: STRING; VAR mesto1: INTEGER);
- VAR
- i, t : INTEGER;
- ok : BOOLEAN;
- BEGIN
- i := 0;
- ok := FALSE;
- krajStringa(str,t);
- WHILE ((i # t) AND (NOT ok)) DO
- IF (',' = str[i]) THEN
- ok := TRUE;
- ELSE
- i := i + 1;
- END
- END;
- mesto1 := i
- END prviZarez;
- PROCEDURE drugiZarez(str: STRING; VAR mesto2: INTEGER);
- VAR
- i, k, t : INTEGER;
- ok : BOOLEAN;
- BEGIN
- i := 0;
- k := 0;
- ok := FALSE;
- krajStringa(str,t);
- WHILE ((i # t) AND (NOT ok)) DO
- IF (',' = str[i]) THEN
- INC(k);
- IF (k = 2) THEN
- ok := TRUE
- ELSE
- mesto2 := i;
- INC(i);
- END;
- ELSE
- INC(i);
- END;
- END;
- mesto2 := i;
- END drugiZarez;
- PROCEDURE initString(VAR str: STRING);
- BEGIN
- str := "";
- END initString;
- PROCEDURE kopirajString(str1: STRING;VAR str2: STRING);
- VAR
- i : INTEGER;
- BEGIN
- initString(str2);
- FOR i := 0 TO MaxString DO
- str2[i] := str1[i]
- END;
- END kopirajString;
- PROCEDURE transferIme(VAR str1 : STRING;str2: STRING; prvi: INTEGER);
- VAR
- i : INTEGER;
- BEGIN
- initString(str1);
- FOR i := 0 TO (prvi-1) DO
- str1[i] := str2[i];
- END
- END transferIme;
- PROCEDURE transferZarezaPrezime(VAR str1 : STRING;str2: STRING; prvi,drugi: INTEGER);
- VAR
- p, i : INTEGER;
- BEGIN
- initString(str1);
- p := 0;
- FOR i := 0 TO MaxString DO
- IF ((i < drugi) AND (i > prvi)) THEN
- str1[p] := str2[i];
- INC(p);
- END;
- END;
- END transferZarezaPrezime;
- PROCEDURE transferGodiste(VAR str1: STRING;str2: STRING; drugi,poslednji: INTEGER);
- VAR
- p, i : INTEGER;
- BEGIN
- initString(str1);
- p := 0;
- FOR i := 0 TO MaxString DO
- IF ((i <= poslednji) AND (i > drugi)) THEN
- str1[p] := str2[i];
- INC(p);
- END;
- END;
- END transferGodiste;
- PROCEDURE krajStringa(str: STRING;VAR kraj: INTEGER);
- VAR
- i : INTEGER;
- BEGIN
- i := 0;
- WHILE ((str[i] # '.') AND (i < MaxString)) DO
- INC(kraj);
- INC(i);
- END
- END krajStringa;
- PROCEDURE ucitajIspisiIzFajla(VAR f: File;t: INTEGER);
- VAR
- i, broj, k : INTEGER;
- str1, str2, string1, string2, string3 : STRING;
- t1, t2, god, kraj : INTEGER;
- znak : CHAR;
- BEGIN
- f := Open(fajl);
- WriteLn;
- WriteString("Sledi ispis studenata iz fajla");
- WriteLn;
- i := 1;
- str2 := "";
- EOF := FALSE;
- WHILE (NOT EOF) DO
- RdStr(f,str1);
- INC(i);
- broj := poredi(str1, str2);
- IF ((broj # 0) AND (i # (t-1))) THEN
- prviZarez(str1,t1);
- drugiZarez(str1,t2);
- krajStringa(str1,kraj);
- initString(string1);
- transferIme(string1,str1,t1);
- initString(string2);
- transferZarezaPrezime(string2,str1,t1,t2);
- initString(string3);
- transferZarezaPrezime(string3,str1,t2,kraj);
- WriteString("Ispis ");
- WriteInt(i,0);
- WriteString(". imena, prezimena i godista iz fajla. "); WriteLn;
- WriteString("ime: ");WriteString(string1); WriteLn;
- WriteString("prezime: ");WriteString(string2); WriteLn;
- WriteString("godiste: : ");WriteString(string3); WriteLn;
- END
- END;
- Close(f);
- END ucitajIspisiIzFajla;
- BEGIN
- unosImenaPrezimenaGodista(f1,studenti,brStudenata);
- ucitajIspisiIzFajla(f1,brStudenata);
- END vf.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement