Contest question: logic error and semantics error?

I participated in a contest and dropped the following Question:

33-analyze the algorithm and check the correct option for this algorithm.

Algorithm Calculo_Media:

Var N1, N2, MEDIA: Inteiro
Início
  Leia N1, N2
  MEDIA ← (N1 + N2) / 2
  Se MEDIA >= 7 então
     Escreva “Aprovado”
  Senão
     Escreva “Reprovado”
  Fim_se
Fim

A) when executed the algorithm will run without errors;

B) the algorithm will run, but there is a semantics error;

C) when executed the algorithm will have a logic error, plus there is no semantics error;

D) when executed the algorithm will have a logic error and a semantics error

I marked the letter "B", because I think that the error that exists in this algorithm can only be of semantics. The preliminary template pointed to the letter " C "as correct, after the features changed to"D".

Besides the semantics error is there also logic error in this algorithm?

Source

Author: Denis Caixeta, 2016-01-18

4 answers

I would mark answer to and then enter appeal first to try to accept my answer, and if it is not possible to challenge the question. Unless, of course, someone officially justified the answer plausibly.

I can't see execution error there, it's a simple and "yummy" algorithm.

To say you have a logic error there should be a definition of what the problem is. This is not present, so it is not possible to assign an error of logic in something you do not know what to do.

To say that there is a semantic error it is necessary to know the rules of the programming language, even a more abstract language. There are several algorithm languages, each with its own rules.

Within the algorithm language that I know and within what I expect this algorithm to do, there is no error at all.

What one can claim is that the mean is being calculated on top of an integer value. But it's okay for me to do this. Only one definition that should accept decimal values is that it would cause a logic error.

This logic error in thesis could be a consequence of a semantic error, although I doubt it, I think the semantic would make the execution unfeasible before it, and the fixing the logic would be correct. Semantics could force you to do a conversion to be able to do this calculation, but how am I going to know in something abstract like that?

Could anyone claim that accepting any value. I doubt this is a need for such a simple algorithm, but if it is, you should have a problem defining this.

The algorithm does everything correctly within what intuitiveness determines, it can not go beyond it. If something is missing it is the fault of the poorly asked question and it cannot require the person reading to know what it is about.

Besides this I ran on an " IDE " that understands this algorithm and ran without apparent errors. Of course I had to make adaptations because none I found used this syntax of the question.

I would probably justify in the proof my choice. I don't know how much this could help anything.

It may be that the question was based on some handout that the person should study beforehand. There everything Mute, would have to answer what the Apostille says, even if it is wrong, because the contest is trying to determine who decorated the Apostille.

 10
Author: Maniero, 2019-11-22 14:31:03

Could be a semantic error if somewhere in the question it was specified that notes can be rational numbers, so it would be a mistake to use "integer". It could also be considered a logic error to allow" read " Notes > 10 or

 5
Author: BrunoRB, 2016-01-18 16:21:05

I agree with you. There is only one semantics error. At no point in the question are the values of N1 and N2 provided, so the execution of the algorithm will stop to receive the value of N1 and there will be no error.

But we know that if the sum of N1 with N2 was 0, it would generate a division error by zero. We also know that dividing N1 and N2 by 2 can generate a non-integer number, different from the media statement. But this error did not occur because the values were not passed and the calculation was not done.

This question is a catch and depends a lot on each interpretation. I would like other colleagues to come forward.

 4
Author: Andre Mesquita, 2016-01-18 16:15:38

One problem:

The mean cannot be an integer because if the sum of n1 and n2 results in an odd number, the mean will not be an integer.

I believe this is a logic error as well.

I found this in phpbrasil

Http://phpbrasil.com/artigo/yAVSjjsFq2vR/os-4-tipos-de-erros-em-programacao

 0
Author: Diogenes Silveira, 2016-01-18 16:42:10