[question word] … [verb (plain)] + ことか [question word] … [i-adj] + ことか [question word] … [na-adj] + な + ことか [question word] … [na-adj] / [noun] + だった + ことか
ことか is an exclamation about how far something went: "how happy I was!", "you have no idea how long I waited!". A question word such as どんなに, どれほど, どれだけ or なんど何度 opens the sentence, and the verb or adjective before ことか is in the plain form, past or non-past.
The sentence is not a question, and nobody answers it. It ends with 。 or !, not ?. The feeling can be gratitude, frustration, relief or longing; it is strong in every case.
A な-adjective keeps な, or takes だった in the past: どんなにしずか静かなことか, どんなにたいへん大変だったことか. A noun takes だった: どれほどのくろう苦労だったことか.
ことか belongs to writing, speeches and heartfelt talk. In everyday conversation the same feeling usually comes out with すごく or ほんとうに本当に. The polite form is ことでしょう, or ことでしょうか.