User:Lukassos

Pascal Guidance

So what`s going on Fellas? here`s your guide for pascal in time i`ll build it up for beginning some examples(I`m sorry for my English):

1. Program kandid; uses wincrt;

var f1,f2:text; pk,j,i,k,hlas: integer; mena: array [1..20] of string; hlasy:array [1..20] of integer;

begin assign(f1,'kandid.txt'); assign(f2,'volby.txt'); reset(f1); reset(f2);

while not eof (f1) do begin pk:=pk+1; readln(f1,mena[pk]); end; for i:=1 to pk do hlasy[i]:=0; while not eof (f2) do begin read(f2,k); while not eoln(f2) do   begin

read(f2,hlas); hlasy[k]:=hlasy[k] +hlas; end; readln(f2);                      {doplnte triedenie} end; for i:= 1 to pk do begin writeln(mena[i], ': ',hlasy[i]); end;

close(f1); close(f2); end.

2. program parcele; uses wincrt; var pole:array [1..10,1..10] of integer; i,j,k: integer; vlas: array[1..10] of integer; max,imax :integer; begin writeln('Zadaj vlastnikov parciel '); for i:=1 to 10 do begin for j:= 1 to 10 do                    readln(pole[i,j]); end;

for i:=1 to 10 do begin for j:= 1 to 10 do                     write(pole[i,j]:5); writeln; end;

for i:=1 to 5 do begin for j:= 1 to 5 do begin for k:=1 to 5 do                                       if m[i,j]=k then vlas[k]:=vlas[k]+1; end; end; writeln; writeln('Pocet parciel jednotlivych vlastnikov: '); for i:=1 to 5 do begin write(i,'.- '); writeln(vlas[i]:5); end; max:=0; for i:= 1 to 5 do if vlas[i]> max then begin max:=kolko[i]; vmax:=i; end; writeln; writeln('Najviac parcel vlastni ',vmax);

readln; end.

[[3.

program M03_cestovka;]] uses wincrt; type datum=record d,m: integer; end; tzajazd=record miesto: string; zac,kon: datum; miest: integer; end; var t: text; z: char; p,r,s,i,j,n,d1,d2,aut,code: integer; zajazd: array[1..20] of tzajazd; pom: array[1..2] of char; drok: array[1..365] of integer; m: array[1..12] of integer;

{doplnte proceduru}

procedure bus; begin p:=0; r:=1; for i:=1 to n do begin p:=p+zajazd[i].miest; if(zajazd[r].miest0)then inc(aut);

for j:=d1 to d2 do    drok[j]:=drok[j]+aut;

end; s:=0; for i:=1 to 365 do if(drok[i]>s)then s:=drok[i]; end;

begin m[1]:=31; m[2]:=28; m[3]:=31; m[4]:=30; m[5]:=31; m[6]:=30; m[7]:=31; m[8]:=31; m[9]:=30; m[10]:=31; m[11]:=30; m[12]:=31; assign(t,'zajazd.txt'); reset(t); readln(t,n); for i:=1 to n do begin read(t,zajazd[i].miest); read(t,z); read(t,pom[1]); read(t,pom[2]); if(pom[2]='.')then val(pom[1],zajazd[i].zac.d,code) else begin val(pom[1]+pom[2],zajazd[i].zac.d,code); read(t,z); end; read(t,pom[1]); read(t,pom[2]); if(pom[2]='.')then zajazd[i].zac.m:=ord(pom[1])-48 else begin zajazd[i].zac.m:=ord(pom[1])*10+ord(pom[2])-528; read(t,z); end; read(t,z); read(t,pom[1]); read(t,pom[2]); if(pom[2]='.')then zajazd[i].kon.d:=ord(pom[1])-48 else begin zajazd[i].kon.d:=ord(pom[1])*10+ord(pom[2])-528; read(t,z); end; read(t,pom[1]); read(t,pom[2]); if(pom[2]='.')then zajazd[i].kon.m:=ord(pom[1])-48 else begin zajazd[i].kon.m:=ord(pom[1])*10+ord(pom[2])-528; read(t,z); end; read(t,z); readln(t,zajazd[i].miesto); end;

close(t); bus; writeln('Na zajazdoch je volnych ',p,' miest.'); writeln('Najviac volnych miest (',zajazd[r].miest,')  ',zajazd[r].miesto,'.'); writeln('minimalny pocet autobusov: ',s); readln; end.

[[4.

program prevod_sustav;]] var n, p, zv   : word; prevod   : string;

begin write('Zadaj n '); readln(n); p:=n; zv:=0;prevod:=''; while p<>0 do begin zv:=p mod 2; if zv=0 then prevod:='0'+prevod else prevod:='1'+ prevod; p:=p div 2; end; writeln(N, '(10)=',prevod,'(2)'); readln; end.

[[5.

program hitparada;]] USES CRT;

type info = record nazov:string[9]; pocet:integer; end;

var piesen:info; a:array [1..10] of info;

PROCEDURE SPOCITAJ; VAR i:INTEGER; sum :integer; f1:text;

begin assign(f1,'e:\hitpar.txt'); reset(f1); sum:=0; for i:=1 to 10 do begin readln(f1,piesen.nazov); readln(f1,piesen.pocet); a[i]:=piesen; sum:=sum+piesen.pocet; writeln(piesen.nazov,' ',piesen.pocet); end;

writeln; writeln('Pocet vsetkych hlasov: ',sum); close(f1); END;

PROCEDURE UTRIED; VAR i,j:INTEGER; pom:info;

BEGIN

FOR i:=1 TO 10 DO   FOR j:=1 TO 10-1 DO      IF a[j].pocet < a[j+1].pocet THEN BEGIN pom:=a[j]; a[j]:=a[j+1]; a[j+1]:=pom; {moznost pouzit dve polia:POM:=B[J];B[J]:=B[J+1];B[J+1]:=POM;} END; END;

PROCEDURE VYPIS; VAR i:INTEGER; BEGIN FOR i:=1 TO 10 DO   BEGIN WRITELN(i:3,'. MIESTO ',a[i].nazov,' ',a[i].pocet:5); END; END;

BEGIN CLRSCR; SPOCITAJ; UTRIED; VYPIS; readln; END.