Contest question: logic error and semantic error?

14

I participated in a contest and fell the following question:

  

33 - Analyze the algorithm and tick the correct option for this algorithm.

Calculation_Media Algorithm:

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 be executed, but there is a semantic error;

C) When executed the algorithm will have a logic error, but there is no semantic error;

D) When executed the algorithm will have a logic error and a semantic error

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

In addition to the semantic error there is also a logic error in this algorithm?

Font

    
asked by anonymous 18.01.2016 / 16:51

4 answers

9

I would check Answer A and then I would first appeal to try to accept my answer, and if it is not possible to contest the issue. Unless, of course, someone officially justified the answer plausibly.

I can not see execution error there. It is a simple and "dirty" algorithm.

To say that you have a logic error there should be a definition of what the problem is. This is not present. You can not assign a logic error to something you do not know what you should 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 I know and within what I expect this algorithm to do, there is no error whatsoever.

What one can claim is that the mean is being calculated over an integer value. But it's ok for me to do this. Only one definition that should accept decimal values is that there would be a logic error.

This pseudo logic error could be a consequence of a semantic error, although I doubt it, I think the semantic would make it impossible to execute before and fixing it, the logic would be correct. The semantics could force a conversion to be able to do this calculation. But how do I know something abstract like that?

One could argue that it is accepting any value. I doubt that's a necessity for such a simple algorithm. But if it is, I should have a problem setting it.

The algorithm does everything correctly within what intuitiveness determines. You can not go beyond it. If something is missing, it is the fault of the wrong question and it can not require the person who reads to know what it is.

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

I would probably justify my choice on the test. I do not know how much that could help.

It may be that the question was based on some handout that the person should study previously. Then everything would change, it would have to answer what the handout says, even if it is wrong.

    
18.01.2016 / 17:51
5

It could be a semantic error if somewhere in the question was specified that the notes can be rational numbers, then it would be a mistake to use "Integer". It could also be considered a logic error to allow "read" notes > 10 or < 0. However if the exercise statement is only this I would mark "A" When executed the algorithm will run without errors; and would say that if they considered another correct answer is because they have traveled legally in some highly subjective interpretation, which is ironic when it comes to a question about the accuracy of a code.     

18.01.2016 / 17:21
4

I agree with you. There is only one semantic error. At any moment of the question are given the values of N1 and N2, 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 is 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 express themselves.

    
18.01.2016 / 17:15
0

The problem:

The mean can not be an integer because if the sum of n1 and n2 yields an odd number, the mean will not be an integer.

I think this is a logic bug as well.

I found this in phpbrasil

link

    
18.01.2016 / 17:42