24/11/07 19:05
TheCrow
Scusate per il titolo non molto kiaro, ma a scuola ci hanno assegnato un programma ke utilizza la struttura RECORD.
Dopo aver realizzato il programma, ho notato ke non passa a una procedura.
Praticamente dopo aver caricato il record ed aver effettuato la media (tramite procedure) si blocca.
Vi posto il sorgente :
Program Table;
Uses
Crt;
Const
Max = 30;
Type
Stringa = string [20] ;
Stringa2 = string [10] ;
Alunni = record
Nome : Stringa ;
Cognome : Stringa ;
Data : Stringa2 ;
Voti : Array [1..5] of real ;
Media : Real ;
End;
Var
N_Alunni,I,J : integer;
Lista : array [1..Max] of alunni ;
Tot : real;
Temp : string;
Cont : integer;
Name,Surname : String [40] ;
Procedure Dim ;
Begin
Repeat
Write('Inserire il numero degli alunni [ max 30 ] : ');ReadLn(N_Alunni);
Until (N_Alunni>0) and (N_Alunni<=30)
End;
Procedure Load ;
Begin
I:=1;
repeat
WriteLn('Alunno #',I);
Write('Insrire il nome : ');ReadLn(Lista[I].nome);
Write('Inserire il cognome : ');ReadLn(Lista[I].cognome);
Write('Inserire la data di nascita : ');ReadLn(Lista[I].data);
J:=1;
Repeat
Write('Inserire il ',J,' voto : ');ReadLn(Lista[I].Voti[J]);
J:=J+1;
Until J>5;
I:=I+1;
Until I>N_Alunni
End;
Procedure Media_V ;
Begin
For I:=1 to N_Alunni do
Begin
Tot:=0;
For J:=1 to 5 do
Begin
Tot:=Tot+Lista[I].Voti[J];
End;
Lista[I].Media:=Tot/5;
End;
End;
Procedure Scambia_C;
Begin
Temp := Lista[I].cognome;
Lista[I].cognome :=Lista[J].cognome;
Lista[J].cognome :=Temp;
End;
Procedure Scambia_N;
Begin
Temp := Lista[J].nome;
Lista[I].nome :=Lista[J].nome;
Lista[J].nome :=Temp;
End;
Procedure Ordina ;
Begin
I:=1;
Repeat
J:=I+1;
Repeat
IF (Lista[I].cognome>Lista[J].cognome) Then
Scambia_C
Else if
(Lista[I].nome>Lista[J].nome) Then
Scambia_N;
J:=J+1;
Until J<N_Alunni;
I:=I+1;
Until I<(N_Alunni-1);
End;
Procedure Stampa ;
Begin
For I:=1 to N_Alunni do
Begin
WriteLn(Lista[I].cognome);
WriteLn(Lista[I].nome);
WriteLn(Lista[I].data);
WriteLn(Lista[I].media);
End;
End;
Procedure Upper ;
Begin
For Cont:=1 to Length(Name) do
Begin
Name[Cont] := UPCASE (Name[Cont]);
End;
WriteLn(Name);
For I:=1 to Length(Surname) do
Begin
Surname[I] := UPCASE (surname[I])
End;
WriteLn(Surname);
Delay(1000);
End;
Procedure Print ;
Begin
I:=1;
repeat
IF (Lista[I].nome=name) and (Lista[I].cognome=surname) then
Begin
WriteLn(Lista[I].Media);
End;
I:=I+1;
until I<N_Alunni
End;
Begin
ClrScr;
Dim;
Load;
Media_V;
Ordina;
Stampa;
WriteLn('Chiave di ricerca');
Write('Inserire il nome : ');ReadLn(name);
Write('Inserire il cognome : ');ReadLn(surname);
Upper;
Print;
End.
Dopo aver realizzato il programma, ho notato ke non passa a una procedura.
Praticamente dopo aver caricato il record ed aver effettuato la media (tramite procedure) si blocca.
Vi posto il sorgente :
Program Table;
Uses
Crt;
Const
Max = 30;
Type
Stringa = string [20] ;
Stringa2 = string [10] ;
Alunni = record
Nome : Stringa ;
Cognome : Stringa ;
Data : Stringa2 ;
Voti : Array [1..5] of real ;
Media : Real ;
End;
Var
N_Alunni,I,J : integer;
Lista : array [1..Max] of alunni ;
Tot : real;
Temp : string;
Cont : integer;
Name,Surname : String [40] ;
Procedure Dim ;
Begin
Repeat
Write('Inserire il numero degli alunni [ max 30 ] : ');ReadLn(N_Alunni);
Until (N_Alunni>0) and (N_Alunni<=30)
End;
Procedure Load ;
Begin
I:=1;
repeat
WriteLn('Alunno #',I);
Write('Insrire il nome : ');ReadLn(Lista[I].nome);
Write('Inserire il cognome : ');ReadLn(Lista[I].cognome);
Write('Inserire la data di nascita : ');ReadLn(Lista[I].data);
J:=1;
Repeat
Write('Inserire il ',J,' voto : ');ReadLn(Lista[I].Voti[J]);
J:=J+1;
Until J>5;
I:=I+1;
Until I>N_Alunni
End;
Procedure Media_V ;
Begin
For I:=1 to N_Alunni do
Begin
Tot:=0;
For J:=1 to 5 do
Begin
Tot:=Tot+Lista[I].Voti[J];
End;
Lista[I].Media:=Tot/5;
End;
End;
Procedure Scambia_C;
Begin
Temp := Lista[I].cognome;
Lista[I].cognome :=Lista[J].cognome;
Lista[J].cognome :=Temp;
End;
Procedure Scambia_N;
Begin
Temp := Lista[J].nome;
Lista[I].nome :=Lista[J].nome;
Lista[J].nome :=Temp;
End;
Procedure Ordina ;
Begin
I:=1;
Repeat
J:=I+1;
Repeat
IF (Lista[I].cognome>Lista[J].cognome) Then
Scambia_C
Else if
(Lista[I].nome>Lista[J].nome) Then
Scambia_N;
J:=J+1;
Until J<N_Alunni;
I:=I+1;
Until I<(N_Alunni-1);
End;
Procedure Stampa ;
Begin
For I:=1 to N_Alunni do
Begin
WriteLn(Lista[I].cognome);
WriteLn(Lista[I].nome);
WriteLn(Lista[I].data);
WriteLn(Lista[I].media);
End;
End;
Procedure Upper ;
Begin
For Cont:=1 to Length(Name) do
Begin
Name[Cont] := UPCASE (Name[Cont]);
End;
WriteLn(Name);
For I:=1 to Length(Surname) do
Begin
Surname[I] := UPCASE (surname[I])
End;
WriteLn(Surname);
Delay(1000);
End;
Procedure Print ;
Begin
I:=1;
repeat
IF (Lista[I].nome=name) and (Lista[I].cognome=surname) then
Begin
WriteLn(Lista[I].Media);
End;
I:=I+1;
until I<N_Alunni
End;
Begin
ClrScr;
Dim;
Load;
Media_V;
Ordina;
Stampa;
WriteLn('Chiave di ricerca');
Write('Inserire il nome : ');ReadLn(name);
Write('Inserire il cognome : ');ReadLn(surname);
Upper;
Print;
End.
aaa