Hello, I am new here and have a question. I just took a c++ test and disagree with one of the true/false questions. The exact question is: The floor(x) function rounds integers down. True or False. It seemed like a trick question, so I put false and was marked wrong for it.
Integers are whole numbers so they wouldn't be rounded at all, correct?
That would be like writing cout << floor(10). Which would output 10
I think the issue is how one interprets the statement.
If you interpret it as a literal logical statement, the sentence is true: if you pass an integer to floor() it will indeed round it down to the nearest integer less than or equal to the argument (which is itself). It would be equally true to say that floor() rounds integers up, or that it's an identity function over the integers, or that it cancels out the imaginary part of the parameter.
If you interpret it as a description of what the function does then it's false because it's incomplete. The function doesn't accept only integer values. It would obviously be pointless if it did.
So the question is, were the other questions in the test treated with the same degree of literality? If not then I would challenge it. One can either be insufferably pedantic or not, but not switch from one to the other on a whim.
I think that's an awful question. I agree that 'true' is, very strictly speaking, more correct, but what could that kind of question possibly be trying to teach you? It provides no value, no utility.
An aside, when I first read the question, I was focused on "rounds" as a description of the real-life measurable action that takes place. So when I read "the floor function rounds integers down", I would say, "no, it does not round integers down; it keeps integers unchanged (as fixed points)."
You can also describe floor(x) as being idempotent in this way -- which I think is a much more interesting takeaway to learn.
or that it cancels out the imaginary part of the parameter.
floor(x) also solves P versus NP and the Riemann hypothesis, then returns the greatest integer less than or equal to the input value.
since it does cast to a double inside, are there edge cases where it gives a -1 to the input?
regardless, I think it is a dumb question. Professors have 2 choices though, for our field. They can ask you to write code on the fly, or ask you dumb questions about details, or to trace through confusing code. None of it is valid, writing code under time pressure (talking 45 min or less) is not reasonable (though I have had to debug and repair in those kinds of conditions!) and goofball questions are also not reasonable. Its tough to strike a balance but the professors have to give tests (most places anyway) in a field where projects make much more sense (but you can cheat on those so easily...).
linked-in is the same, try to pass the c++ test, its 50% tricky questions. I got it on the first try, but I had to stop and go into trick question mindset to do it.
Thanks for the replies everyone, he hasn't responded to my e-mail yet. I understand where people are coming from, but this is an intro to C++ course, it's not a 400 level computer science course. I was taught floor() rounds a number down to the nearest integer, ceil() rounds a number up to the nearest integer. He is very clever, and asks a LOT of tricky questions, so I thought it was a trick question. I study hard for the class and do very well, so I was a bit infuriated when I saw that my answer was wrong. That's why I posted here. I now see both sides, but regardless, this is is how you learn!