Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Pascal - Non passa alla procedura.
Forum - Pascal - Non passa alla procedura.

Avatar
TheCrow (Ex-Member)
Expert


Messaggi: 471
Iscritto: 31/05/2007

Segnala al moderatore
Postato alle 20:05
Sabato, 24/11/2007
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.

PM Quote
Avatar
TheCrow (Ex-Member)
Expert


Messaggi: 471
Iscritto: 31/05/2007

Segnala al moderatore
Postato alle 15:42
Giovedė, 29/11/2007
Piccola revisione (non funziona lo stesso)

Codice sorgente - presumibilmente Delphi

  1. Program Studenti;
  2.  
  3. Uses
  4.     Crt;
  5.  
  6. Const
  7.      Max = 30;
  8.  
  9. Type
  10.     Stringa  = string [20] ;
  11.     Stringa2 = string [10] ;
  12.     Alunni = record
  13.           Nome    : Stringa ;
  14.           Cognome : Stringa ;
  15.           Data    : Stringa2 ;
  16.           Voti    : Array [1..5] of real ;
  17.           Media   : Real ;
  18.     End;
  19.  
  20. Var
  21.  
  22. N_Alunni,I,J : integer;
  23. Lista        : array [1..Max] of alunni ;
  24. Tot          : real;
  25. Temp         : string;
  26. Cont         : integer;
  27. Name,Surname : String [40] ;
  28. carattere,c : char;
  29.  
  30. Procedure Dim ;
  31.  
  32. Begin
  33.      Repeat
  34.            Write('Inserire il numero degli alunni [ max 30 ] : ');ReadLn(N_Alunni);
  35.      Until (N_Alunni>0) and (N_Alunni<=30)
  36. End;
  37.  
  38. Procedure Load ;
  39.  
  40. Begin
  41.      I:=1;
  42.      repeat
  43.          WriteLn('Alunno #',I);
  44.          GoToXY(1,WhereY+1);Write('Insrire il nome : ');
  45.          repeat
  46.          carattere :=readkey;
  47.          c := UpCase(carattere);
  48.          Lista[J].Nome[I] := C ;
  49.          Write(Lista[J].Nome[I]);
  50.          until carattere=chr(13);
  51.          GoToXY(1,WhereY+1);Write('Inserire il cognome : ');
  52.          repeat
  53.          carattere :=readkey;
  54.          c := UpCase(carattere);
  55.          Lista[J].Cognome[I] := C ;
  56.          Write(Lista[J].Cognome[I]);
  57.          until carattere=chr(13);
  58.          GoToXY(1,WhereY+1);Write('Inserire la data di nascita : ');ReadLn(Lista[I].data);
  59.          J:=1;
  60.          Repeat
  61.              Write('Inserire il ',J,' voto : ');ReadLn(Lista[I].Voti[J]);
  62.              J:=J+1;
  63.          Until J>5;
  64.          I:=I+1;
  65.      Until I>N_Alunni
  66. End;
  67.  
  68. Procedure Media_V ;
  69.  
  70. Begin
  71.      For I:=1 to N_Alunni do
  72.          Begin
  73.               Tot:=0;
  74.               For J:=1 to 5 do
  75.                   Begin
  76.                        Tot:=Tot+Lista[I].Voti[J];
  77.                   End;
  78.               Lista[I].Media:=Tot/5;
  79.          End;
  80.  
  81. End;
  82.  
  83. Procedure Scambia_C;
  84.  
  85. Begin
  86.     Temp := Lista[I].cognome;
  87.     Lista[I].cognome :=Lista[J].cognome;
  88.     Lista[J].cognome :=Temp;
  89. End;
  90.  
  91. Procedure Scambia_N;
  92.  
  93. Begin
  94.      Temp := Lista[J].nome;
  95.      Lista[I].nome :=Lista[J].nome;
  96.      Lista[J].nome :=Temp;
  97. End;
  98.  
  99. Procedure Ordina ;
  100.  
  101. Begin
  102.      I:=1;
  103.      Repeat
  104.           J:=I+1;
  105.           Repeat
  106.                 IF (Lista[I].cognome>Lista[J].cognome) Then
  107.                    Scambia_C
  108.                 Else if
  109.                      (Lista[I].nome>Lista[J].nome) Then
  110.                      Scambia_N;
  111.                 J:=J+1;
  112.           Until J<N_Alunni;
  113.           I:=I+1;
  114.      Until I<(N_Alunni-1);
  115.  
  116. End;
  117.  
  118. Procedure Stampa ;
  119.  
  120. Begin
  121.      For I:=1 to N_Alunni do
  122.          Begin
  123.               WriteLn(Lista[I].cognome);
  124.               WriteLn(Lista[I].nome);
  125.               WriteLn(Lista[I].data);
  126.               WriteLn(Lista[I].media);
  127.          End;
  128.         readln;
  129. End;
  130.  
  131. Procedure Print ;
  132.  
  133. Begin
  134.      I:=1;
  135.      repeat
  136.            IF (Lista[I].nome=name) and (Lista[I].cognome=surname) then
  137.            Begin
  138.               WriteLn(Lista[I].Media);
  139.            End;
  140.            I:=I+1;
  141.      until I<N_Alunni
  142. End;
  143.  
  144. Begin
  145.      ClrScr;
  146.      Dim;
  147.      Load;
  148.      Media_V;
  149.      Ordina;
  150.      Stampa;
  151.      WriteLn('Chiave di ricerca');
  152.      Write('Inserire il nome : ');
  153.      I:=1;
  154.      repeat
  155.                 carattere := readkey;
  156.                 c := upcase (carattere);
  157.                 name[I]:=c;
  158.                 Write(name[I]);
  159.                 I:=I+1;
  160.      until c = chr(13);
  161.      Write('Inserire il cognome : ');
  162.      I:=1;
  163.      repeat
  164.                 carattere := readkey;
  165.                 c := upcase (carattere);
  166.                 surname[I] := c;
  167.                 Write(surname[I]);
  168.                 I:=I+1;
  169.      until c = chr(13);
  170.      Print;
  171.      readln;
  172.  
  173. End.


