How to calculate STFT of a function for a rectangular window
I don't understand what you mean by "positioned at $n=5$" with length $20$. Indeed:


is "positioned" the beginning  or the center?
is length an half-length around a central position, or a full length?
finally, at a given location, this is not an STFT anymore, but a mere windowed Fourier transform.


If I interpret your question in its most obvious sense, the window starts from $n=5$ to $n=20+5-1=24$, on an interval where $u[n]=1$, so you'd just have to compute a simple DFT of a cosine. The result can be obtained via Euler/De Moivre formulae, with two finite sums of geometric series. 

If this is not the case, please provide more information, close forms are at hand