Contest question: logic error and semantic error?

Asked

Viewed 426 times

15

I participated in a contest and fell 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 be executed without errors;

B) The algorithm will be executed, but there is a semantic error;

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

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

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

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

Source

  • 3

    This is the kind of question that falls into contest? I would find it easy, but apparently there are things in these questions that I can not see. I wonder how it is possible to point out a logic error if it has not written in lufar some what is the logic to be followed, ie there is a defined problem. The semantic error depends on the algorithm language. Where does it say which language? Do you have to guess? Or is it implied by something else that is not apparent in the question? Alias, proof of contest with Portuguese error, wonder...

  • 2

    @rray do not know, this is assumption. If the proof was made by someone who does not know Portuguese, imagine if you know how to make a question that makes sense. I would enter with feature imputing at least the question. The question itself has: A) no error; B) misspelling; C) grammatical error; D) both

  • 5

    I don’t see any mistakes there. By the way, I have already given some contests, and usually who makes the computer issues clearly is not in the area;

  • 5

    Still I am curious for someone to point out some mistake there. Suddenly there is some VERY discreet prank. Now, if the plaintiff claims that the error is a in place of =, have to pick up rubber slippers in the face, because nothing prevents be the symbol of attribution of this language. By the way, very semantic this arrow for attribution. It should only be boring to type.

4 answers

10


I would mark answer A and then would 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 in a plausible manner.

I can’t see an execution error there, it’s a simple algorithm and "manly".

To say that 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 a logic error 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 language of algorithm I know and within what I hope this algorithm does, there is no mistake.

What one can claim is that the average is being calculated over an integer value. But for me it’s okay to do this. Only a definition of accepting decimal values would make a logic error.

This error of logic in theory could be the consequence of a semantic error, although I doubt, I think that the semantic would make the execution impossible before it, and fixing the logic would be correct. Semantics could compel you to make a conversion in order to make this calculation, but how will I know in something so abstract?

Someone could claim to accept any amount. I doubt that’s a need for such a simple algorithm, but if it is, there should be a problem defining this.

The algorithm does everything correctly within what intuitiveness determines, it cannot go beyond it. If something is missing it is the fault of the wrong question asked and she cannot demand that the person reading it knows what it is.

In addition I ran in 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.

Probably I would justify in proof my choice. I don’t know how much this could help anything.

It may be that the question was based on some booklet that one should study beforehand. Then everything changed, would have to answer what the apostille says, even if it is wrong, because the contest is trying to determine who memorized the apostille.

  • "Then everything changed, would have to answer what the booklet says, even if it is wrong." That is the horror of our world...

5

It could be a semantic error if somewhere in the question is specified that the 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 < 0. However if the exercise statement is only this I would mark "A) When executed the algorithm will be executed without errors;" and I would say that if they considered another answer to be correct it’s because they traveled legal in some highly subjective interpretation, which is ironic when it comes to a question about the accuracy of a code.

  • It is. No error. It stands in the cursor of N1.

  • 2

    If you had an "NDA" it would be the best answer. Negative note is "business rule", and not algorithm problem. In order not to accept negative or higher than ten, there is no need in the statement that the track is this. Who said that the grade is not 1 to 14? Or -5 to +5 and the utopian average? kkk...

  • Yes, exactly why I said in the following sentence "if the statement is only this...".

4

I agree with you. There’s only one semantic error. At no time 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 and N2 were 0, it would generate a division error by zero. We also know that the division of 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 prank and depends a lot on each interpretation. I would like other colleagues to express themselves.

  • You’re wrong about that. Read N1 and N2 supposedly is the input. Where you are going by zero? ( 0 + 0 ) / 2 = 0, no problem. And what’s the problem of calculating with integers?

  • you’re right, @Bacco.

  • However, I think there would be no error because the cursor would stop to receive the value and the values are not in the question.

  • 7

    The question is very bad. Not @Denis, but who prepared the proof. I can’t talk about that particular contest, I suppose it’s totally regular and transparent... But I’ve seen others with question of this type that are only to regularize the "nephew" who works in the place.

  • Absolutely. But it was nice to hear other answers from colleagues.

0

  • 3

    If the notes of the entity that will use the mean do not admit non-integer numbers, using integer in the algorithm is a suitable solution. For your answer to be true, just looking at the "business rule" of the entity that uses the average. The statement is flawed in this sense. And even if I did, I can’t say that "when executed" error will occur. It depends on the input. It is one thing for the code to have an error, another is if in a certain condition the error appears.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.