Is there a difference between the pronunciation of c, k and q in classical Latin? If they are all the same, why have three different letters for the same sound? Also, if x is pronounced just like ks, why have a separate letter for it?
The article Latin Alphabet of Wikipedia gives an answer to your question.
In short, the Latin alphabet is believed to be founded on the Cumæ alphabet (7th century). The Archaic Latin and Old Latin alphabets have then the letters 𐌂, 𐌊, and 𐌒, corresponding to C, K and Q.
At first, the letter C was used to note the sound /k/ and /g/, because the Etruscans didn't had the sound /g/ so they use gamma for /k/. Later the letter G replaced it. The letter K is rare (Kalendæ…). Q is a variant of /k/ before /u/, coming from the greek koppa, and only conserved in QV (qui != cui).
The letter ⟨C⟩ was the western form of the Greek gamma, but it was used for the sounds /ɡ/ and /k/ alike, possibly under the influence of Etruscan, which might have lacked any voiced plosives. Later, probably during the 3rd century BC, the letter ⟨Z⟩ — unneeded to write Latin properly — was replaced with the new letter ⟨G⟩, a ⟨C⟩ modified with a small vertical stroke, which took its place in the alphabet. From then on, ⟨G⟩ represented the voiced plosive /ɡ/, while ⟨C⟩ was generally reserved for the voiceless plosive /k/. The letter ⟨K⟩ was used only rarely, in a small number of words such as Kalendae, often interchangeably with ⟨C⟩.
More details are also given in the article for the letter Q:
In the earliest Latin inscriptions, the letters C, K and Q were all used to represent the two sounds /k/ and /ɡ/, which were not differentiated in writing. Of these, Q was used before a rounded vowel (e.g. ⟨EQO⟩ 'ego'), K before /a/, and C elsewhere. Later, the use of C (and its variant G) replaced most usages of K and Q: Q survived only to represent /k/ when immediately followed by a /w/ sound. The Etruscans used Q in conjunction with V to represent /kʷ/.
And in the article for the letter K:
(…) Of these, Q was used to represent /k/ or /g/ before a rounded vowel, K before /a/, and C elsewhere. Later, the use of C and its variant G replaced most usages of K and Q. K survived only in a few fossilized forms such as Kalendae.
About the sound /ks/ of X, in the article for the letter X:
In Ancient Greek, 'Χ' and 'Ψ' were among several variants of the same letter, used originally for /kʰ/ and later, in western areas such as Arcadia, as a simplification of the digraph 'ΧΣ' for /ks/. In the end, more conservative eastern forms became the standard of Classical Greek, and thus 'Χ' (Chi) stands for /kʰ/ (later /x/). However, the Etruscans had taken over 'Χ' from western Greek, and it therefore stands for /ks/ in Etruscan and Latin.
The letter 'Χ' ~ 'Ψ' for /kʰ/ was a Greek addition to the alphabet, placed after the Semitic letters along with phi 'Φ' for /pʰ/. (The variant 'Ψ' later replaced the digraph 'ΦΣ' for /ps/; omega was a later addition).