From: Doni Pracner Date: Sat, 15 Feb 2014 17:56:01 +0000 (+0100) Subject: zadaci sa fajlovima se citaju iz modula umesto da su direkt u skripti X-Git-Tag: v14a~8^2~1 X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=bef26da68dd1d317acbd31d0862c1066c6a7cfe2;p=spa1skripta-public.git zadaci sa fajlovima se citaju iz modula umesto da su direkt u skripti --- diff --git a/skripta-spa1-sadrzaj.tex b/skripta-spa1-sadrzaj.tex index d9f8e19..50655d0 100644 --- a/skripta-spa1-sadrzaj.tex +++ b/skripta-spa1-sadrzaj.tex @@ -649,34 +649,7 @@ radu. Potrebno je sve redove iz fajla učitati i ispisati ih na ekran. -\begin{lstlisting}[style=codeblock] -MODULE ispis; -FROM FIO IMPORT File, Open, Close, EOF, RdStr; -FROM InOut IMPORT WriteString, WriteLn, ReadString; - -PROCEDURE ispisF(ime: ARRAY OF CHAR); -VAR - f:File; - s : ARRAY[1..100] OF CHAR; -BEGIN - f:=Open(ime); - EOF := FALSE; - WHILE NOT EOF DO - RdStr(f,s); - WriteString(s); - WriteLn; - END; - Close(f); -END ispisF; - -VAR - ime: ARRAY[1..100] OF CHAR; -BEGIN - WriteString("unesite ime fajla:"); - ReadString(ime); - ispisF(ime); -END ispis. -\end{lstlisting} +\lstinputlisting[style=codeblock]{kodovi/fajlovi/ispis.mod} \subsection{Zadatak: spisak studenata} @@ -685,132 +658,7 @@ novog studenta u spisak i snima fajl. U fajlu se u svakom redu nalazi podatak o jednom studentu, redom prezime, ime i godina rođenja, razdvojeni razmacima. -\begin{lstlisting}[style=codeblock] -MODULE nizslog; -FROM InOut IMPORT WriteString, WriteLn, - WriteCard, ReadCard, ReadString; -FROM FIO IMPORT File, Open, Create, Close, EOF, - RdItem, RdCard, WrStr, WrCard, WrLn; -FROM Str IMPORT Compare; - -CONST - MaxStud = 100; -TYPE - String = ARRAY[1..30] OF CHAR; - Student = RECORD - ime, prez: String; - god: CARDINAL; - END; - Studenti = ARRAY[1..MaxStud] OF Student; - -PROCEDURE UcitajF(fajl:String; - VAR spisak: Studenti; VAR n:CARDINAL); -VAR - f:File; -BEGIN - n:=0; - f:= Open(fajl); - EOF := FALSE; - WHILE NOT EOF DO - INC(n); - RdItem(f, spisak[n].prez); - RdItem(f, spisak[n].ime); - spisak[n].god := RdCard(f); - END; - Close(f); -END UcitajF; - -PROCEDURE Ispisi(spisak:Studenti; n:CARDINAL); -VAR - i: CARDINAL; -BEGIN - FOR i:=1 TO n DO - WriteString(spisak[i].prez); - WriteString(" "); - WriteString(spisak[i].ime); - WriteString(" "); - WriteCard(spisak[i].god,1); - WriteLn; - END; -END Ispisi; - -PROCEDURE IspisiF(fajl:String; - spisak:Studenti; n:CARDINAL); -VAR - f:File; - i: CARDINAL; -BEGIN - IF (n>0) AND (n<=MaxStud) THEN - f:=Create(fajl); - (* pravimo takav fajl da ne - postoji zadnji prazan red *) - FOR i:=1 TO n-1 DO - WrStr(f,spisak[i].prez); - WrStr(f," "); - WrStr(f,spisak[i].ime); - WrStr(f," "); - WrCard(f,spisak[i].god,1); - WrLn(f); - END; - WrStr(f,spisak[n].prez); - WrStr(f," "); - WrStr(f,spisak[n].ime); - WrStr(f," "); - WrCard(f,spisak[n].god,1); - Close(f); - END; -END IspisiF; - -PROCEDURE NoviStudent(VAR spisak:Studenti; - VAR n:CARDINAL); -VAR - stud,temp:Student; - i:CARDINAL; - dodaj:BOOLEAN; -BEGIN - IF n