PM Quote
Avatar
WARRIOR (Ex-Member)
Guru


Messaggi: 627
Iscritto: 30/03/2007

Segnala al moderatore
Postato alle 18:18
Giovedė, 29/11/2007
Pierpaolo nella dichiarazione del tipo, dichiari i campi del record, senza dichiararlo davvero.

Codice sorgente - presumibilmente Pascal

  1. qualcosa = record
  2. ----
  3. ----
  4. ----
  5. end;



:k:

PM Quote
Avatar
TheCrow (Ex-Member)
Expert


Messaggi: 471
Iscritto: 31/05/2007

Segnala al moderatore
Postato alle 18:39
Giovedė, 29/11/2007
Non ho capito dove č l'errore.:(

PM Quote
Avatar
WARRIOR (Ex-Member)
Guru


Messaggi: 627
Iscritto: 30/03/2007

Segnala al moderatore
Postato alle 0:01
Venerdė, 30/11/2007
Ah no scusa errore mio :), il codice č scritto tutto compatto, quindi mi sono perso un' istruzione :D. Quando ho tempo provo il codice e ti dico. :k:

PM Quote
Avatar
TheCrow (Ex-Member)
Expert


Messaggi: 471
Iscritto: 31/05/2007

Segnala al moderatore
Postato alle 16:30
Venerdė, 30/11/2007
Grazie Luca.

Io non lo riesco proprio a trovare.

PM Quote
Avatar
WARRIOR (Ex-Member)
Guru


Messaggi: 627
Iscritto: 30/03/2007

Segnala al moderatore
Postato alle 20:08
Venerdė, 30/11/2007
In effetti non passa oltre la procedura media, c'č qualche errore fatale di mezzo.
Non penso sia questo il problema, ma cmq prova a dichiarare la variabile Temp, anzichč string, Stringa.

Ultima modifica effettuata da WARRIOR il 30/11/2007 alle 20:14
PM Quote
Avatar
sange_90 (Ex-Member)
Pro


Messaggi: 185
Iscritto: 23/01/2007

Segnala al moderatore
Postato alle 20:15
Venerdė, 30/11/2007
Penso cmq che il programma sarebbe pių compatto se avesse procedure con passaggio di parametri facendo a meno di usare variabili globali al loro interno... ;)

PM Quote