Let Anita's rank be x. Then Anjali's rank is 3x.
Since there are 4 students with ranks worse than Anjali, we have 3x+4≤40.
This simplifies to 3x≤36, leading to x≤12.
Thus, Anita's rank can be at most 12.
If x=12, then Anjali's rank would be 36, which satisfies the condition.
Therefore, Anita's rank in the class is 12.