The responses should be
I'm second (in the gradebook).
I'm second in line.
Because your name is in the gradebook. Your name is not in a number. So "I'm second in number" is not correct. In practice the phrase "in the gradebook" would be omitted, because it is clear from the context.
So the questions must be:
What position are you in the gradebook?
What number are you in the gradebook?
Similarly for the doctor:
What position are you (in line)?
In actual use, both these situations seem unlikely: A teacher would not need to ask where the student is, since the teacher should know this information already. Similarly you would not normally need to ask another person for their position to see a doctor, especially if that person is a stranger.
Also "gradebook" should perhaps be "markbook" or "register". And I don't know what the reference to "alphabet" means in your example, so I'm ignoring it.