How could Kirk become a Captain at the end of the film, or Uhura be a LT, as Spock referred to her before he and Kirk left to rescue Captain Pike, when they both started the mission as Cadets?
They were in a state of war. During wartime, flag officers can commission (confer officer status) and promote (raise in rank) to meet battlefield need. These promotions can skip ranks. Often the promotions are temporary, e.g. for the duration of the hostilities (a brevet promotion); but permanent battlefield promotions and commissions can also be made. There are regulations concerning their use, and they currently rare in the US military, but they do exist.
This is how it has been done historically, so we can imagine they have similar rules in the future.