a) This amounts to sampling from the set $\{a,b\}$, 4 times with replacement and with ordering. Thus, there are $2\times2\times2\times2=2^4=16$ possible functions. The 16 possibilities are:
$\{(1,a),(2,a),(3,a),(4,a)\},\\
\{(1,b),(2,a),(3,a),(4,a)\},\\
\{(1,a),(2,b),(3,a),(4,a)\},\\
\{(1,a),(2,a),(3,b),(4,a)\},\\
\{(1,a),(2,a),(3,a),(4,b)\},\\
\{(1,b),(2,b),(3,a),(4,a)\},\\
\{(1,a),(2,b),(3,b),(4,a)\},\\
\{(1,a),(2,a),(3,b),(4,b)\},\\
\{(1,b),(2,a),(3,b),(4,a)\},\\
\{(1,a),(2,b),(3,a),(4,b)\},\\
\{(1,b),(2,a),(3,a),(4,b)\},\\
\{(1,b),(2,b),(3,b),(4,a)\},\\
\{(1,a),(2,b),(3,b),(4,b)\},\\
\{(1,b),(2,a),(3,b),(4,b)\},\\
\{(1,b),(2,b),(3,a),(4,b)\},\\
\{(1,b),(2,b),(3,b),(4,b)\}$
However, there are two mappings that are not onto - the first and last in the list. So, there are 14 possible onto functions.
(b) The second case is similar. Note that the set B has three elements.
The required number of mappings = Total number of possibilities - functions that are not onto
= Total number of functions from A to C - (onto functions from A to C, considering only two elements of C at a time)
= Total number of functions from A to C - (total number of functions from A to C, considering only two elements of C, at a time - functions that are not onto)
= $3^4 - {3\choose2}({2^4}-1)=81-3(16-1)=36$