Codice errato

2011-12: Intermediate
Import the following code sample (XMW920), there are a number of errors – fix these.
Most of the errors prevent the sample compiling so it should be relatively easy to identify these from the compiler error reports.
Click on these to take you to the offending line.
There is also one other error that allows the code to run, but doesn’t work as expected, so you will need to test the code.
When all the errors are detected, the code works fine, but it is not ‘good’ code.
It jumps all-over-the-place using Goto statements and is very hard to follow.
The remainder of this challenge is to rewrite the code with a good structure using no Goto statements if possible, using any methods you think make the code clearer (possibly Arrays, While or Subroutines etc), also comment it.

Soluzione 1

Importa il codice seguente d’esempio (XMW920), ci sono diversi errori – correggili.
La maggior parte degli errori impediscono la semplice compilazione quindi dovrebbe essere relativamente facile individuarli a partire dagli errori riportati dal compilatore.
Clicca su ciascuno di essi per portarti alla linea corrispondente.
Originale

Corretto

Soluzione 2

C’è un ulteriore errore che permette al codice di essere eseguito, ma non di funzionare come dovrebbe, quindi sarà necessario che tu metta alla prova il codice.

Soluzione 3

Quando tutti gli errori saranno individuati il codice funzionerà correttamente ma non si tratta di un buon codice.
Salta dappertutto utilizzando l’istruzione GoTo ed è molto difficile da seguire.
L’ultima parte di questa sfida è riscrivere il codice con una buona struttura senza utilizzare, se possibile, l’istruzione GoTo, utilizzando qualsiasi metodo che ritieni necessario per semplificare il codice (per esempio Arrays, While, Sottoprogrammi, …), inoltre commentalo.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *