mi faresti un esempio su una funzione ad es. calcolare la media

es.
io ho un programma tipo questo
mi potreste indicare che tipo di variabili si mettono affianco alle porcedure e come si fa la function calcmedia

codice:
program voti;
const
maxvoti=100;
Type
tipovoto=1..100;
voti=array [1..maxvoti] of integer;
Var
I:integer;
voto:voti;
totale:integer;
N:integer;

procedure leggistud;??????????????CHE VARIABILI SI METTONO QUI 
var
txtvoti:text;
Begin
assign (txtvoti, 'C:\miei\esercizi\voti.txt');
Reset (txtvoti);
 I:=1;
 Totale:=0;
while not (eof (txtvoti)) do
begin
readln (txtvoti, voto[i]);
totale:=totale+voto[i];
i:=i+1;
end;
end;


QUI DOVREI FARE LA FUNZIONE PER CALCOLARE LA MEDIA (I DATI DI INPUT SONO totale E i.

 begin
leggistud;


N:=I;
writeln (calcmedia);
Writeln ( 'VOTO':10, 'GRADO':20);
For i:=1 To N do
begin
Write(voto[i]:10);
If (voto[i]>(calcmedia+10)) then
write('Soddisfacente':20)
else
If ((voto[i]+10)<(calcmedia)) then
write('Insoddisfacente':20)
else
write('buono':20);
writeln;
 end;
readln;


end.